Commit 44f28bdea09415d40b4d73a7668db5961362ec53
Committed by
Greg Kroah-Hartman
1 parent
3e61dfd850
Exists in
master
and in
7 other branches
Driver core: reduce duplicated code for platform_device creation
This makes the two similar functions platform_device_register_simple and platform_device_register_data one line inline functions using a new generic function platform_device_register_resndata. Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Showing 3 changed files with 85 additions and 82 deletions Side-by-side Diff
Documentation/DocBook/device-drivers.tmpl
drivers/base/platform.c
... | ... | @@ -344,108 +344,56 @@ |
344 | 344 | EXPORT_SYMBOL_GPL(platform_device_unregister); |
345 | 345 | |
346 | 346 | /** |
347 | - * platform_device_register_simple - add a platform-level device and its resources | |
348 | - * @name: base name of the device we're adding | |
349 | - * @id: instance id | |
350 | - * @res: set of resources that needs to be allocated for the device | |
351 | - * @num: number of resources | |
347 | + * platform_device_register_resndata - add a platform-level device with | |
348 | + * resources and platform-specific data | |
352 | 349 | * |
353 | - * This function creates a simple platform device that requires minimal | |
354 | - * resource and memory management. Canned release function freeing memory | |
355 | - * allocated for the device allows drivers using such devices to be | |
356 | - * unloaded without waiting for the last reference to the device to be | |
357 | - * dropped. | |
358 | - * | |
359 | - * This interface is primarily intended for use with legacy drivers which | |
360 | - * probe hardware directly. Because such drivers create sysfs device nodes | |
361 | - * themselves, rather than letting system infrastructure handle such device | |
362 | - * enumeration tasks, they don't fully conform to the Linux driver model. | |
363 | - * In particular, when such drivers are built as modules, they can't be | |
364 | - * "hotplugged". | |
365 | - * | |
366 | - * Returns &struct platform_device pointer on success, or ERR_PTR() on error. | |
367 | - */ | |
368 | -struct platform_device *platform_device_register_simple(const char *name, | |
369 | - int id, | |
370 | - const struct resource *res, | |
371 | - unsigned int num) | |
372 | -{ | |
373 | - struct platform_device *pdev; | |
374 | - int retval; | |
375 | - | |
376 | - pdev = platform_device_alloc(name, id); | |
377 | - if (!pdev) { | |
378 | - retval = -ENOMEM; | |
379 | - goto error; | |
380 | - } | |
381 | - | |
382 | - if (num) { | |
383 | - retval = platform_device_add_resources(pdev, res, num); | |
384 | - if (retval) | |
385 | - goto error; | |
386 | - } | |
387 | - | |
388 | - retval = platform_device_add(pdev); | |
389 | - if (retval) | |
390 | - goto error; | |
391 | - | |
392 | - return pdev; | |
393 | - | |
394 | -error: | |
395 | - platform_device_put(pdev); | |
396 | - return ERR_PTR(retval); | |
397 | -} | |
398 | -EXPORT_SYMBOL_GPL(platform_device_register_simple); | |
399 | - | |
400 | -/** | |
401 | - * platform_device_register_data - add a platform-level device with platform-specific data | |
402 | 350 | * @parent: parent device for the device we're adding |
403 | 351 | * @name: base name of the device we're adding |
404 | 352 | * @id: instance id |
353 | + * @res: set of resources that needs to be allocated for the device | |
354 | + * @num: number of resources | |
405 | 355 | * @data: platform specific data for this platform device |
406 | 356 | * @size: size of platform specific data |
407 | 357 | * |
408 | - * This function creates a simple platform device that requires minimal | |
409 | - * resource and memory management. Canned release function freeing memory | |
410 | - * allocated for the device allows drivers using such devices to be | |
411 | - * unloaded without waiting for the last reference to the device to be | |
412 | - * dropped. | |
413 | - * | |
414 | 358 | * Returns &struct platform_device pointer on success, or ERR_PTR() on error. |
415 | 359 | */ |
416 | -struct platform_device *platform_device_register_data( | |
360 | +struct platform_device *platform_device_register_resndata( | |
417 | 361 | struct device *parent, |
418 | 362 | const char *name, int id, |
363 | + const struct resource *res, unsigned int num, | |
419 | 364 | const void *data, size_t size) |
420 | 365 | { |
366 | + int ret = -ENOMEM; | |
421 | 367 | struct platform_device *pdev; |
422 | - int retval; | |
423 | 368 | |
424 | 369 | pdev = platform_device_alloc(name, id); |
425 | - if (!pdev) { | |
426 | - retval = -ENOMEM; | |
427 | - goto error; | |
428 | - } | |
370 | + if (!pdev) | |
371 | + goto err; | |
429 | 372 | |
430 | 373 | pdev->dev.parent = parent; |
431 | 374 | |
432 | - if (size) { | |
433 | - retval = platform_device_add_data(pdev, data, size); | |
434 | - if (retval) | |
435 | - goto error; | |
375 | + if (res) { | |
376 | + ret = platform_device_add_resources(pdev, res, num); | |
377 | + if (ret) | |
378 | + goto err; | |
436 | 379 | } |
437 | 380 | |
438 | - retval = platform_device_add(pdev); | |
439 | - if (retval) | |
440 | - goto error; | |
381 | + if (data) { | |
382 | + ret = platform_device_add_data(pdev, data, size); | |
383 | + if (ret) | |
384 | + goto err; | |
385 | + } | |
441 | 386 | |
442 | - return pdev; | |
387 | + ret = platform_device_add(pdev); | |
388 | + if (ret) { | |
389 | +err: | |
390 | + platform_device_put(pdev); | |
391 | + return ERR_PTR(ret); | |
392 | + } | |
443 | 393 | |
444 | -error: | |
445 | - platform_device_put(pdev); | |
446 | - return ERR_PTR(retval); | |
394 | + return pdev; | |
447 | 395 | } |
448 | -EXPORT_SYMBOL_GPL(platform_device_register_data); | |
396 | +EXPORT_SYMBOL_GPL(platform_device_register_resndata); | |
449 | 397 | |
450 | 398 | static int platform_drv_probe(struct device *_dev) |
451 | 399 | { |
include/linux/platform_device.h
... | ... | @@ -43,10 +43,64 @@ |
43 | 43 | extern int platform_get_irq_byname(struct platform_device *, const char *); |
44 | 44 | extern int platform_add_devices(struct platform_device **, int); |
45 | 45 | |
46 | -extern struct platform_device *platform_device_register_simple(const char *, int id, | |
47 | - const struct resource *, unsigned int); | |
48 | -extern struct platform_device *platform_device_register_data(struct device *, | |
49 | - const char *, int, const void *, size_t); | |
46 | +extern struct platform_device *platform_device_register_resndata( | |
47 | + struct device *parent, const char *name, int id, | |
48 | + const struct resource *res, unsigned int num, | |
49 | + const void *data, size_t size); | |
50 | + | |
51 | +/** | |
52 | + * platform_device_register_simple - add a platform-level device and its resources | |
53 | + * @name: base name of the device we're adding | |
54 | + * @id: instance id | |
55 | + * @res: set of resources that needs to be allocated for the device | |
56 | + * @num: number of resources | |
57 | + * | |
58 | + * This function creates a simple platform device that requires minimal | |
59 | + * resource and memory management. Canned release function freeing memory | |
60 | + * allocated for the device allows drivers using such devices to be | |
61 | + * unloaded without waiting for the last reference to the device to be | |
62 | + * dropped. | |
63 | + * | |
64 | + * This interface is primarily intended for use with legacy drivers which | |
65 | + * probe hardware directly. Because such drivers create sysfs device nodes | |
66 | + * themselves, rather than letting system infrastructure handle such device | |
67 | + * enumeration tasks, they don't fully conform to the Linux driver model. | |
68 | + * In particular, when such drivers are built as modules, they can't be | |
69 | + * "hotplugged". | |
70 | + * | |
71 | + * Returns &struct platform_device pointer on success, or ERR_PTR() on error. | |
72 | + */ | |
73 | +static inline struct platform_device *platform_device_register_simple( | |
74 | + const char *name, int id, | |
75 | + const struct resource *res, unsigned int num) | |
76 | +{ | |
77 | + return platform_device_register_resndata(NULL, name, id, | |
78 | + res, num, NULL, 0); | |
79 | +} | |
80 | + | |
81 | +/** | |
82 | + * platform_device_register_data - add a platform-level device with platform-specific data | |
83 | + * @parent: parent device for the device we're adding | |
84 | + * @name: base name of the device we're adding | |
85 | + * @id: instance id | |
86 | + * @data: platform specific data for this platform device | |
87 | + * @size: size of platform specific data | |
88 | + * | |
89 | + * This function creates a simple platform device that requires minimal | |
90 | + * resource and memory management. Canned release function freeing memory | |
91 | + * allocated for the device allows drivers using such devices to be | |
92 | + * unloaded without waiting for the last reference to the device to be | |
93 | + * dropped. | |
94 | + * | |
95 | + * Returns &struct platform_device pointer on success, or ERR_PTR() on error. | |
96 | + */ | |
97 | +static inline struct platform_device *platform_device_register_data( | |
98 | + struct device *parent, const char *name, int id, | |
99 | + const void *data, size_t size) | |
100 | +{ | |
101 | + return platform_device_register_resndata(parent, name, id, | |
102 | + NULL, 0, data, size); | |
103 | +} | |
50 | 104 | |
51 | 105 | extern struct platform_device *platform_device_alloc(const char *name, int id); |
52 | 106 | extern int platform_device_add_resources(struct platform_device *pdev, |