From: Russell King <rmk+lkml@arm.linux.org.uk>
To: Dmitry Torokhov <dtor_core@ameritech.net>
Cc: Greg KH <greg@kroah.com>, linux-kernel@vger.kernel.org
Subject: Re: [PATCH 0/3] Couple of sysfs patches
Date: Fri, 18 Jun 2004 20:29:49 +0100 [thread overview]
Message-ID: <20040618202949.B17516@flint.arm.linux.org.uk> (raw)
In-Reply-To: <200406161751.03574.dtor_core@ameritech.net>; from dtor_core@ameritech.net on Wed, Jun 16, 2004 at 05:51:03PM -0500
On Wed, Jun 16, 2004 at 05:51:03PM -0500, Dmitry Torokhov wrote:
> What about freeing the resources? Can it be put in platform_device_unregister
> or is it release handler task? I'd put it in unregister because when I call
> unregister I expect device be half-dead and release as much resources as it
> can.
Greg,
Here's the updated patch - to be applied on top of the
platform_get_resource() patch sent previously.
diff -up -x BitKeeper -x ChangeSet -x SCCS -x _xlk -x *.orig -x *.rej orig/drivers/base/platform.c linux/drivers/base/platform.c
--- orig/drivers/base/platform.c Fri Jun 18 20:28:13 2004
+++ linux/drivers/base/platform.c Fri Jun 18 20:24:02 2004
@@ -55,51 +55,24 @@ int platform_get_irq(struct platform_dev
}
/**
- * platform_add_device - add one platform device
- * @dev: platform device
- *
- * Adds one platform device, claiming the memory resources
- */
-int platform_add_device(struct platform_device *dev)
-{
- int i;
-
- for (i = 0; i < dev->num_resources; i++) {
- struct resource *p, *r = &dev->resource[i];
-
- r->name = dev->dev.bus_id;
-
- p = NULL;
- if (r->flags & IORESOURCE_MEM)
- p = &iomem_resource;
- else if (r->flags & IORESOURCE_IO)
- p = &ioport_resource;
-
- if (p && request_resource(p, r)) {
- printk(KERN_ERR
- "%s%d: failed to claim resource %d\n",
- dev->name, dev->id, i);
- break;
- }
- }
- if (i == dev->num_resources)
- platform_device_register(dev);
- return 0;
-}
-
-/**
* platform_add_devices - add a numbers of platform devices
* @devs: array of platform devices to add
* @num: number of platform devices in array
*/
int platform_add_devices(struct platform_device **devs, int num)
{
- int i;
+ int i, ret = 0;
- for (i = 0; i < num; i++)
- platform_add_device(devs[i]);
+ for (i = 0; i < num; i++) {
+ ret = platform_device_register(devs[i]);
+ if (ret) {
+ while (--i >= 0)
+ platform_device_unregister(devs[i]);
+ break;
+ }
+ }
- return 0;
+ return ret;
}
/**
@@ -109,6 +82,8 @@ int platform_add_devices(struct platform
*/
int platform_device_register(struct platform_device * pdev)
{
+ int i, ret = 0;
+
if (!pdev)
return -EINVAL;
@@ -119,15 +94,53 @@ int platform_device_register(struct plat
snprintf(pdev->dev.bus_id,BUS_ID_SIZE,"%s%u",pdev->name,pdev->id);
+ for (i = 0; i < pdev->num_resources; i++) {
+ struct resource *p, *r = &pdev->resource[i];
+
+ r->name = pdev->dev.bus_id;
+
+ p = NULL;
+ if (r->flags & IORESOURCE_MEM)
+ p = &iomem_resource;
+ else if (r->flags & IORESOURCE_IO)
+ p = &ioport_resource;
+
+ if (p && request_resource(p, r)) {
+ printk(KERN_ERR
+ "%s: failed to claim resource %d\n",
+ pdev->dev.bus_id, i);
+ ret = -EBUSY;
+ goto failed;
+ }
+ }
+
pr_debug("Registering platform device '%s'. Parent at %s\n",
pdev->dev.bus_id,pdev->dev.parent->bus_id);
- return device_register(&pdev->dev);
+
+ ret = device_register(&pdev->dev);
+ if (ret == 0)
+ return ret;
+
+ failed:
+ while (--i >= 0)
+ if (pdev->resource[i].flags & (IORESOURCE_MEM|IORESOURCE_IO))
+ release_resource(&pdev->resource[i]);
+ return ret;
}
void platform_device_unregister(struct platform_device * pdev)
{
- if (pdev)
+ int i;
+
+ if (pdev) {
device_unregister(&pdev->dev);
+
+ for (i = 0; i < pdev->num_resources; i++) {
+ struct resource *r = &pdev->resource[i];
+ if (r->flags & (IORESOURCE_MEM|IORESOURCE_IO))
+ release_resource(r);
+ }
+ }
}
diff -up -x BitKeeper -x ChangeSet -x SCCS -x _xlk -x *.orig -x *.rej orig/include/linux/device.h linux/include/linux/device.h
--- orig/include/linux/device.h Fri Jun 18 20:28:13 2004
+++ linux/include/linux/device.h Thu Jun 10 19:15:03 2004
@@ -392,7 +392,6 @@ extern struct device platform_bus;
extern struct resource *platform_get_resource(struct platform_device *, unsigned int, unsigned int);
extern int platform_get_irq(struct platform_device *, unsigned int);
-extern int platform_add_device(struct platform_device *);
extern int platform_add_devices(struct platform_device **, int);
/* drivers/base/power.c */
--
Russell King
Linux kernel 2.6 ARM Linux - http://www.arm.linux.org.uk/
maintainer of: 2.6 PCMCIA - http://pcmcia.arm.linux.org.uk/
2.6 Serial core
next prev parent reply other threads:[~2004-06-18 19:35 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2004-06-10 14:46 [PATCH 0/3] Couple of sysfs patches Dmitry Torokhov
2004-06-10 16:06 ` Russell King
2004-06-10 16:14 ` Greg KH
2004-06-10 18:17 ` Russell King
2004-06-10 20:25 ` Russell King
2004-06-16 22:51 ` Dmitry Torokhov
2004-06-18 19:29 ` Russell King [this message]
2004-06-18 20:39 ` Greg KH
-- strict thread matches above, loose matches on Subject: below --
2004-06-18 19:59 Dmitry Torokhov
2004-06-09 7:21 Dmitry Torokhov
2004-06-09 22:13 ` Greg KH
[not found] ` <200406091732.28684.dtor_core@ameritech.net>
2004-06-09 22:45 ` Greg KH
[not found] ` <200406091754.23303.dtor_core@ameritech.net>
2004-06-09 23:19 ` Greg KH
2004-06-10 6:40 ` Dmitry Torokhov
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20040618202949.B17516@flint.arm.linux.org.uk \
--to=rmk+lkml@arm.linux.org.uk \
--cc=dtor_core@ameritech.net \
--cc=greg@kroah.com \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox