diff options
author | Ricardo Ribalda Delgado <ricardo.ribalda@gmail.com> | 2015-05-26 03:31:26 -0400 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2015-05-31 21:15:17 -0400 |
commit | 6d9d4b1469b0d9748145e168fc9ec585e1f3f4b0 (patch) | |
tree | 7b083155b6046ace5fd1d9ceed01c9261a9fa838 | |
parent | b6d2233f2916fa9338786aeab2e936c5a07e4d0c (diff) |
base/platform: Remove code duplication
Failure path of platform_device_add was almost the same as
platform_device_del. Refactor same code in a function.
Acked-by: Rob Herring <robh@kernel.org>
Signed-off-by: Ricardo Ribalda Delgado <ricardo.ribalda@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
-rw-r--r-- | drivers/base/platform.c | 60 |
1 files changed, 25 insertions, 35 deletions
diff --git a/drivers/base/platform.c b/drivers/base/platform.c index 5a29387e5ff6..cba8e0e83bfc 100644 --- a/drivers/base/platform.c +++ b/drivers/base/platform.c | |||
@@ -298,6 +298,25 @@ int platform_device_add_data(struct platform_device *pdev, const void *data, | |||
298 | } | 298 | } |
299 | EXPORT_SYMBOL_GPL(platform_device_add_data); | 299 | EXPORT_SYMBOL_GPL(platform_device_add_data); |
300 | 300 | ||
301 | static void platform_device_cleanout(struct platform_device *pdev, int n_res) | ||
302 | { | ||
303 | int i; | ||
304 | |||
305 | if (pdev->id_auto) { | ||
306 | ida_simple_remove(&platform_devid_ida, pdev->id); | ||
307 | pdev->id = PLATFORM_DEVID_AUTO; | ||
308 | } | ||
309 | |||
310 | for (i = 0; i < n_res; i++) { | ||
311 | struct resource *r = &pdev->resource[i]; | ||
312 | unsigned long type = resource_type(r); | ||
313 | |||
314 | if ((type == IORESOURCE_MEM || type == IORESOURCE_IO) && | ||
315 | r->parent) | ||
316 | release_resource(r); | ||
317 | } | ||
318 | } | ||
319 | |||
301 | /** | 320 | /** |
302 | * platform_device_add - add a platform device to device hierarchy | 321 | * platform_device_add - add a platform device to device hierarchy |
303 | * @pdev: platform device we're adding | 322 | * @pdev: platform device we're adding |
@@ -371,23 +390,8 @@ int platform_device_add(struct platform_device *pdev) | |||
371 | dev_name(&pdev->dev), dev_name(pdev->dev.parent)); | 390 | dev_name(&pdev->dev), dev_name(pdev->dev.parent)); |
372 | 391 | ||
373 | ret = device_add(&pdev->dev); | 392 | ret = device_add(&pdev->dev); |
374 | if (ret == 0) | 393 | if (ret) |
375 | return ret; | 394 | platform_device_cleanout(pdev, i); |
376 | |||
377 | /* Failure path */ | ||
378 | if (pdev->id_auto) { | ||
379 | ida_simple_remove(&platform_devid_ida, pdev->id); | ||
380 | pdev->id = PLATFORM_DEVID_AUTO; | ||
381 | } | ||
382 | |||
383 | while (--i >= 0) { | ||
384 | struct resource *r = &pdev->resource[i]; | ||
385 | unsigned long type = resource_type(r); | ||
386 | |||
387 | if ((type == IORESOURCE_MEM || type == IORESOURCE_IO) && | ||
388 | r->parent) | ||
389 | release_resource(r); | ||
390 | } | ||
391 | 395 | ||
392 | return ret; | 396 | return ret; |
393 | } | 397 | } |
@@ -403,25 +407,11 @@ EXPORT_SYMBOL_GPL(platform_device_add); | |||
403 | */ | 407 | */ |
404 | void platform_device_del(struct platform_device *pdev) | 408 | void platform_device_del(struct platform_device *pdev) |
405 | { | 409 | { |
406 | int i; | 410 | if (!pdev) |
407 | 411 | return; | |
408 | if (pdev) { | ||
409 | device_del(&pdev->dev); | ||
410 | |||
411 | if (pdev->id_auto) { | ||
412 | ida_simple_remove(&platform_devid_ida, pdev->id); | ||
413 | pdev->id = PLATFORM_DEVID_AUTO; | ||
414 | } | ||
415 | |||
416 | for (i = 0; i < pdev->num_resources; i++) { | ||
417 | struct resource *r = &pdev->resource[i]; | ||
418 | unsigned long type = resource_type(r); | ||
419 | 412 | ||
420 | if ((type == IORESOURCE_MEM || type == IORESOURCE_IO) && | 413 | device_del(&pdev->dev); |
421 | r->parent) | 414 | platform_device_cleanout(pdev, pdev->num_resources); |
422 | release_resource(r); | ||
423 | } | ||
424 | } | ||
425 | } | 415 | } |
426 | EXPORT_SYMBOL_GPL(platform_device_del); | 416 | EXPORT_SYMBOL_GPL(platform_device_del); |
427 | 417 | ||