lkml.org 
[lkml]   [2006]   [Sep]   [13]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
Date
From
Subject[03/12] driver core fixes: fixup platform_device_register_simple()
From: Cornelia Huck <cornelia.huck@de.ibm.com>

Remember to remove allocated resources if platform_device_add() fails.
Introduce a helper function platform_device_del_resources() for this,
which can also be used by platform_device_del().

Signed-off-by: Cornelia Huck <cornelia.huck@de.ibm.com>

platform.c | 29 ++++++++++++++++++-----------
1 file changed, 18 insertions(+), 11 deletions(-)

--- linux-2.6.18-rc6/drivers/base/platform.c 2006-09-12 16:37:21.000000000 +0200
+++ linux-2.6.18-rc6+CH/drivers/base/platform.c 2006-09-12 16:39:10.000000000 +0200
@@ -202,6 +202,17 @@ int platform_device_add_resources(struct
}
EXPORT_SYMBOL_GPL(platform_device_add_resources);

+static void platform_device_del_resources(struct platform_device *pdev)
+{
+ int i;
+
+ for (i = 0; i < pdev->num_resources; i++) {
+ struct resource *r = &pdev->resource[i];
+ if (r->flags & (IORESOURCE_MEM|IORESOURCE_IO))
+ release_resource(r);
+ }
+}
+
/**
* platform_device_add_data
* @pdev: platform device allocated by platform_device_alloc to add resources to
@@ -296,15 +307,8 @@ EXPORT_SYMBOL_GPL(platform_device_add);
*/
void platform_device_del(struct platform_device *pdev)
{
- int i;
-
if (pdev) {
- for (i = 0; i < pdev->num_resources; i++) {
- struct resource *r = &pdev->resource[i];
- if (r->flags & (IORESOURCE_MEM|IORESOURCE_IO))
- release_resource(r);
- }
-
+ platform_device_del_resources(pdev);
device_del(&pdev->dev);
}
}
@@ -365,17 +369,20 @@ struct platform_device *platform_device_
if (num) {
retval = platform_device_add_resources(pdev, res, num);
if (retval)
- goto error;
+ goto error_put;
}

retval = platform_device_add(pdev);
if (retval)
- goto error;
+ goto error_resources;

return pdev;

-error:
+error_resources:
+ platform_device_del_resources(pdev);
+error_put:
platform_device_put(pdev);
+error:
return ERR_PTR(retval);
}
EXPORT_SYMBOL_GPL(platform_device_register_simple);
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
\
 
 \ /
  Last update: 2006-09-13 18:45    [W:1.215 / U:0.012 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site