2006-09-13 16:41:53

by Cornelia Huck

[permalink] [raw]
Subject: [03/12] driver core fixes: fixup platform_device_register_simple()

From: Cornelia Huck <[email protected]>

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 <[email protected]>

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);


2006-09-14 02:31:10

by Dmitry Torokhov

[permalink] [raw]
Subject: Re: [03/12] driver core fixes: fixup platform_device_register_simple()

Hi,

On Wednesday 13 September 2006 12:38, Cornelia Huck wrote:
> From: Cornelia Huck <[email protected]>
>
> 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().
>

platform_device_add() already releases all resources in case of failure.
Memory allocated for resource structures is released by
platform_device_release(). I do not think this patch is needed.

As fas as platform_device_register_somple() goes it should just die and
users should be converted to platofrm_device_alloc/add.

--
Dmitry

2006-09-14 07:06:38

by Cornelia Huck

[permalink] [raw]
Subject: Re: [03/12] driver core fixes: fixup platform_device_register_simple()

On Wed, 13 Sep 2006 22:31:05 -0400,
Dmitry Torokhov <[email protected]> wrote:

> platform_device_add() already releases all resources in case of failure.
> Memory allocated for resource structures is released by
> platform_device_release(). I do not think this patch is needed.

Uh, of course, you're right.

Greg, please disregard this patch.

--
Cornelia Huck
Linux for zSeries Developer
Tel.: +49-7031-16-4837, Mail: [email protected]