* [2/9] driver core fixes: device_register() retval check in platform.c
@ 2006-09-22 9:36 Cornelia Huck
2006-09-23 21:10 ` Russell King
0 siblings, 1 reply; 3+ messages in thread
From: Cornelia Huck @ 2006-09-22 9:36 UTC (permalink / raw)
To: Greg K-H; +Cc: linux-kernel
From: Cornelia Huck <cornelia.huck@de.ibm.com>
Check the return value of device_register() in platform_bus_init().
Signed-off-by: Cornelia Huck <cornelia.huck@de.ibm.com>
---
drivers/base/platform.c | 11 +++++++++--
1 file changed, 9 insertions(+), 2 deletions(-)
--- linux-2.6-CH.orig/drivers/base/platform.c
+++ linux-2.6-CH/drivers/base/platform.c
@@ -563,8 +563,15 @@ EXPORT_SYMBOL_GPL(platform_bus_type);
int __init platform_bus_init(void)
{
- device_register(&platform_bus);
- return bus_register(&platform_bus_type);
+ int error;
+
+ error = device_register(&platform_bus);
+ if (error)
+ return error;
+ error = bus_register(&platform_bus_type);
+ if (error)
+ device_unregister(&platform_bus);
+ return error;
}
#ifndef ARCH_HAS_DMA_GET_REQUIRED_MASK
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [2/9] driver core fixes: device_register() retval check in platform.c 2006-09-22 9:36 [2/9] driver core fixes: device_register() retval check in platform.c Cornelia Huck @ 2006-09-23 21:10 ` Russell King 2006-09-25 14:58 ` Cornelia Huck 0 siblings, 1 reply; 3+ messages in thread From: Russell King @ 2006-09-23 21:10 UTC (permalink / raw) To: Cornelia Huck; +Cc: Greg K-H, linux-kernel On Fri, Sep 22, 2006 at 11:36:55AM +0200, Cornelia Huck wrote: > From: Cornelia Huck <cornelia.huck@de.ibm.com> > > Check the return value of device_register() in platform_bus_init(). > > Signed-off-by: Cornelia Huck <cornelia.huck@de.ibm.com> > > --- > drivers/base/platform.c | 11 +++++++++-- > 1 file changed, 9 insertions(+), 2 deletions(-) > > --- linux-2.6-CH.orig/drivers/base/platform.c > +++ linux-2.6-CH/drivers/base/platform.c > @@ -563,8 +563,15 @@ EXPORT_SYMBOL_GPL(platform_bus_type); > > int __init platform_bus_init(void) > { > - device_register(&platform_bus); > - return bus_register(&platform_bus_type); > + int error; > + > + error = device_register(&platform_bus); > + if (error) > + return error; > + error = bus_register(&platform_bus_type); > + if (error) > + device_unregister(&platform_bus); > + return error; I don't think there's much value in patches such as this - if the platform bus type didn't register, what happens when we then try to register a platform device driver or a platform device? ISTR doing that before the bus type is registered leads to an OOPS. So, presumably to do this properly, if the platform_bus_type failed to register, you need to force all platform device/platform device driver registrations to also fail. At that point, is the added complexity really worth it? -- Russell King Linux kernel 2.6 ARM Linux - http://www.arm.linux.org.uk/ maintainer of: 2.6 Serial core ^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [2/9] driver core fixes: device_register() retval check in platform.c 2006-09-23 21:10 ` Russell King @ 2006-09-25 14:58 ` Cornelia Huck 0 siblings, 0 replies; 3+ messages in thread From: Cornelia Huck @ 2006-09-25 14:58 UTC (permalink / raw) To: Russell King; +Cc: Greg K-H, linux-kernel On Sat, 23 Sep 2006 22:10:32 +0100, Russell King <rmk+lkml@arm.linux.org.uk> wrote: > I don't think there's much value in patches such as this - if the > platform bus type didn't register, what happens when we then try > to register a platform device driver or a platform device? ISTR > doing that before the bus type is registered leads to an OOPS. Yes, since the klists have not yet been initialized. > So, presumably to do this properly, if the platform_bus_type failed > to register, you need to force all platform device/platform device > driver registrations to also fail. We should fail registration (gracefully) of all devices/drivers which specify a bus that is !NULL but has not been registered. Unfortunately, I don't see an easy way to do this. However, we can fail the registration of devices that specify a parent that is !NULL but not yet added to the tree. This catches platform devices registering before platform_bus_type (since platform_bus is not registered then), similar for other bus types like iucv. (Unfortunately, not drivers...) From: Cornelia Huck <cornelia.huck@de.ibm.com> Force parent devices to be registered before their children. Otherwise we'll oops when creating the child's sysfs directory. Signed-off-by: Cornelia Huck <cornelia.huck@de.ibm.com> --- drivers/base/bus.c | 6 ++++-- drivers/base/core.c | 5 ++++- 2 files changed, 8 insertions(+), 3 deletions(-) --- linux-2.6.18-mm1.orig/drivers/base/core.c +++ linux-2.6.18-mm1/drivers/base/core.c @@ -474,7 +474,10 @@ int device_add(struct device *dev) } parent = get_device(dev->parent); - + if (parent && !device_is_registered(parent)) { + error = -EINVAL; + goto Error; + } pr_debug("DEV: registering device: ID = '%s'\n", dev->bus_id); /* first, register with generic layer. */ --- linux-2.6.18-mm1.orig/drivers/base/bus.c +++ linux-2.6.18-mm1/drivers/base/bus.c @@ -418,7 +418,8 @@ int bus_attach_device(struct device * de ret = 0; } else dev->is_registered = 0; - } + } else + dev->is_registered = 1; return ret; } @@ -443,7 +444,8 @@ void bus_remove_device(struct device * d pr_debug("bus %s: remove device %s\n", dev->bus->name, dev->bus_id); device_release_driver(dev); put_bus(dev->bus); - } + } else + dev->is_registered = 0; } static int driver_add_attrs(struct bus_type * bus, struct device_driver * drv) ^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2006-09-25 14:58 UTC | newest] Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2006-09-22 9:36 [2/9] driver core fixes: device_register() retval check in platform.c Cornelia Huck 2006-09-23 21:10 ` Russell King 2006-09-25 14:58 ` Cornelia Huck
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®