Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

dt: Refactor of_platform_bus_probe()

The current implementation uses three copies of of basically identical
code. This patch consolidates them to make the code simpler.

Signed-off-by: Grant Likely <grant.likely@secretlab.ca>

+18 -37
+18 -37
drivers/of/platform.c
··· 210 210 EXPORT_SYMBOL(of_platform_device_create); 211 211 212 212 /** 213 - * of_platform_bus_create - Create an OF device for a bus node and all its 214 - * children. Optionally recursively instantiate matching busses. 213 + * of_platform_bus_create() - Create a device for a node and its children. 215 214 * @bus: device node of the bus to instantiate 216 215 * @matches: match table, NULL to use the default, OF_NO_DEEP_PROBE to 217 - * disallow recursive creation of child busses 216 + * disallow recursive creation of child buses 217 + * @parent: parent for new device, or NULL for top level. 218 + * 219 + * Creates a platform_device for the provided device_node, and optionally 220 + * recursively create devices for all the child nodes. 218 221 */ 219 - static int of_platform_bus_create(const struct device_node *bus, 222 + static int of_platform_bus_create(struct device_node *bus, 220 223 const struct of_device_id *matches, 221 224 struct device *parent) 222 225 { ··· 227 224 struct platform_device *dev; 228 225 int rc = 0; 229 226 227 + dev = of_platform_device_create(bus, NULL, parent); 228 + if (!dev || !of_match_node(matches, bus)) 229 + return 0; 230 + 230 231 for_each_child_of_node(bus, child) { 231 232 pr_debug(" create child: %s\n", child->full_name); 232 - dev = of_platform_device_create(child, NULL, parent); 233 - if (dev == NULL) 234 - continue; 235 - 236 - if (!of_match_node(matches, child)) 237 - continue; 238 - if (rc == 0) { 239 - pr_debug(" and sub busses\n"); 240 - rc = of_platform_bus_create(child, matches, &dev->dev); 241 - } 233 + rc = of_platform_bus_create(child, matches, &dev->dev); 242 234 if (rc) { 243 235 of_node_put(child); 244 236 break; ··· 243 245 } 244 246 245 247 /** 246 - * of_platform_bus_probe - Probe the device-tree for platform busses 248 + * of_platform_bus_probe() - Probe the device-tree for platform buses 247 249 * @root: parent of the first level to probe or NULL for the root of the tree 248 250 * @matches: match table, NULL to use the default 249 251 * @parent: parent to hook devices from, NULL for toplevel ··· 256 258 struct device *parent) 257 259 { 258 260 struct device_node *child; 259 - struct platform_device *dev; 260 261 int rc = 0; 261 262 262 263 if (WARN_ON(!matches || matches == OF_NO_DEEP_PROBE)) ··· 274 277 * children 275 278 */ 276 279 if (of_match_node(matches, root)) { 277 - pr_debug(" root match, create all sub devices\n"); 278 - dev = of_platform_device_create(root, NULL, parent); 279 - if (dev == NULL) 280 - goto bail; 281 - 282 - pr_debug(" create all sub busses\n"); 283 - rc = of_platform_bus_create(root, matches, &dev->dev); 284 - goto bail; 285 - } 286 - for_each_child_of_node(root, child) { 280 + rc = of_platform_bus_create(root, matches, parent); 281 + } else for_each_child_of_node(root, child) { 287 282 if (!of_match_node(matches, child)) 288 283 continue; 289 - 290 - pr_debug(" match: %s\n", child->full_name); 291 - dev = of_platform_device_create(child, NULL, parent); 292 - if (dev == NULL) 293 - continue; 294 - 295 - rc = of_platform_bus_create(child, matches, &dev->dev); 296 - if (rc) { 297 - of_node_put(child); 284 + rc = of_platform_bus_create(child, matches, parent); 285 + if (rc) 298 286 break; 299 - } 300 287 } 301 - bail: 288 + 302 289 of_node_put(root); 303 290 return rc; 304 291 }