ChangeSet 1.1018.1.13, 2003/04/04 17:13:54-08:00, greg@kroah.com driver core: move the hotplug support for /sys/devices to use the kobject logic. We can't switch /sys/class or /sys/bus to use this because they are not creating new kobjects, only linking to the kobjects in /sys/devices. drivers/base/base.h | 5 ---- drivers/base/core.c | 55 ++++++++++++++++++++++++++++++++++++++++--------- drivers/base/hotplug.c | 32 +--------------------------- 3 files changed, 48 insertions(+), 44 deletions(-) diff -Nru a/drivers/base/base.h b/drivers/base/base.h --- a/drivers/base/base.h Mon Apr 7 15:13:25 2003 +++ b/drivers/base/base.h Mon Apr 7 15:13:25 2003 @@ -18,13 +18,8 @@ #ifdef CONFIG_HOTPLUG -extern int dev_hotplug(struct device *dev, const char *action); extern int class_hotplug(struct device *dev, const char *action); #else -static inline int dev_hotplug(struct device *dev, const char *action) -{ - return 0; -} static inline int class_hotplug(struct device *dev, const char *action) { return 0; diff -Nru a/drivers/base/core.c b/drivers/base/core.c --- a/drivers/base/core.c Mon Apr 7 15:13:25 2003 +++ b/drivers/base/core.c Mon Apr 7 15:13:25 2003 @@ -23,13 +23,12 @@ DECLARE_MUTEX(device_sem); -#define to_dev(obj) container_of(obj,struct device,kobj) - /* * sysfs bindings for devices. */ +#define to_dev(obj) container_of(obj,struct device,kobj) #define to_dev_attr(_attr) container_of(_attr,struct device_attribute,attr) extern struct attribute * dev_default_attrs[]; @@ -86,11 +85,55 @@ .default_attrs = dev_default_attrs, }; + +static int dev_hotplug_filter(struct kset *kset, struct kobject *kobj) +{ + struct kobj_type *ktype = get_ktype(kobj); + + if (ktype == &ktype_device) { + struct device *dev = to_dev(kobj); + if (dev->bus) + return 1; + } + return 0; +} + +static char *dev_hotplug_name(struct kset *kset, struct kobject *kobj) +{ + struct device *dev = to_dev(kobj); + + return dev->bus->name; +} + +static int dev_hotplug(struct kset *kset, struct kobject *kobj, char **envp, + int num_envp, char *buffer, int buffer_size) +{ + struct device *dev = to_dev(kobj); + int retval = 0; + + if (dev->bus->hotplug) { + /* have the bus specific function add its stuff */ + retval = dev->bus->hotplug (dev, envp, num_envp, buffer, buffer_size); + if (retval) { + pr_debug ("%s - hotplug() returned %d\n", + __FUNCTION__, retval); + } + } + + return retval; +} + +static struct kset_hotplug_ops device_hotplug_ops = { + .filter = dev_hotplug_filter, + .name = dev_hotplug_name, + .hotplug = dev_hotplug, +}; + /** * device_subsys - structure to be registered with kobject core. */ -decl_subsys(devices,&ktype_device); +decl_subsys(devices, &ktype_device, &device_hotplug_ops); /** @@ -192,9 +235,6 @@ if (platform_notify) platform_notify(dev); - /* notify userspace of device entry */ - dev_hotplug(dev, "add"); - devclass_add_device(dev); register_done: if (error && parent) @@ -277,9 +317,6 @@ */ if (platform_notify_remove) platform_notify_remove(dev); - - /* notify userspace that this device is about to disappear */ - dev_hotplug (dev, "remove"); bus_remove_device(dev); diff -Nru a/drivers/base/hotplug.c b/drivers/base/hotplug.c --- a/drivers/base/hotplug.c Mon Apr 7 15:13:25 2003 +++ b/drivers/base/hotplug.c Mon Apr 7 15:13:25 2003 @@ -2,8 +2,8 @@ * drivers/base/hotplug.c - hotplug call code * * Copyright (c) 2000-2001 David Brownell - * Copyright (c) 2002 Greg Kroah-Hartman - * Copyright (c) 2002 IBM Corp. + * Copyright (c) 2002-2003 Greg Kroah-Hartman + * Copyright (c) 2002-2003 IBM Corp. * * Based off of drivers/usb/core/usb.c:call_agent(), which was * written by David Brownell. @@ -53,17 +53,6 @@ if (!hotplug_path [0]) return -ENODEV; - if (in_interrupt ()) { - pr_debug ("%s - in_interrupt, not allowed!", __FUNCTION__); - return -EIO; - } - - if (!current->fs->root) { - /* don't try to do anything unless we have a root partition */ - pr_debug ("%s - %s -- no FS yet\n", __FUNCTION__, action); - return -EIO; - } - envp = (char **) kmalloc (NUM_ENVP * sizeof (char *), GFP_KERNEL); if (!envp) return -ENOMEM; @@ -127,23 +116,6 @@ kfree (envp); return retval; } - - -/* - * dev_hotplug - called when any device is added or removed from a bus - */ -int dev_hotplug (struct device *dev, const char *action) -{ - pr_debug ("%s\n", __FUNCTION__); - if (!dev) - return -ENODEV; - - if (!dev->bus) - return -ENODEV; - - return do_hotplug (dev, dev->bus->name, action, dev->bus->hotplug); -} - /* * class_hotplug - called when a class is added or removed from a device