[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <20060913183840.5a2e4989@gondolin.boeblingen.de.ibm.com>
Date: Wed, 13 Sep 2006 18:38:40 +0200
From: Cornelia Huck <cornelia.huck@...ibm.com>
To: Greg K-H <greg@...ah.com>
Cc: linux-kernel <linux-kernel@...r.kernel.org>
Subject: [03/12] driver core fixes: fixup platform_device_register_simple()
From: Cornelia Huck <cornelia.huck@...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@...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@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists