Driver core patches for 2.6.20
Subsystems (16)
PATCH 1/1 Driver core patches for 2.6.20
Here are a bunch of Driver core, sysfs, and driver model patches for 2.6.20-git
They include the conversion of the network drivers to use 'struct device' instead of 'struct class' (the patch has been in -mm for over 6 months and was acked by David Miller) some module sysfs additions to make userspace tools simpler, and lots of cleanups and fixes. See the full log below for details.
All of these have been in the -mm tree for quite a while.
Please pull from:
master.kernel.org:/pub/scm/linux/kernel/git/gregkh/driver-2.6.git/
Patches will be sent as a follow-on to this message to lkml for people to see.
thanks,
greg k-h
Documentation/HOWTO | 1 + drivers/base/class.c | 21 ++- drivers/base/core.c | 203 +++++++++++++------- drivers/base/dd.c | 21 ++- drivers/base/firmware_class.c | 2 +- drivers/base/platform.c | 11 +- drivers/ide/setup-pci.c | 7 +- drivers/infiniband/ulp/ipoib/ipoib_main.c | 33 ++-- drivers/infiniband/ulp/ipoib/ipoib_vlan.c | 11 +- drivers/input/serio/serio.c | 6 +- drivers/net/arm/at91_ether.c | 2 +- drivers/net/arm/etherh.c | 2 +- drivers/net/bonding/bond_sysfs.c | 287 +++++++++++++++++----------- drivers/net/iseries_veth.c | 2 +- drivers/net/macb.c | 36 ++-- drivers/net/smc911x.c | 2 +- drivers/net/smc91x.c | 2 +- drivers/net/wireless/hostap/hostap_main.c | 2 +- drivers/net/wireless/orinoco.c | 4 +- drivers/net/wireless/orinoco_cs.c | 2 +- drivers/net/wireless/spectrum_cs.c | 2 +- drivers/pci/pci-driver.c | 4 +- drivers/pcmcia/cs.c | 34 ++-- drivers/pcmcia/cs_internal.h | 4 +- drivers/pcmcia/ds.c | 14 +- drivers/pcmcia/i82092.c | 2 +- drivers/pcmcia/i82365.c | 2 +- drivers/pcmcia/pcmcia_ioctl.c | 1 - drivers/pcmcia/pcmcia_resource.c | 1 - drivers/pcmcia/pd6729.c | 2 +- drivers/pcmcia/rsrc_nonstatic.c | 56 +++--- drivers/pcmcia/soc_common.c | 6 +- drivers/pcmcia/socket_sysfs.c | 104 ++++++----- drivers/pcmcia/tcic.c | 2 +- drivers/pcmcia/yenta_socket.c | 2 +- drivers/spi/pxa2xx_spi.c | 2 +- drivers/spi/spi.c | 32 ++-- drivers/spi/spi_bitbang.c | 6 +- drivers/spi/spi_butterfly.c | 4 +- drivers/usb/core/driver.c | 4 +- drivers/usb/input/hid-lgff.c | 4 +- fs/sysfs/bin.c | 6 +- fs/sysfs/dir.c | 214 ++++++++++++++++++---- fs/sysfs/file.c | 82 ++++++--- fs/sysfs/group.c | 2 + fs/sysfs/inode.c | 36 ++++- fs/sysfs/mount.c | 11 +- fs/sysfs/symlink.c | 1 + fs/sysfs/sysfs.h | 21 ++ include/linux/device.h | 12 +- include/linux/ide.h | 4 +- include/linux/kobject.h | 4 + include/linux/module.h | 3 +- include/linux/netdevice.h | 5 +- include/linux/pci.h | 5 +- include/linux/serio.h | 5 + include/linux/spi/spi.h | 10 +- include/linux/sysfs.h | 24 ++- include/linux/usb.h | 5 +- include/pcmcia/ss.h | 2 +- kernel/module.c | 76 ++++++-- kernel/params.c | 28 ++- lib/kobject.c | 73 ++++++-- net/bridge/br_if.c | 2 +- net/bridge/br_sysfs_br.c | 234 +++++++++++++----------- net/bridge/br_sysfs_if.c | 2 +- net/core/dev.c | 6 +- net/core/net-sysfs.c | 175 ++++++++++-------- net/core/skbuff.c | 2 +- 69 files changed, 1286 insertions(+), 709 deletions(-)
---------------
Cornelia Huck (6):
driver core: Remove device_is_registered() in device_move(). driver core: Allow device_move(dev, NULL).
driver core fixes: make_class_name() retval checks driver core fixes: device_register() retval check in platform.c driver core: Don't stop probing on ->probe errors. driver core: Change function call order in device_bind_driver().
Dave Jones (1):
Driver Core: Increase the default timeout value of the firmware subsystem
Eric W. Biederman (1):
sysfs: Shadow directory support
Frank Haverkamp (1):
SYSFS: Fix missing include of list.h in sysfs.h
Frederik Deweerdt (1):
sysfs: suppress lockdep warnings
Greg Kroah-Hartman (8):
Kobject: make kobject apis more robust in handling NULL pointers Driver core: convert pcmcia code to use struct device
Driver core: convert SPI code to use struct device
Network: convert network devices to use struct device instead of class_device
Modules: only add drivers/ direcory if needed
PCI: add the sysfs driver name to all modules
SERIO: add the sysfs driver name to all modules
USB: add the sysfs driver name to all modules
Kay Sievers (5):
MODULES: add the module name for built in kernel drivers /sys/modules/*/holders
Driver core: add uevent vars for devices of a class Driver core: add device_type to struct device Driver core: allow to delay the uevent at device creation time
Mariusz Kozlowski (2):
sysfs: kobject_put cleanup
kobject: kobject_put cleanup
Oliver Neukum (2):
Driver core: fix race in sysfs between sysfs_remove_file() and read()/write()
sysfs: error handling in sysfs, fill_read_buffer()
Robert P. J. Day (1):
HOWTO: Add a reference to Harbison and Steele
PATCH 1/28 Kobject: make kobject apis more robust in handling NULL pointers
From: Greg Kroah-Hartman <[email protected]>
It should be ok to pass in NULL for some kobject functions, so add error checking for all exported kobject functions to be more robust.
--- lib/kobject.c | 19 +++++++++++++++++++ 1 files changed, 19 insertions(+), 0 deletions(-)
lib/kobject.c +19 -0
@@ -126,6 +126,8 @@ EXPORT_SYMBOL_GPL(kobject_get_path);*/ void kobject_init (struct kobject * kobj) { +if (!kobj) +return ;kref_init (&kobj->kref);INIT_LIST_HEAD (&kobj->entry);init_waitqueue_head (&kobj->poll);
@@ -366,6 +368,8 @@ out:void kobject_del (struct kobject * kobj) { +if (!kobj) +return ;sysfs_remove_dir (kobj);unlink (kobj); }
@@ -377,6 +381,8 @@ void kobject_del(struct kobject * kobj)void kobject_unregister (struct kobject * kobj) { +if (!kobj) +return ;pr_debug ("kobject %s: unregistering\n" ,kobject_name (kobj));kobject_uevent (kobj,KOBJ_REMOVE );kobject_del (kobj);
@@ -523,6 +529,8 @@ int kset_add(struct kset * k)int kset_register (struct kset * k) { +if (!k) +return -EINVAL ;kset_init (k);return kset_add (k); }
@@ -535,6 +543,8 @@ int kset_register(struct kset * k)void kset_unregister (struct kset * k) { +if (!k) +return ;kobject_unregister (&k->kobj); }
@@ -586,6 +596,9 @@ int subsystem_register(struct subsystem * s) {int error; +if (!s) +return -EINVAL ; +subsystem_init (s);pr_debug ("subsystem %s: registering\n" ,s->kset.kobj.name);
@@ -598,6 +611,8 @@ int subsystem_register(struct subsystem * s)void subsystem_unregister (struct subsystem * s) { +if (!s) +return ;pr_debug ("subsystem %s: unregistering\n" ,s->kset.kobj.name);kset_unregister (&s->kset); }
@@ -612,6 +627,10 @@ void subsystem_unregister(struct subsystem * s)int subsys_create_file (struct subsystem * s,struct subsys_attribute * a) {int error =0 ; + +if (!s || !a) +return -EINVAL ; +if (subsys_get (s)) { error =sysfs_create_file (&s->kset.kobj,&a->attr);subsys_put (s);
Signature · 1 line
1.4.4.4
PATCH 2/28 Driver core: convert pcmcia code to use struct device
From: Greg Kroah-Hartman <[email protected]>
Converts from using struct "class_device" to "struct device" making everything show up properly in /sys/devices/ with symlinks from the /sys/class directory.
--- drivers/pcmcia/cs.c | 34 ++++++------ drivers/pcmcia/cs_internal.h | 4 +- drivers/pcmcia/ds.c | 14 +++--- drivers/pcmcia/i82092.c | 2 +- drivers/pcmcia/i82365.c | 2 +- drivers/pcmcia/pcmcia_ioctl.c | 1 - drivers/pcmcia/pcmcia_resource.c | 1 - drivers/pcmcia/pd6729.c | 2 +- drivers/pcmcia/rsrc_nonstatic.c | 56 +++++++++++--------- drivers/pcmcia/soc_common.c | 6 +- drivers/pcmcia/socket_sysfs.c | 104 ++++++++++++++++++++++---------------- drivers/pcmcia/tcic.c | 2 +- drivers/pcmcia/yenta_socket.c | 2 +- include/pcmcia/ss.h | 2 +- 14 files changed, 127 insertions(+), 105 deletions(-)
drivers/pcmcia/cs.c +17 -17
@@ -110,7 +110,7 @@ int pcmcia_socket_dev_suspend(struct device *dev, pm_message_t state)down_read (&pcmcia_socket_list_rwsem);list_for_each_entry (socket, &pcmcia_socket_list, socket_list) { -if (socket->dev.dev != dev) +if (socket->dev.parent != dev)continue ;mutex_lock (&socket->skt_mutex);socket_suspend (socket);
@@ -128,7 +128,7 @@ int pcmcia_socket_dev_resume(struct device *dev)down_read (&pcmcia_socket_list_rwsem);list_for_each_entry (socket, &pcmcia_socket_list, socket_list) { -if (socket->dev.dev != dev) +if (socket->dev.parent != dev)continue ;mutex_lock (&socket->skt_mutex);socket_resume (socket);
@@ -143,12 +143,12 @@ EXPORT_SYMBOL(pcmcia_socket_dev_resume);struct pcmcia_socket *pcmcia_get_socket (struct pcmcia_socket *skt) { -struct class_device *cl_dev =class_device_get (&skt->dev); -if (!cl_dev) +struct device *dev =get_device (&skt->dev); +if (!dev)return NULL ; - skt =class_get_devdata (cl_dev); + skt =dev_get_drvdata (dev);if (!try_module_get (skt->owner)) { -class_device_put (&skt->dev); +put_device (&skt->dev);return NULL ; }return (skt);
@@ -159,14 +159,14 @@ EXPORT_SYMBOL(pcmcia_get_socket);void pcmcia_put_socket (struct pcmcia_socket *skt) {module_put (skt->owner); -class_device_put (&skt->dev); +put_device (&skt->dev); }EXPORT_SYMBOL (pcmcia_put_socket); -static void pcmcia_release_socket (struct class_device *class_dev) +static void pcmcia_release_socket (struct device *dev) { -struct pcmcia_socket *socket =class_get_devdata (class_dev); +struct pcmcia_socket *socket =dev_get_drvdata (dev);complete (&socket->socket_released); }
@@ -181,7 +181,7 @@ int pcmcia_register_socket(struct pcmcia_socket *socket)struct task_struct *tsk;int ret; -if (!socket || !socket->ops || !socket->dev.dev || !socket->resource_ops) +if (!socket || !socket->ops || !socket->dev.parent || !socket->resource_ops)return -EINVAL ;cs_dbg (socket,0 ,"pcmcia_register_socket(0x%p)\n" , socket->ops);
@@ -226,9 +226,9 @@ int pcmcia_register_socket(struct pcmcia_socket *socket)#endif /* set proper values in socket->dev */ - socket->dev.class_data = socket; +dev_set_drvdata (&socket->dev, socket); socket->dev.class = &pcmcia_socket_class; -snprintf (socket->dev.class_id,BUS_ID_SIZE ,"pcmcia_socket%u" , socket->sock); +snprintf (socket->dev.bus_id,BUS_ID_SIZE ,"pcmcia_socket%u" , socket->sock);/* base address = 0, map = 0 */ socket->cis_mem.flags =0 ;
@@ -640,7 +640,7 @@ static int pccardd(void *__skt) skt->ops->set_socket (skt, &skt->socket);/* register with the device core */ - ret =class_device_register (&skt->dev); + ret =device_register (&skt->dev);if (ret) {printk (KERN_WARNING "PCMCIA: unable to register socket 0x%p\n" , skt);
@@ -689,7 +689,7 @@ static int pccardd(void *__skt)remove_wait_queue (&skt->thread_wait, &wait);/* remove from the device core */ -class_device_unregister (&skt->dev); +device_unregister (&skt->dev);return 0 ; }
@@ -904,7 +904,7 @@ int pcmcia_insert_card(struct pcmcia_socket *skt)EXPORT_SYMBOL (pcmcia_insert_card); -static int pcmcia_socket_uevent (struct class_device *dev,char **envp, +static int pcmcia_socket_uevent (struct device *dev,char **envp,int num_envp,char *buffer,int buffer_size) { struct pcmcia_socket *s = container_of(dev, struct pcmcia_socket, dev);
@@ -930,8 +930,8 @@ static void pcmcia_release_socket_class(struct class *data)struct class pcmcia_socket_class = { .name ="pcmcia_socket" , - .uevent = pcmcia_socket_uevent, - .release = pcmcia_release_socket, + .dev_uevent = pcmcia_socket_uevent, + .dev_release = pcmcia_release_socket, .class_release = pcmcia_release_socket_class, };EXPORT_SYMBOL (pcmcia_socket_class);
drivers/pcmcia/cs_internal.h +2 -2
@@ -142,7 +142,7 @@ struct pcmcia_callback{int pccard_register_pcmcia (struct pcmcia_socket *s,struct pcmcia_callback *c); -#define cs_socket_name (skt) ((skt)->dev.class_id) +#define cs_socket_name (skt) ((skt)->dev.bus_id)#ifdef DEBUG extern int cs_debug_level (int );
@@ -158,6 +158,6 @@ extern int cs_debug_level(int);#endif #define cs_err(skt, fmt, arg...) \ - printk(KERN_ERR "cs: %s: " fmt, (skt)->dev.class_id , ## arg) + printk(KERN_ERR "cs: %s: " fmt, (skt)->dev.bus_id , ## arg)#endif /* _LINUX_CS_INTERNAL_H */
drivers/pcmcia/ds.c +7 -7
@@ -572,7 +572,7 @@ struct pcmcia_device * pcmcia_device_add(struct pcmcia_socket *s, unsigned int f p_dev->func = function; p_dev->dev.bus = &pcmcia_bus_type; - p_dev->dev.parent = s->dev.dev; + p_dev->dev.parent = s->dev.parent; p_dev->dev.release = pcmcia_release_dev; bus_id_len =sprintf (p_dev->dev.bus_id,"%d.%d" , p_dev->socket->sock, p_dev->device_no);
@@ -1328,10 +1328,10 @@ static struct pcmcia_callback pcmcia_bus_callback = { .resume = pcmcia_bus_resume, }; -static int __devinit pcmcia_bus_add_socket (struct class_device *class_dev, +static int __devinit pcmcia_bus_add_socket (struct device *dev,struct class_interface *class_intf) { -struct pcmcia_socket *socket =class_get_devdata (class_dev); +struct pcmcia_socket *socket =dev_get_drvdata (dev);int ret; socket =pcmcia_get_socket (socket);
@@ -1364,10 +1364,10 @@ static int __devinit pcmcia_bus_add_socket(struct class_device *class_dev,return 0 ; } -static void pcmcia_bus_remove_socket (struct class_device *class_dev, +static void pcmcia_bus_remove_socket (struct device *dev,struct class_interface *class_intf) { -struct pcmcia_socket *socket =class_get_devdata (class_dev); +struct pcmcia_socket *socket =dev_get_drvdata (dev);if (!socket)return ;
@@ -1389,8 +1389,8 @@ static void pcmcia_bus_remove_socket(struct class_device *class_dev,/* the pcmcia_bus_interface is used to handle pcmcia socket devices */ static struct class_interface pcmcia_bus_interface = { .class = &pcmcia_socket_class, - .add = &pcmcia_bus_add_socket, - .remove = &pcmcia_bus_remove_socket, + .add_dev = &pcmcia_bus_add_socket, + .remove_dev = &pcmcia_bus_remove_socket, };
drivers/pcmcia/i82092.c +1 -1
@@ -161,7 +161,7 @@ static int __devinit i82092aa_pci_probe(struct pci_dev *dev, const struct pci_depci_set_drvdata (dev, &sockets[i].socket);for (i =0 ; i<socket_count; i++) { - sockets[i].socket.dev.dev = &dev->dev; + sockets[i].socket.dev.parent = &dev->dev; sockets[i].socket.ops = &i82092aa_operations; sockets[i].socket.resource_ops = &pccard_nonstatic_ops; ret =pcmcia_register_socket (&sockets[i].socket);
drivers/pcmcia/i82365.c +1 -1
@@ -1298,7 +1298,7 @@ static int __init init_i82365(void)/* register sockets with the pcmcia core */ for (i =0 ; i < sockets; i++) { - socket[i].socket.dev.dev = &i82365_device->dev; + socket[i].socket.dev.parent = &i82365_device->dev; socket[i].socket.ops = &pcic_operations; socket[i].socket.resource_ops = &pccard_nonstatic_ops; socket[i].socket.owner =THIS_MODULE ;
drivers/pcmcia/pcmcia_ioctl.c +0 -1
@@ -59,7 +59,6 @@ typedef struct user_info_t {#ifdef DEBUG extern int ds_pc_debug; -#define cs_socket_name (skt) ((skt)->dev.class_id) #define ds_dbg(lvl, fmt, arg...) do { \ if (ds_pc_debug >= lvl) \
drivers/pcmcia/pcmcia_resource.c +0 -1
@@ -48,7 +48,6 @@ static u8 pcmcia_used_irq[NR_IRQS];#ifdef DEBUG extern int ds_pc_debug; -#define cs_socket_name (skt) ((skt)->dev.class_id) #define ds_dbg(skt, lvl, fmt, arg...) do { \ if (ds_pc_debug >= lvl) \
drivers/pcmcia/pd6729.c +1 -1
@@ -682,7 +682,7 @@ static int __devinit pd6729_pci_probe(struct pci_dev *dev, socket[i].socket.ops = &pd6729_operations; socket[i].socket.resource_ops = &pccard_nonstatic_ops; - socket[i].socket.dev.dev = &dev->dev; + socket[i].socket.dev.parent = &dev->dev; socket[i].socket.driver_data = &socket[i]; }
drivers/pcmcia/rsrc_nonstatic.c +31 -25
131 lines not on this page · raw message
drivers/pcmcia/soc_common.c +3 -3
@@ -478,10 +478,10 @@ dump_bits(char **p, const char *prefix, unsigned int val, struct bittbl *bits, i* * Returns: the number of characters added to the buffer */ -static ssize_t show_status (struct class_device *class_dev,char *buf) +static ssize_t show_status (struct device *dev,char *buf) {struct soc_pcmcia_socket *skt = - container_of(class_dev, struct soc_pcmcia_socket, socket.dev); + container_of(dev, struct soc_pcmcia_socket, socket.dev);char *p = buf; p+=sprintf (p,"slot : %d\n" , skt->nr);
@@ -747,7 +747,7 @@ int soc_common_drv_pcmcia_probe(struct device *dev, struct pcmcia_low_level *opsadd_timer (&skt->poll_timer); -class_device_create_file (&skt->socket.dev, &class_device_attr_status); +device_create_file (&skt->socket.dev, &device_attr_status); }dev_set_drvdata (dev, sinfo);
drivers/pcmcia/socket_sysfs.c +61 -43
234 lines not on this page · raw message
drivers/pcmcia/tcic.c +1 -1
@@ -512,7 +512,7 @@ static int __init init_tcic(void)for (i =0 ; i < sockets; i++) { socket_table[i].socket.ops = &tcic_operations; socket_table[i].socket.resource_ops = &pccard_nonstatic_ops; - socket_table[i].socket.dev.dev = &tcic_device.dev; + socket_table[i].socket.dev.parent = &tcic_device.dev; ret =pcmcia_register_socket (&socket_table[i].socket);if (ret && i)pcmcia_unregister_socket (&socket_table[0 ].socket);
drivers/pcmcia/yenta_socket.c +1 -1
@@ -1104,7 +1104,7 @@ static int __devinit yenta_probe (struct pci_dev *dev, const struct pci_device_i/* prepare pcmcia_socket */ socket->socket.ops = ¥ta_socket_operations; socket->socket.resource_ops = &pccard_nonstatic_ops; - socket->socket.dev.dev = &dev->dev; + socket->socket.dev.parent = &dev->dev; socket->socket.driver_data = socket; socket->socket.owner =THIS_MODULE ; socket->socket.features =SS_CAP_PAGE_REGS |SS_CAP_PCCARD ;
include/pcmcia/ss.h +1 -1
@@ -284,7 +284,7 @@ struct pcmcia_socket {#endif /* socket device */ -struct class_device dev; +struct device dev;void *driver_data;/* data internal to the socket driver */ };
Signature · 1 line
1.4.4.4
PATCH 3/28 Driver core: convert SPI code to use struct device
From: Greg Kroah-Hartman <[email protected]>
Converts from using struct "class_device" to "struct device" making everything show up properly in /sys/devices/ with symlinks from the /sys/class directory.
--- drivers/spi/pxa2xx_spi.c | 2 +- drivers/spi/spi.c | 32 ++++++++++++++++---------------- drivers/spi/spi_bitbang.c | 6 +++--- drivers/spi/spi_butterfly.c | 4 ++-- include/linux/spi/spi.h | 10 +++++----- 5 files changed, 27 insertions(+), 27 deletions(-)
drivers/spi/pxa2xx_spi.c +1 -1
@@ -1234,7 +1234,7 @@ static int init_queue(struct driver_data *drv_data)INIT_WORK (&drv_data->pump_messages, pump_messages); drv_data->workqueue =create_singlethread_workqueue ( - drv_data->master->cdev.dev->bus_id); + drv_data->master->dev.parent->bus_id);if (drv_data->workqueue ==NULL )return -EBUSY ;
drivers/spi/spi.c +16 -16
@@ -193,7 +193,7 @@ struct spi_device *__init_or_module spi_new_device(struct spi_master *master, struct spi_board_info *chip) { struct spi_device *proxy; -struct device *dev = master->cdev.dev; +struct device *dev = &master->dev;int status;/* NOTE: caller did any chip->bus_num checks necessary */
@@ -215,7 +215,7 @@ spi_new_device(struct spi_master *master, struct spi_board_info *chip) proxy->modalias = chip->modalias;snprintf (proxy->dev.bus_id,sizeof proxy->dev.bus_id, -"%s.%u" , master->cdev.class_id, +"%s.%u" , master->dev.bus_id, chip->chip_select); proxy->dev.parent = dev; proxy->dev.bus = &spi_bus_type;
@@ -290,7 +290,7 @@ static void __init_or_module scan_boardinfo(struct spi_master *master) {struct boardinfo *bi; -struct device *dev = master->cdev.dev; +struct device *dev = master->dev.parent;down (&board_lock);list_for_each_entry (bi, &board_list, list) {
@@ -319,18 +319,18 @@ scan_boardinfo(struct spi_master *master)/*-------------------------------------------------------------------------*/ -static void spi_master_release (struct class_device *cdev) +static void spi_master_release (struct device *dev) {struct spi_master *master; - master = container_of(cdev, struct spi_master, cdev); + master = container_of(dev, struct spi_master, dev);kfree (master); }static struct class spi_master_class = { .name ="spi_master" , .owner =THIS_MODULE , - .release = spi_master_release, + .dev_release = spi_master_release, };
@@ -364,9 +364,9 @@ spi_alloc_master(struct device *dev, unsigned size)if (!master)return NULL ; -class_device_initialize (&master->cdev); - master->cdev.class = &spi_master_class; - master->cdev.dev =get_device (dev); +device_initialize (&master->dev); + master->dev.class = &spi_master_class; + master->dev.parent =get_device (dev);spi_master_set_devdata (master, &master[1 ]);return master;
@@ -396,7 +396,7 @@ int __init_or_module spi_register_master(struct spi_master *master) {static atomic_t dyn_bus_id =ATOMIC_INIT ((1 <<16 ) -1 ); -struct device *dev = master->cdev.dev; +struct device *dev = master->dev.parent;int status = -ENODEV ;int dynamic =0 ;
@@ -412,12 +412,12 @@ spi_register_master(struct spi_master *master)/* register the device, then userspace will see it. * registration fails if the bus ID is in use. */ -snprintf (master->cdev.class_id,sizeof master->cdev.class_id, +snprintf (master->dev.bus_id,sizeof master->dev.bus_id,"spi%u" , master->bus_num); - status =class_device_add (&master->cdev); + status =device_add (&master->dev);if (status <0 ) goto done; -dev_dbg (dev,"registered master %s%s\n" , master->cdev.class_id, +dev_dbg (dev,"registered master %s%s\n" , master->dev.bus_id, dynamic ?" (dynamic)" :"" );/* populate children from any spi device tables */
@@ -449,8 +449,8 @@ void spi_unregister_master(struct spi_master *master) {int dummy; - dummy =device_for_each_child (master->cdev.dev,NULL , __unregister); -class_device_unregister (&master->cdev); + dummy =device_for_each_child (&master->dev,NULL , __unregister); +device_unregister (&master->dev); }EXPORT_SYMBOL_GPL (spi_unregister_master);
@@ -471,7 +471,7 @@ struct spi_master *spi_busnum_to_master(u16 bus_num)down (&spi_master_class.sem);list_for_each_entry (cdev, &spi_master_class.children, node) { - m = container_of(cdev, struct spi_master, cdev); + m = container_of(cdev, struct spi_master, dev.kobj);if (m->bus_num == bus_num) { master =spi_master_get (m);break ;
drivers/spi/spi_bitbang.c +3 -3
@@ -479,7 +479,7 @@ int spi_bitbang_start(struct spi_bitbang *bitbang)/* this task is the only thing to touch the SPI bits */ bitbang->busy =0 ; bitbang->workqueue =create_singlethread_workqueue ( - bitbang->master->cdev.dev->bus_id); + bitbang->master->dev.parent->bus_id);if (bitbang->workqueue ==NULL ) { status = -EBUSY ; goto err1;
@@ -513,14 +513,14 @@ int spi_bitbang_stop(struct spi_bitbang *bitbang)while (!list_empty (&bitbang->queue) && limit--) {spin_unlock_irq (&bitbang->lock); -dev_dbg (bitbang->master->cdev.dev,"wait for queue\n" ); +dev_dbg (&bitbang->master->dev,"wait for queue\n" );msleep (10 );spin_lock_irq (&bitbang->lock); }spin_unlock_irq (&bitbang->lock);if (!list_empty (&bitbang->queue)) { -dev_err (bitbang->master->cdev.dev,"queue didn't empty\n" ); +dev_err (&bitbang->master->dev,"queue didn't empty\n" );return -EBUSY ; }
drivers/spi/spi_butterfly.c +2 -2
@@ -246,7 +246,7 @@ static void butterfly_attach(struct parport *p)* and no way to be selective about what it binds to. */ -/* FIXME where should master->cdev.dev come from? +/* FIXME where should master->dev.parent come from? * e.g. /sys/bus/pnp0/00:0b, some PCI thing, etc * setting up a platform device like this is an ugly kluge... */
@@ -386,7 +386,7 @@ static void butterfly_detach(struct parport *p) butterfly =NULL ;/* stop() unregisters child devices too */ - pdev =to_platform_device (pp->bitbang.master->cdev.dev); + pdev =to_platform_device (pp->bitbang.master->dev.parent); status =spi_bitbang_stop (&pp->bitbang);/* turn off VCC */
include/linux/spi/spi.h +5 -5
@@ -170,7 +170,7 @@ static inline void spi_unregister_driver(struct spi_driver *sdrv)* message's completion function when the transaction completes. */ struct spi_master { -struct class_device cdev; +struct device dev;/* other than negative (== assign one dynamically), bus_num is fully * board-specific. usually that simplifies to being SOC-specific.
@@ -216,17 +216,17 @@ struct spi_master {static inline void *spi_master_get_devdata (struct spi_master *master) { -return class_get_devdata (&master->cdev); +return dev_get_drvdata (&master->dev); }static inline void spi_master_set_devdata (struct spi_master *master,void *data) { -class_set_devdata (&master->cdev, data); +dev_set_drvdata (&master->dev, data); }static inline struct spi_master *spi_master_get (struct spi_master *master) { -if (!master || !class_device_get (&master->cdev)) +if (!master || !get_device (&master->dev))return NULL ;return master; }
@@ -234,7 +234,7 @@ static inline struct spi_master *spi_master_get(struct spi_master *master)static inline void spi_master_put (struct spi_master *master) {if (master) -class_device_put (&master->cdev); +put_device (&master->dev); }
Signature · 1 line
1.4.4.4
PATCH 4/28 Network: convert network devices to use struct device instead of class_device
From: Greg Kroah-Hartman <[email protected]>
This lets the network core have the ability to handle suspend/resume issues, if it wants to.
Thanks to Frederik Deweerdt <[email protected]> for the arm driver fixes.
--- drivers/infiniband/ulp/ipoib/ipoib_main.c | 33 ++-- drivers/infiniband/ulp/ipoib/ipoib_vlan.c | 11 +- drivers/net/arm/at91_ether.c | 2 +- drivers/net/arm/etherh.c | 2 +- drivers/net/bonding/bond_sysfs.c | 287 +++++++++++++++++----------- drivers/net/iseries_veth.c | 2 +- drivers/net/macb.c | 36 ++-- drivers/net/smc911x.c | 2 +- drivers/net/smc91x.c | 2 +- drivers/net/wireless/hostap/hostap_main.c | 2 +- drivers/net/wireless/orinoco.c | 4 +- drivers/net/wireless/orinoco_cs.c | 2 +- drivers/net/wireless/spectrum_cs.c | 2 +- include/linux/netdevice.h | 5 +- net/bridge/br_if.c | 2 +- net/bridge/br_sysfs_br.c | 234 +++++++++++++----------- net/bridge/br_sysfs_if.c | 2 +- net/core/dev.c | 6 +- net/core/net-sysfs.c | 175 ++++++++++-------- net/core/skbuff.c | 2 +- 20 files changed, 451 insertions(+), 362 deletions(-)
drivers/infiniband/ulp/ipoib/ipoib_main.c +15 -18
@@ -958,16 +958,17 @@ struct ipoib_dev_priv *ipoib_intf_alloc(const char *name)return netdev_priv (dev); } -static ssize_t show_pkey (struct class_device *cdev,char *buf) +static ssize_t show_pkey (struct device *dev, +struct device_attribute *attr,char *buf) { -struct ipoib_dev_priv *priv = - netdev_priv(container_of(cdev, struct net_device, class_dev)); +struct ipoib_dev_priv *priv =netdev_priv (to_net_dev (dev));return sprintf (buf,"0x%04x\n" , priv->pkey); } -static CLASS_DEVICE_ATTR(pkey, S_IRUGO, show_pkey, NULL); +static DEVICE_ATTR(pkey, S_IRUGO, show_pkey, NULL); -static ssize_t create_child (struct class_device *cdev, +static ssize_t create_child (struct device *dev, +struct device_attribute *attr,const char *buf,size_t count) {int pkey;
@@ -985,14 +986,14 @@ static ssize_t create_child(struct class_device *cdev,*/ pkey |=0x8000 ; - ret = ipoib_vlan_add(container_of(cdev, struct net_device, class_dev), - pkey); + ret =ipoib_vlan_add (to_net_dev (dev), pkey);return ret ? ret : count; } -static CLASS_DEVICE_ATTR(create_child, S_IWUGO, NULL, create_child); +static DEVICE_ATTR(create_child, S_IWUGO, NULL, create_child); -static ssize_t delete_child (struct class_device *cdev, +static ssize_t delete_child (struct device *dev, +struct device_attribute *attr,const char *buf,size_t count) {int pkey;
@@ -1004,18 +1005,16 @@ static ssize_t delete_child(struct class_device *cdev,if (pkey <0 || pkey >0xffff )return -EINVAL ; - ret = ipoib_vlan_delete(container_of(cdev, struct net_device, class_dev), - pkey); + ret =ipoib_vlan_delete (to_net_dev (dev), pkey);return ret ? ret : count; } -static CLASS_DEVICE_ATTR(delete_child, S_IWUGO, NULL, delete_child); +static DEVICE_ATTR(delete_child, S_IWUGO, NULL, delete_child);int ipoib_add_pkey_attr (struct net_device *dev) { -return class_device_create_file (&dev->class_dev, - &class_device_attr_pkey); +return device_create_file (&dev->dev, &dev_attr_pkey); } static struct net_device *ipoib_add_port(const char *format,
@@ -1083,11 +1082,9 @@ static struct net_device *ipoib_add_port(const char *format,if (ipoib_add_pkey_attr (priv->dev)) goto sysfs_failed; -if (class_device_create_file (&priv->dev->class_dev, - &class_device_attr_create_child)) +if (device_create_file (&priv->dev->dev, &dev_attr_create_child)) goto sysfs_failed; -if (class_device_create_file (&priv->dev->class_dev, - &class_device_attr_delete_child)) +if (device_create_file (&priv->dev->dev, &dev_attr_delete_child)) goto sysfs_failed;return priv->dev;
drivers/infiniband/ulp/ipoib/ipoib_vlan.c +5 -6
@@ -42,15 +42,15 @@#include "ipoib.h" -static ssize_t show_parent (struct class_device *class_dev,char *buf) +static ssize_t show_parent (struct device *d,struct device_attribute *attr, +char *buf) { -struct net_device *dev = - container_of(class_dev, struct net_device, class_dev); +struct net_device *dev =to_net_dev (d);struct ipoib_dev_priv *priv =netdev_priv (dev);return sprintf (buf,"%s\n" , priv->parent->name); } -static CLASS_DEVICE_ATTR(parent, S_IRUGO, show_parent, NULL); +static DEVICE_ATTR(parent, S_IRUGO, show_parent, NULL);int ipoib_vlan_add (struct net_device *pdev,unsigned short pkey) {
@@ -118,8 +118,7 @@ int ipoib_vlan_add(struct net_device *pdev, unsigned short pkey)if (ipoib_add_pkey_attr (priv->dev)) goto sysfs_failed; -if (class_device_create_file (&priv->dev->class_dev, - &class_device_attr_parent)) +if (device_create_file (&priv->dev->dev, &dev_attr_parent)) goto sysfs_failed;list_add_tail (&priv->list, &ppriv->child_intfs);
drivers/net/arm/at91_ether.c +1 -1
@@ -641,7 +641,7 @@ static void at91ether_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo {strlcpy (info->driver,DRV_NAME ,sizeof (info->driver));strlcpy (info->version,DRV_VERSION ,sizeof (info->version)); -strlcpy (info->bus_info, dev->class_dev.dev->bus_id,sizeof (info->bus_info)); +strlcpy (info->bus_info, dev->dev.parent->bus_id,sizeof (info->bus_info)); }static const struct ethtool_ops at91ether_ethtool_ops = {
drivers/net/arm/etherh.c +1 -1
@@ -587,7 +587,7 @@ static void etherh_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *i {strlcpy (info->driver,DRV_NAME ,sizeof (info->driver));strlcpy (info->version,DRV_VERSION ,sizeof (info->version)); -strlcpy (info->bus_info, dev->class_dev.dev->bus_id, +strlcpy (info->bus_info, dev->dev.parent->bus_id,sizeof (info->bus_info)); }
drivers/net/bonding/bond_sysfs.c +174 -113
685 lines not on this page · raw message
drivers/net/iseries_veth.c +1 -1
@@ -1102,7 +1102,7 @@ static struct net_device * __init veth_probe_one(int vlan, }kobject_init (&port->kobject); - port->kobject.parent = &dev->class_dev.kobj; + port->kobject.parent = &dev->dev.kobj; port->kobject.ktype = &veth_port_ktype;kobject_set_name (&port->kobject,"veth_port" );if (0 !=kobject_add (&port->kobject))
drivers/net/macb.c +18 -18
@@ -27,8 +27,6 @@#include "macb.h" -#define to_net_dev (class) container_of(class, struct net_device, class_dev) -#define RX_BUFFER_SIZE 128#define RX_RING_SIZE 512#define RX_RING_BYTES (sizeof(struct dma_desc) * RX_RING_SIZE)
@@ -945,10 +943,10 @@ static int macb_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)return ret; } -static ssize_t macb_mii_show (const struct class_device *cd,char *buf, +static ssize_t macb_mii_show (const struct device *_dev,char *buf,unsigned long addr) { -struct net_device *dev =to_net_dev (cd); +struct net_device *dev =to_net_dev (_dev);struct macb *bp =netdev_priv (dev);ssize_t ret = -EINVAL ;
@@ -962,11 +960,13 @@ static ssize_t macb_mii_show(const struct class_device *cd, char *buf, }#define MII_ENTRY (name, addr) \ -static ssize_t show_##name(struct class_device *cd, char *buf) \ +static ssize_t show_##name(struct device *_dev, \ + struct device_attribute *attr, \ + char *buf) \ { \ - return macb_mii_show(cd, buf, addr); \ + return macb_mii_show(_dev, buf, addr); \ } \ -static CLASS_DEVICE_ATTR(name, S_IRUGO, show_##name, NULL) +static DEVICE_ATTR(name, S_IRUGO, show_##name, NULL)MII_ENTRY (bmcr,MII_BMCR );MII_ENTRY (bmsr,MII_BMSR );
@@ -977,13 +977,13 @@ MII_ENTRY(lpa, MII_LPA);MII_ENTRY (expansion,MII_EXPANSION );static struct attribute *macb_mii_attrs[] = { - &class_device_attr_bmcr.attr, - &class_device_attr_bmsr.attr, - &class_device_attr_physid1.attr, - &class_device_attr_physid2.attr, - &class_device_attr_advertise.attr, - &class_device_attr_lpa.attr, - &class_device_attr_expansion.attr, + &dev_attr_bmcr.attr, + &dev_attr_bmsr.attr, + &dev_attr_physid1.attr, + &dev_attr_physid2.attr, + &dev_attr_advertise.attr, + &dev_attr_lpa.attr, + &dev_attr_expansion.attr,NULL , };
@@ -994,17 +994,17 @@ static struct attribute_group macb_mii_group = {static void macb_unregister_sysfs (struct net_device *net) { -struct class_device *class_dev = &net->class_dev; +struct device *_dev = &net->dev; -sysfs_remove_group (&class_dev->kobj, &macb_mii_group); +sysfs_remove_group (&_dev->kobj, &macb_mii_group); }static int macb_register_sysfs (struct net_device *net) { -struct class_device *class_dev = &net->class_dev; +struct device *_dev = &net->dev;int ret; - ret =sysfs_create_group (&class_dev->kobj, &macb_mii_group); + ret =sysfs_create_group (&_dev->kobj, &macb_mii_group);if (ret) printk(KERN_WARNING "%s: sysfs mii attribute registration failed: %d\n",
drivers/net/smc911x.c +1 -1
@@ -1659,7 +1659,7 @@ smc911x_ethtool_getdrvinfo(struct net_device *dev, struct ethtool_drvinfo *info) {strncpy (info->driver,CARDNAME ,sizeof (info->driver));strncpy (info->version, version,sizeof (info->version)); -strncpy (info->bus_info, dev->class_dev.dev->bus_id,sizeof (info->bus_info)); +strncpy (info->bus_info, dev->dev.parent->bus_id,sizeof (info->bus_info)); }static int smc911x_ethtool_nwayreset (struct net_device *dev)
drivers/net/smc91x.c +1 -1
@@ -1712,7 +1712,7 @@ smc_ethtool_getdrvinfo(struct net_device *dev, struct ethtool_drvinfo *info) {strncpy (info->driver,CARDNAME ,sizeof (info->driver));strncpy (info->version, version,sizeof (info->version)); -strncpy (info->bus_info, dev->class_dev.dev->bus_id,sizeof (info->bus_info)); +strncpy (info->bus_info, dev->dev.parent->bus_id,sizeof (info->bus_info)); }static int smc_ethtool_nwayreset (struct net_device *dev)
drivers/net/wireless/hostap/hostap_main.c +1 -1
@@ -84,7 +84,7 @@ struct net_device * hostap_add_interface(struct local_info *local,if (strchr (dev->name,'%' )) ret =dev_alloc_name (dev, dev->name); -SET_NETDEV_DEV (dev, mdev->class_dev.dev); +SET_NETDEV_DEV (dev, mdev->dev.parent);if (ret >=0 ) ret =register_netdevice (dev);
drivers/net/wireless/orinoco.c +2 -2
@@ -4293,8 +4293,8 @@ static void orinoco_get_drvinfo(struct net_device *dev,strncpy (info->driver,DRIVER_NAME ,sizeof (info->driver) -1 );strncpy (info->version,DRIVER_VERSION ,sizeof (info->version) -1 );strncpy (info->fw_version, priv->fw_name,sizeof (info->fw_version) -1 ); -if (dev->class_dev.dev) -strncpy (info->bus_info, dev->class_dev.dev->bus_id, +if (dev->dev.parent) +strncpy (info->bus_info, dev->dev.parent->bus_id,sizeof (info->bus_info) -1 );else snprintf(info->bus_info, sizeof(info->bus_info) - 1,
drivers/net/wireless/orinoco_cs.c +1 -1
@@ -332,7 +332,7 @@ orinoco_cs_config(struct pcmcia_device *link)/* Finally, report what we've done */ printk (KERN_DEBUG "%s: " DRIVER_NAME " at %s, irq %d, io " -"0x%04x-0x%04x\n" , dev->name, dev->class_dev.dev->bus_id, +"0x%04x-0x%04x\n" , dev->name, dev->dev.parent->bus_id, link->irq.AssignedIRQ, link->io.BasePort1, link->io.BasePort1 + link->io.NumPorts1 -1 );
drivers/net/wireless/spectrum_cs.c +1 -1
@@ -806,7 +806,7 @@ spectrum_cs_config(struct pcmcia_device *link)/* Finally, report what we've done */ printk (KERN_DEBUG "%s: " DRIVER_NAME " at %s, irq %d, io " -"0x%04x-0x%04x\n" , dev->name, dev->class_dev.dev->bus_id, +"0x%04x-0x%04x\n" , dev->name, dev->dev.parent->bus_id, link->irq.AssignedIRQ, link->io.BasePort1, link->io.BasePort1 + link->io.NumPorts1 -1 );
include/linux/netdevice.h +3 -2
@@ -529,10 +529,11 @@ struct net_devicestruct net_bridge_port *br_port;/* class/net/name entry */ -struct class_device class_dev; +struct device dev;/* space for optional statistics and wireless sysfs groups */ struct attribute_group *sysfs_groups[3 ]; }; +#define to_net_dev (d) container_of(d, struct net_device, dev)#define NETDEV_ALIGN 32#define NETDEV_ALIGN_CONST (NETDEV_ALIGN - 1)
@@ -548,7 +549,7 @@ static inline void *netdev_priv(struct net_device *dev)/* Set the sysfs physical device reference for the network logical device * if set prior to registration will cause a symlink during initialization. */ -#define SET_NETDEV_DEV (net, pdev) ((net)->class_dev.dev = (pdev)) +#define SET_NETDEV_DEV (net, pdev) ((net)->dev.parent = (pdev))struct packet_type {__be16 type;/* This is really htons(ether_type). */
net/bridge/br_if.c +1 -1
@@ -286,7 +286,7 @@ static struct net_bridge_port *new_nbp(struct net_bridge *br,kobject_init (&p->kobj);kobject_set_name (&p->kobj,SYSFS_BRIDGE_PORT_ATTR ); p->kobj.ktype = &brport_ktype; - p->kobj.parent = &(dev->class_dev.kobj); + p->kobj.parent = &(dev->dev.kobj); p->kobj.kset =NULL ;return p;
net/bridge/br_sysfs_br.c +127 -107
395 lines not on this page · raw message
net/bridge/br_sysfs_if.c +1 -1
@@ -211,7 +211,7 @@ int br_sysfs_addif(struct net_bridge_port *p)struct brport_attribute **a;int err; - err =sysfs_create_link (&p->kobj, &br->dev->class_dev.kobj, + err =sysfs_create_link (&p->kobj, &br->dev->dev.kobj,SYSFS_BRIDGE_PORT_LINK );if (err) goto out2;
net/core/dev.c +3 -3
@@ -751,7 +751,7 @@ int dev_change_name(struct net_device *dev, char *newname)else strlcpy (dev->name, newname,IFNAMSIZ ); - err =class_device_rename (&dev->class_dev, dev->name); + err =device_rename (&dev->dev, dev->name);if (!err) {hlist_del (&dev->name_hlist);hlist_add_head (&dev->name_hlist,dev_name_hash (dev->name));
@@ -3221,8 +3221,8 @@ void free_netdev(struct net_device *dev)BUG_ON (dev->reg_state !=NETREG_UNREGISTERED ); dev->reg_state =NETREG_RELEASED ; -/* will free via class release */ -class_device_put (&dev->class_dev); +/* will free via device release */ +put_device (&dev->dev);#else kfree ((char *)dev - dev->padded);#endif
net/core/net-sysfs.c +93 -82
349 lines not on this page · raw message
net/core/skbuff.c +1 -1
@@ -268,7 +268,7 @@ nodata:struct sk_buff *__netdev_alloc_skb (struct net_device *dev,unsigned int length,gfp_t gfp_mask) { -int node = dev->class_dev.dev ?dev_to_node (dev->class_dev.dev) :-1 ; +int node = dev->dev.parent ?dev_to_node (dev->dev.parent) :-1 ;struct sk_buff *skb; skb =__alloc_skb (length +NET_SKB_PAD , gfp_mask,0 , node);
Signature · 1 line
1.4.4.4
PATCH 5/28 driver core: Remove device_is_registered() in device_move().
From: Cornelia Huck <[email protected]>
device_is_registered() will always be false for a device with no bus. Remove this check and trust the caller to know what they're doing.
--- drivers/base/core.c | 4 ---- 1 files changed, 0 insertions(+), 4 deletions(-)
drivers/base/core.c +0 -4
@@ -1004,10 +1004,6 @@ int device_move(struct device *dev, struct device *new_parent)if (!dev)return -EINVAL ; -if (!device_is_registered (dev)) { - error = -EINVAL ; - goto out; - } new_parent =get_device (new_parent);if (!new_parent) { error = -EINVAL ;
Signature · 1 line
1.4.4.4
PATCH 6/28 driver core: Allow device_move(dev, NULL).
From: Cornelia Huck <[email protected]>
If we allow NULL as the new parent in device_move(), we need to make sure that the device is placed into the same place as it would if it was newly registered:
- Consider the device virtual tree. In order to be able to reuse code, setup_parent() has been tweaked a bit.
- kobject_move() can fall back to the kset's kobject.
- sysfs_move_dir() uses the sysfs root dir as fallback.
--- drivers/base/core.c | 76 +++++++++++++++++++++++++++++++------------------- fs/sysfs/dir.c | 6 +--- lib/kobject.c | 6 ++-- 3 files changed, 52 insertions(+), 36 deletions(-)
drivers/base/core.c +47 -29
@@ -390,22 +390,23 @@ void device_initialize(struct device *dev) }#ifdef CONFIG_SYSFS_DEPRECATED -static int setup_parent (struct device *dev,struct device *parent) +static struct kobject *get_device_parent (struct device *dev, +struct device *parent) {/* Set the parent to the class, not the parent device */ /* this keeps sysfs from having a symlink to make old udevs happy */ if (dev->class) - dev->kobj.parent = &dev->class->subsys.kset.kobj; +return &dev->class->subsys.kset.kobj;else if (parent) - dev->kobj.parent = &parent->kobj; +return &parent->kobj; -return 0 ; +return NULL ; }#else -static int virtual_device_parent (struct device *dev) +static struct kobject *virtual_device_parent (struct device *dev) {if (!dev->class) -return -ENODEV ; +return ERR_PTR (-ENODEV );if (!dev->class->virtual_dir) {static struct kobject *virtual_dir =NULL ;
@@ -415,25 +416,31 @@ static int virtual_device_parent(struct device *dev) dev->class->virtual_dir = kobject_add_dir(virtual_dir, dev->class->name); } - dev->kobj.parent = dev->class->virtual_dir; -return 0 ; +return dev->class->virtual_dir; } -static int setup_parent (struct device *dev,struct device *parent) +static struct kobject *get_device_parent (struct device *dev, +struct device *parent) { -int error; -/* if this is a class device, and has no parent, create one */ if ((dev->class) && (parent ==NULL )) { - error =virtual_device_parent (dev); -if (error) -return error; +return virtual_device_parent (dev); }else if (parent) - dev->kobj.parent = &parent->kobj; +return &parent->kobj; +return NULL ; +} +#endif +static int setup_parent (struct device *dev,struct device *parent) +{ +struct kobject *kobj; + kobj =get_device_parent (dev, parent); +if (IS_ERR (kobj)) +return PTR_ERR (kobj); +if (kobj) + dev->kobj.parent = kobj;return 0 ; } -#endif /** * device_add - add device to device hierarchy.
@@ -976,12 +983,18 @@ static int device_move_class_links(struct device *dev,sysfs_remove_link (&dev->kobj,"device" );sysfs_remove_link (&old_parent->kobj, class_name); } - error =sysfs_create_link (&dev->kobj, &new_parent->kobj,"device" ); -if (error) - goto out; - error =sysfs_create_link (&new_parent->kobj, &dev->kobj, class_name); -if (error) -sysfs_remove_link (&dev->kobj,"device" ); +if (new_parent) { + error =sysfs_create_link (&dev->kobj, &new_parent->kobj, +"device" ); +if (error) + goto out; + error =sysfs_create_link (&new_parent->kobj, &dev->kobj, + class_name); +if (error) +sysfs_remove_link (&dev->kobj,"device" ); + } +else + error =0 ; out:kfree (class_name);return error;
@@ -993,25 +1006,28 @@ out:/** * device_move - moves a device to a new parent * @dev: the pointer to the struct device to be moved -* @new_parent: the new parent of the device +* @new_parent: the new parent of the device (can by NULL) */ int device_move (struct device *dev,struct device *new_parent) {int error;struct device *old_parent; +struct kobject *new_parent_kobj; dev =get_device (dev);if (!dev)return -EINVAL ; new_parent =get_device (new_parent); -if (!new_parent) { - error = -EINVAL ; + new_parent_kobj =get_device_parent (dev, new_parent); +if (IS_ERR (new_parent_kobj)) { + error =PTR_ERR (new_parent_kobj); +put_device (new_parent); goto out; }pr_debug ("DEVICE: moving '%s' to '%s'\n" , dev->bus_id, - new_parent->bus_id); - error =kobject_move (&dev->kobj, &new_parent->kobj); + new_parent ? new_parent->bus_id :"<NULL>" ); + error =kobject_move (&dev->kobj, new_parent_kobj);if (error) {put_device (new_parent); goto out;
@@ -1020,7 +1036,8 @@ int device_move(struct device *dev, struct device *new_parent) dev->parent = new_parent;if (old_parent)klist_remove (&dev->knode_parent); -klist_add_tail (&dev->knode_parent, &new_parent->klist_children); +if (new_parent) +klist_add_tail (&dev->knode_parent, &new_parent->klist_children);if (!dev->class) goto out_put; error =device_move_class_links (dev, old_parent, new_parent);
@@ -1028,7 +1045,8 @@ int device_move(struct device *dev, struct device *new_parent)/* We ignore errors on cleanup since we're hosed anyway... */ device_move_class_links (dev, new_parent, old_parent);if (!kobject_move (&dev->kobj, &old_parent->kobj)) { -klist_remove (&dev->knode_parent); +if (new_parent) +klist_remove (&dev->knode_parent);if (old_parent)klist_add_tail (&dev->knode_parent, &old_parent->klist_children);
fs/sysfs/dir.c +2 -4
@@ -378,12 +378,10 @@ int sysfs_move_dir(struct kobject *kobj, struct kobject *new_parent)struct sysfs_dirent *new_parent_sd, *sd;int error; -if (!new_parent) -return -EINVAL ; - old_parent_dentry = kobj->parent ? kobj->parent->dentry : sysfs_mount->mnt_sb->s_root; - new_parent_dentry = new_parent->dentry; + new_parent_dentry = new_parent ? + new_parent->dentry : sysfs_mount->mnt_sb->s_root; again:mutex_lock (&old_parent_dentry->d_inode->i_mutex);
lib/kobject.c +3 -3
@@ -314,7 +314,7 @@ int kobject_rename(struct kobject * kobj, const char *new_name)/** * kobject_move - move object to another parent * @kobj: object in question. -* @new_parent: object's new parent +* @new_parent: object's new parent (can be NULL) */ int kobject_move (struct kobject *kobj,struct kobject *new_parent)
@@ -330,8 +330,8 @@ int kobject_move(struct kobject *kobj, struct kobject *new_parent)return -EINVAL ; new_parent =kobject_get (new_parent);if (!new_parent) { - error = -EINVAL ; - goto out; +if (kobj->kset) + new_parent =kobject_get (&kobj->kset->kobj); }/* old object path */ devpath =kobject_get_path (kobj,GFP_KERNEL );
Signature · 1 line
1.4.4.4
PATCH 7/28 MODULES: add the module name for built in kernel drivers
From: Kay Sievers <[email protected]>
--- include/linux/device.h | 1 + include/linux/module.h | 2 +- kernel/module.c | 33 ++++++++++++++++++++++++--------- kernel/params.c | 12 +++++------- 4 files changed, 31 insertions(+), 17 deletions(-)
include/linux/device.h +1 -0
@@ -126,6 +126,7 @@ struct device_driver {struct klist_node knode_bus;struct module * owner; +const char * mod_name;/* used for built-in modules */ int (*probe) (struct device * dev);int (*remove) (struct device * dev);
include/linux/module.h +1 -1
@@ -58,6 +58,7 @@ struct module_kobject {struct kobject kobj;struct module *mod; +struct kobject *drivers_dir; };/* These are either module local, or the kernel's dummy ones. */
@@ -263,7 +264,6 @@ struct modulestruct module_attribute *modinfo_attrs;const char *version;const char *srcversion; -struct kobject *drivers_dir;/* Exported symbols */ const struct kernel_symbol *syms;
kernel/module.c +24 -9
@@ -1131,8 +1131,8 @@ static int mod_sysfs_setup(struct module *mod,if (err) goto out; - mod->drivers_dir =kobject_add_dir (&mod->mkobj.kobj,"drivers" ); -if (!mod->drivers_dir) { + mod->mkobj.drivers_dir =kobject_add_dir (&mod->mkobj.kobj,"drivers" ); +if (!mod->mkobj.drivers_dir) { err = -ENOMEM ; goto out_unreg; }
@@ -1151,7 +1151,7 @@ static int mod_sysfs_setup(struct module *mod, out_unreg_param:module_param_sysfs_remove (mod); out_unreg_drivers: -kobject_unregister (mod->drivers_dir); +kobject_unregister (mod->mkobj.drivers_dir); out_unreg:kobject_del (&mod->mkobj.kobj);kobject_put (&mod->mkobj.kobj);
@@ -1163,7 +1163,7 @@ static void mod_kobject_remove(struct module *mod) {module_remove_modinfo_attrs (mod);module_param_sysfs_remove (mod); -kobject_unregister (mod->drivers_dir); +kobject_unregister (mod->mkobj.drivers_dir);kobject_unregister (&mod->mkobj.kobj); }
@@ -2344,15 +2344,30 @@ void module_add_driver(struct module *mod, struct device_driver *drv) {char *driver_name;int no_warn; +struct module_kobject *mk =NULL ; -if (!mod || !drv) +if (!drv) +return ; + +if (mod) + mk = &mod->mkobj; +else if (drv->mod_name) { +struct kobject *mkobj; + +/* Lookup built-in module entry in /sys/modules */ + mkobj =kset_find_obj (&module_subsys.kset, drv->mod_name); +if (mkobj) + mk = container_of(mkobj, struct module_kobject, kobj); + } + +if (!mk)return ;/* Don't check return codes; these calls are idempotent */ - no_warn =sysfs_create_link (&drv->kobj, &mod->mkobj.kobj,"module" ); + no_warn =sysfs_create_link (&drv->kobj, &mk->kobj,"module" ); driver_name =make_driver_name (drv);if (driver_name) { - no_warn =sysfs_create_link (mod->drivers_dir, &drv->kobj, + no_warn =sysfs_create_link (mk->drivers_dir, &drv->kobj, driver_name);kfree (driver_name); }
@@ -2367,10 +2382,10 @@ void module_remove_driver(struct device_driver *drv)return ;sysfs_remove_link (&drv->kobj,"module" ); -if (drv->owner && drv->owner->drivers_dir) { +if (drv->owner && drv->owner->mkobj.drivers_dir) { driver_name =make_driver_name (drv);if (driver_name) { -sysfs_remove_link (drv->owner->drivers_dir, +sysfs_remove_link (drv->owner->mkobj.drivers_dir, driver_name);kfree (driver_name); }
kernel/params.c +5 -7
@@ -561,14 +561,12 @@ static void __init kernel_param_sysfs_setup(const char *name, mk->mod =THIS_MODULE ;kobj_set_kset_s (mk, module_subsys);kobject_set_name (&mk->kobj, name); - ret =kobject_register (&mk->kobj); +kobject_init (&mk->kobj); + ret =kobject_add (&mk->kobj);BUG_ON (ret <0 ); - -/* no need to keep the kobject if no parameter is exported */ -if (!param_sysfs_setup (mk, kparam, num_params, name_skip)) { -kobject_unregister (&mk->kobj); -kfree (mk); - } +param_sysfs_setup (mk, kparam, num_params, name_skip); + mk->drivers_dir =kobject_add_dir (&mk->kobj,"drivers" ); +kobject_uevent (&mk->kobj,KOBJ_ADD ); }/*
Signature · 1 line
1.4.4.4
PATCH 8/28 Modules: only add drivers/ direcory if needed
From: Greg Kroah-Hartman <[email protected]>
This changes the module core to only create the drivers/ directory if we are going to put something in it.
--- kernel/module.c | 20 +++++++++++--------- kernel/params.c | 1 - 2 files changed, 11 insertions(+), 10 deletions(-)
kernel/module.c +11 -9
@@ -1131,12 +1131,6 @@ static int mod_sysfs_setup(struct module *mod,if (err) goto out; - mod->mkobj.drivers_dir =kobject_add_dir (&mod->mkobj.kobj,"drivers" ); -if (!mod->mkobj.drivers_dir) { - err = -ENOMEM ; - goto out_unreg; - } - err =module_param_sysfs_setup (mod, kparam, num_params);if (err) goto out_unreg_drivers;
@@ -1151,8 +1145,6 @@ static int mod_sysfs_setup(struct module *mod, out_unreg_param:module_param_sysfs_remove (mod); out_unreg_drivers: -kobject_unregister (mod->mkobj.drivers_dir); -out_unreg:kobject_del (&mod->mkobj.kobj);kobject_put (&mod->mkobj.kobj); out:
@@ -1163,7 +1155,8 @@ static void mod_kobject_remove(struct module *mod) {module_remove_modinfo_attrs (mod);module_param_sysfs_remove (mod); -kobject_unregister (mod->mkobj.drivers_dir); +if (mod->mkobj.drivers_dir) +kobject_unregister (mod->mkobj.drivers_dir);kobject_unregister (&mod->mkobj.kobj); }
@@ -2340,6 +2333,14 @@ static char *make_driver_name(struct device_driver *drv)return driver_name; } +static void module_create_drivers_dir (struct module_kobject *mk) +{ +if (!mk || mk->drivers_dir) +return ; + + mk->drivers_dir =kobject_add_dir (&mk->kobj,"drivers" ); +} +void module_add_driver (struct module *mod,struct device_driver *drv) {char *driver_name;
@@ -2367,6 +2368,7 @@ void module_add_driver(struct module *mod, struct device_driver *drv) no_warn =sysfs_create_link (&drv->kobj, &mk->kobj,"module" ); driver_name =make_driver_name (drv);if (driver_name) { +module_create_drivers_dir (mk); no_warn =sysfs_create_link (mk->drivers_dir, &drv->kobj, driver_name);kfree (driver_name);
kernel/params.c +0 -1
@@ -565,7 +565,6 @@ static void __init kernel_param_sysfs_setup(const char *name, ret =kobject_add (&mk->kobj);BUG_ON (ret <0 );param_sysfs_setup (mk, kparam, num_params, name_skip); - mk->drivers_dir =kobject_add_dir (&mk->kobj,"drivers" );kobject_uevent (&mk->kobj,KOBJ_ADD ); }
Signature · 1 line
1.4.4.4
PATCH 9/28 PCI: add the sysfs driver name to all modules
From: Greg Kroah-Hartman <[email protected]>
This adds the module name to all PCI drivers, if they are built into the kernel or not. It will show up in /sys/modules/MODULE_NAME/drivers/
It also fixes up the IDE core, which was calling __pci_register_driver() directly.
--- drivers/ide/setup-pci.c | 7 ++++--- drivers/pci/pci-driver.c | 4 +++- include/linux/ide.h | 4 ++-- include/linux/pci.h | 5 +++-- 4 files changed, 12 insertions(+), 8 deletions(-)
drivers/ide/setup-pci.c +4 -3
@@ -783,10 +783,11 @@ static LIST_HEAD(ide_pci_drivers);* Returns are the same as for pci_register_driver */ -int __ide_pci_register_driver (struct pci_driver *driver,struct module *module) +int __ide_pci_register_driver (struct pci_driver *driver,struct module *module, +const char *mod_name) {if (!pre_init) -return __pci_register_driver (driver, module); +return __pci_register_driver (driver, module, mod_name); driver->driver.owner = module;list_add_tail (&driver->node, &ide_pci_drivers);return 0 ;
@@ -862,6 +863,6 @@ void __init ide_scan_pcibus (int scan_direction) {list_del (l); d = list_entry(l, struct pci_driver, node); -__pci_register_driver (d, d->driver.owner); +__pci_register_driver (d, d->driver.owner, d->driver.mod_name); } }
drivers/pci/pci-driver.c +3 -1
@@ -422,7 +422,8 @@ static struct kobj_type pci_driver_kobj_type = {* If no error occurred, the driver remains registered even if * no device was claimed during registration. */ -int __pci_register_driver (struct pci_driver *drv,struct module *owner) +int __pci_register_driver (struct pci_driver *drv,struct module *owner, +const char *mod_name) {int error;
@@ -430,6 +431,7 @@ int __pci_register_driver(struct pci_driver *drv, struct module *owner) drv->driver.name = drv->name; drv->driver.bus = &pci_bus_type; drv->driver.owner = owner; + drv->driver.mod_name = mod_name; drv->driver.kobj.ktype = &pci_driver_kobj_type;if (pci_multithread_probe)
include/linux/ide.h +2 -2
@@ -1192,8 +1192,8 @@ void ide_init_disk(struct gendisk *, ide_drive_t *);extern int ideprobe_init (void );extern void ide_scan_pcibus (int scan_direction)__init ; -extern int __ide_pci_register_driver (struct pci_driver *driver,struct module *owner); -#define ide_pci_register_driver (d) __ide_pci_register_driver(d, THIS_MODULE) +extern int __ide_pci_register_driver (struct pci_driver *driver,struct module *owner,const char *mod_name); +#define ide_pci_register_driver (d) __ide_pci_register_driver(d, THIS_MODULE, KBUILD_MODNAME)void ide_pci_setup_ports (struct pci_dev *,struct ide_pci_device_s *,int ,ata_index_t *);extern void ide_setup_pci_noise (struct pci_dev *dev,struct ide_pci_device_s *d);
include/linux/pci.h +3 -2
@@ -573,10 +573,11 @@ int __must_check pci_bus_alloc_resource(struct pci_bus *bus,void pci_enable_bridges (struct pci_bus *bus);/* Proper probing supporting hot-pluggable devices */ -int __must_check __pci_register_driver (struct pci_driver *,struct module *); +int __must_check __pci_register_driver (struct pci_driver *,struct module *, +const char *mod_name);static inline int __must_check pci_register_driver (struct pci_driver *driver) { -return __pci_register_driver (driver,THIS_MODULE ); +return __pci_register_driver (driver,THIS_MODULE ,KBUILD_MODNAME ); }void pci_unregister_driver (struct pci_driver *);
Signature · 1 line
1.4.4.4
PATCH 10/28 SERIO: add the sysfs driver name to all modules
From: Greg Kroah-Hartman <[email protected]>
This adds the module name to all SERIO drivers, if they are built into the kernel or not. It will show up in /sys/modules/MODULE_NAME/drivers/
--- drivers/input/serio/serio.c | 6 ++++-- include/linux/serio.h | 5 +++++ 2 files changed, 9 insertions(+), 2 deletions(-)
drivers/input/serio/serio.c +4 -2
@@ -45,7 +45,7 @@ EXPORT_SYMBOL(serio_interrupt);EXPORT_SYMBOL (__serio_register_port);EXPORT_SYMBOL (serio_unregister_port);EXPORT_SYMBOL (serio_unregister_child_port); -EXPORT_SYMBOL (serio_register_driver); +EXPORT_SYMBOL (__serio_register_driver);EXPORT_SYMBOL (serio_unregister_driver);EXPORT_SYMBOL (serio_open);EXPORT_SYMBOL (serio_close);
@@ -789,12 +789,14 @@ static void serio_attach_driver(struct serio_driver *drv) drv->driver.name, error); } -int serio_register_driver (struct serio_driver *drv) +int __serio_register_driver (struct serio_driver *drv,struct module *owner,const char *mod_name) {int manual_bind = drv->manual_bind;int error; drv->driver.bus = &serio_bus; + drv->driver.owner = owner; + drv->driver.mod_name = mod_name;/* * Temporarily disable automatic binding because probing
include/linux/serio.h +5 -0
@@ -86,6 +86,11 @@ static inline void serio_register_port(struct serio *serio)void serio_unregister_port (struct serio *serio);void serio_unregister_child_port (struct serio *serio); +int __serio_register_driver (struct serio_driver *drv,struct module *owner,const char *mod_name); +static inline int serio_register_driver (struct serio_driver *drv) +{ +return __serio_register_driver (drv,THIS_MODULE ,KBUILD_MODNAME ); +}int serio_register_driver (struct serio_driver *drv);void serio_unregister_driver (struct serio_driver *drv);
Signature · 1 line
1.4.4.4
PATCH 11/28 USB: add the sysfs driver name to all modules
From: Greg Kroah-Hartman <[email protected]>
This adds the module name to all USB drivers, if they are built into the kernel or not. It will show up in /sys/modules/MODULE_NAME/drivers/
--- drivers/usb/core/driver.c | 4 +++- include/linux/usb.h | 5 +++-- 2 files changed, 6 insertions(+), 3 deletions(-)
drivers/usb/core/driver.c +3 -1
@@ -750,7 +750,8 @@ EXPORT_SYMBOL_GPL(usb_deregister_device_driver);* usb_register_dev() to enable that functionality. This function no longer * takes care of that. */ -int usb_register_driver (struct usb_driver *new_driver,struct module *owner) +int usb_register_driver (struct usb_driver *new_driver,struct module *owner, +const char *mod_name) {int retval =0 ;
@@ -763,6 +764,7 @@ int usb_register_driver(struct usb_driver *new_driver, struct module *owner) new_driver->drvwrap.driver.probe = usb_probe_interface; new_driver->drvwrap.driver.remove = usb_unbind_interface; new_driver->drvwrap.driver.owner = owner; + new_driver->drvwrap.driver.mod_name = mod_name;spin_lock_init (&new_driver->dynids.lock);INIT_LIST_HEAD (&new_driver->dynids.list);
include/linux/usb.h +3 -2
@@ -868,10 +868,11 @@ struct usb_class_driver {* use these in module_init()/module_exit() * and don't forget MODULE_DEVICE_TABLE(usb, ...) */ -extern int usb_register_driver (struct usb_driver *,struct module *); +extern int usb_register_driver (struct usb_driver *,struct module *, +const char *);static inline int usb_register (struct usb_driver *driver) { -return usb_register_driver (driver,THIS_MODULE ); +return usb_register_driver (driver,THIS_MODULE ,KBUILD_MODNAME ); }extern void usb_deregister (struct usb_driver *);
Signature · 1 line
1.4.4.4
PATCH 12/28 /sys/modules/*/holders
From: Kay Sievers <[email protected]>
/sys/module/usbcore/
|-- drivers | |-- usb:hub -> ../../../subsystem/usb/drivers/hub | |-- usb:usb -> ../../../subsystem/usb/drivers/usb | `-- usb:usbfs -> ../../../subsystem/usb/drivers/usbfs |-- holders | |-- ehci_hcd -> ../../../module/ehci_hcd | |-- uhci_hcd -> ../../../module/uhci_hcd | |-- usb_storage -> ../../../module/usb_storage | `-- usbhid -> ../../../module/usbhid |-- initstate
--- include/linux/module.h | 1 + kernel/module.c | 37 +++++++++++++++++++++++++++++++------ kernel/params.c | 17 ++++++++++++++++- 3 files changed, 48 insertions(+), 7 deletions(-)
include/linux/module.h +1 -0
@@ -264,6 +264,7 @@ struct modulestruct module_attribute *modinfo_attrs;const char *version;const char *srcversion; +struct kobject *holders_dir;/* Exported symbols */ const struct kernel_symbol *syms;
kernel/module.c +31 -6
@@ -537,6 +537,8 @@ static int already_uses(struct module *a, struct module *b)static int use_module (struct module *a,struct module *b) {struct module_use *use; +int no_warn; +if (b ==NULL ||already_uses (a, b))return 1 ;if (!strong_try_module_get (b))
@@ -552,6 +554,7 @@ static int use_module(struct module *a, struct module *b) use->module_which_uses = a;list_add (&use->list, &b->modules_which_use_me); + no_warn =sysfs_create_link (b->holders_dir, &a->mkobj.kobj, a->name);return 1 ; }
@@ -569,6 +572,7 @@ static void module_unload_free(struct module *mod)module_put (i);list_del (&use->list);kfree (use); +sysfs_remove_link (i->holders_dir, mod->name);/* There can be at most one match. */ break ; }
@@ -1106,9 +1110,7 @@ static void module_remove_modinfo_attrs(struct module *mod)kfree (mod->modinfo_attrs); } -static int mod_sysfs_setup (struct module *mod, -struct kernel_param *kparam, -unsigned int num_params) +static int mod_sysfs_init (struct module *mod) {int err;
@@ -1125,15 +1127,30 @@ static int mod_sysfs_setup(struct module *mod,kobj_set_kset_s (&mod->mkobj, module_subsys); mod->mkobj.mod = mod; -/* delay uevent until full sysfs population */ kobject_init (&mod->mkobj.kobj); + +out: +return err; +} + +static int mod_sysfs_setup (struct module *mod, +struct kernel_param *kparam, +unsigned int num_params) +{ +int err; + +/* delay uevent until full sysfs population */ err =kobject_add (&mod->mkobj.kobj);if (err) goto out; + mod->holders_dir =kobject_add_dir (&mod->mkobj.kobj,"holders" ); +if (!mod->holders_dir) + goto out_unreg; + err =module_param_sysfs_setup (mod, kparam, num_params);if (err) - goto out_unreg_drivers; + goto out_unreg_holders; err =module_add_modinfo_attrs (mod);if (err)
@@ -1144,7 +1161,9 @@ static int mod_sysfs_setup(struct module *mod, out_unreg_param:module_param_sysfs_remove (mod); -out_unreg_drivers: +out_unreg_holders: +kobject_unregister (mod->holders_dir); +out_unreg:kobject_del (&mod->mkobj.kobj);kobject_put (&mod->mkobj.kobj); out:
@@ -1157,6 +1176,8 @@ static void mod_kobject_remove(struct module *mod)module_param_sysfs_remove (mod);if (mod->mkobj.drivers_dir)kobject_unregister (mod->mkobj.drivers_dir); +if (mod->holders_dir) +kobject_unregister (mod->holders_dir);kobject_unregister (&mod->mkobj.kobj); }
@@ -1761,6 +1782,10 @@ static struct module *load_module(void __user *umod,/* Now we've moved module, initialize linked lists, etc. */ module_unload_init (mod); +/* Initialize kobject, so we can reference it. */ +if (mod_sysfs_init (mod) !=0 ) + goto cleanup; +/* Set up license info based on the info section */ set_license (mod,get_modinfo (sechdrs, infoindex,"license" ));
kernel/params.c +16 -1
@@ -30,6 +30,8 @@ #define DEBUGP(fmt, a...)#endif +static struct kobj_type module_ktype; +static inline char dash2underscore (char c) {if (c =='-' )
@@ -671,6 +673,19 @@ static struct sysfs_ops module_sysfs_ops = { .store = module_attr_store, }; +static int uevent_filter (struct kset *kset,struct kobject *kobj) +{ +struct kobj_type *ktype =get_ktype (kobj); + +if (ktype == &module_ktype) +return 1 ; +return 0 ; +} + +static struct kset_uevent_ops module_uevent_ops = { + .filter = uevent_filter, +}; +#else static struct sysfs_ops module_sysfs_ops = { .show = NULL,
@@ -682,7 +697,7 @@ static struct kobj_type module_ktype = { .sysfs_ops = &module_sysfs_ops, }; -decl_subsys (module, &module_ktype,NULL ); +decl_subsys (module, &module_ktype, &module_uevent_ops);/* * param_sysfs_init - wrapper for built-in params support
Signature · 1 line
1.4.4.4
PATCH 13/28 driver core fixes: make_class_name() retval checks
From: Cornelia Huck <[email protected]>
Make make_class_name() return NULL on error and fixup callers in the driver core.
--- drivers/base/class.c | 21 ++++++++++++++------- drivers/base/core.c | 17 +++++++++++------ 2 files changed, 25 insertions(+), 13 deletions(-)
drivers/base/class.c +14 -7
@@ -364,7 +364,7 @@ char *make_class_name(const char *name, struct kobject *kobj) class_name =kmalloc (size,GFP_KERNEL );if (!class_name) -return ERR_PTR (-ENOMEM ); +return NULL ;strcpy (class_name, name);strcat (class_name,":" );
@@ -411,8 +411,11 @@ static int make_deprecated_class_device_links(struct class_device *class_dev)return 0 ; class_name =make_class_name (class_dev->class->name, &class_dev->kobj); - error =sysfs_create_link (&class_dev->dev->kobj, &class_dev->kobj, - class_name); +if (class_name) + error =sysfs_create_link (&class_dev->dev->kobj, + &class_dev->kobj, class_name); +else + error = -ENOMEM ;kfree (class_name);return error; }
@@ -425,7 +428,8 @@ static void remove_deprecated_class_device_links(struct class_device *class_dev)return ; class_name =make_class_name (class_dev->class->name, &class_dev->kobj); -sysfs_remove_link (&class_dev->dev->kobj, class_name); +if (class_name) +sysfs_remove_link (&class_dev->dev->kobj, class_name); kfree(class_name); }#else
@@ -863,9 +867,12 @@ int class_device_rename(struct class_device *class_dev, char *new_name)if (class_dev->dev) { new_class_name =make_class_name (class_dev->class->name, &class_dev->kobj); -sysfs_create_link (&class_dev->dev->kobj, &class_dev->kobj, - new_class_name); -sysfs_remove_link (&class_dev->dev->kobj, old_class_name); +if (new_class_name) +sysfs_create_link (&class_dev->dev->kobj, + &class_dev->kobj, new_class_name); +if (old_class_name) +sysfs_remove_link (&class_dev->dev->kobj, + old_class_name); }#endif class_device_put (class_dev);
drivers/base/core.c +11 -6
@@ -527,9 +527,13 @@ int device_add(struct device *dev) &dev->kobj, dev->bus_id);#ifdef CONFIG_SYSFS_DEPRECATED if (parent) { -sysfs_create_link (&dev->kobj, &dev->parent->kobj,"device" ); - class_name =make_class_name (dev->class->name, &dev->kobj); -sysfs_create_link (&dev->parent->kobj, &dev->kobj, class_name); +sysfs_create_link (&dev->kobj, &dev->parent->kobj, +"device" ); + class_name =make_class_name (dev->class->name, + &dev->kobj); +if (class_name) +sysfs_create_link (&dev->parent->kobj, + &dev->kobj, class_name); }#endif }
@@ -672,7 +676,9 @@ void device_del(struct device * dev)if (parent) {char *class_name =make_class_name (dev->class->name, &dev->kobj); -sysfs_remove_link (&dev->parent->kobj, class_name); +if (class_name) +sysfs_remove_link (&dev->parent->kobj, + class_name);kfree (class_name);sysfs_remove_link (&dev->kobj,"device" ); }
@@ -975,8 +981,7 @@ static int device_move_class_links(struct device *dev, class_name =make_class_name (dev->class->name, &dev->kobj);if (!class_name) { - error =PTR_ERR (class_name); - class_name =NULL ; + error = -ENOMEM ; goto out; }if (old_parent) {
Signature · 1 line
1.4.4.4
PATCH 14/28 driver core fixes: device_register() retval check in platform.c
From: Cornelia Huck <[email protected]>
Check the return value of device_register() in platform_bus_init().
--- drivers/base/platform.c | 11 +++++++++-- 1 files changed, 9 insertions(+), 2 deletions(-)
drivers/base/platform.c +9 -2
@@ -611,8 +611,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
Signature · 1 line
1.4.4.4
PATCH 15/28 driver core: Don't stop probing on ->probe errors.
From: Cornelia Huck <[email protected]>
Don't stop on the first ->probe error that is not -ENODEV/-ENXIO.
There might be a driver registered returning an unresonable return code, and this stops probing completely even though it may make sense to try the next possible driver. At worst, we may end up with an unbound device.
--- drivers/base/dd.c | 13 ++++++------- 1 files changed, 6 insertions(+), 7 deletions(-)
drivers/base/dd.c +6 -7
@@ -136,18 +136,17 @@ probe_failed:driver_sysfs_remove (dev); dev->driver =NULL ; -if (ret == -ENODEV || ret == -ENXIO ) { -/* Driver matched, but didn't support device -* or device not found. -* Not an error; keep going. -*/ - ret =0 ; - }else { +if (ret != -ENODEV && ret != -ENXIO ) {/* driver matched but the probe failed */ printk (KERN_WARNING "%s: probe of %s failed with error %d\n" , drv->name, dev->bus_id, ret); } +/* +* Ignore errors returned by ->probe so that the next driver can try +* its luck. +*/ + ret =0 ; done:kfree (data);atomic_dec (&probe_count);
Signature · 1 line
1.4.4.4
PATCH 16/28 driver core: Change function call order in device_bind_driver().
From: Cornelia Huck <[email protected]>
Change function call order in device_bind_driver().
If we create symlinks (which might fail) before adding the device to the list we don't have to clean up afterwards (which we didn't).
--- drivers/base/dd.c | 8 ++++++-- 1 files changed, 6 insertions(+), 2 deletions(-)
drivers/base/dd.c +6 -2
@@ -86,8 +86,12 @@ static void driver_sysfs_remove(struct device *dev)*/ int device_bind_driver (struct device *dev) { -driver_bound (dev); -return driver_sysfs_add (dev); +int ret; + + ret =driver_sysfs_add (dev); +if (!ret) +driver_bound (dev); +return ret; }struct stupid_thread_structure {
Signature · 1 line
1.4.4.4
PATCH 17/28 Driver core: fix race in sysfs between sysfs_remove_file() and read()/write()
From: Oliver Neukum <[email protected]>
This patch prevents a race between IO and removing a file from sysfs. It introduces a list of sysfs_buffers associated with a file at the inode. Upon removal of a file the list is walked and the buffers marked orphaned. IO to orphaned buffers fails with -ENODEV. The driver can safely free associated data structures or be unloaded.
--- fs/sysfs/bin.c | 1 + fs/sysfs/dir.c | 1 + fs/sysfs/file.c | 67 ++++++++++++++++++++++++++++++++++++++------------- fs/sysfs/group.c | 1 + fs/sysfs/inode.c | 24 ++++++++++++++++++ fs/sysfs/mount.c | 9 +++++++ fs/sysfs/symlink.c | 1 + fs/sysfs/sysfs.h | 16 ++++++++++++ 8 files changed, 103 insertions(+), 17 deletions(-)
fs/sysfs/bin.c +1 -0
@@ -16,6 +16,7 @@#include <linux/slab.h> #include <asm/uaccess.h> +#include <asm/semaphore.h> #include "sysfs.h"
fs/sysfs/dir.c +1 -0
@@ -9,6 +9,7 @@#include <linux/module.h> #include <linux/kobject.h> #include <linux/namei.h> +#include <asm/semaphore.h> #include "sysfs.h" DECLARE_RWSEM (sysfs_rename_sem);
fs/sysfs/file.c +50 -17
144 lines not on this page · raw message
fs/sysfs/group.c +1 -0
@@ -13,6 +13,7 @@#include <linux/dcache.h> #include <linux/namei.h> #include <linux/err.h> +#include <asm/semaphore.h> #include "sysfs.h"
fs/sysfs/inode.c +24 -0
@@ -13,6 +13,7 @@#include <linux/backing-dev.h> #include <linux/capability.h> #include <linux/errno.h> +#include <asm/semaphore.h> #include "sysfs.h" extern struct super_block * sysfs_sb;
@@ -209,6 +210,22 @@ const unsigned char * sysfs_get_name(struct sysfs_dirent *sd)return NULL ; } +static inline void orphan_all_buffers (struct inode *node) +{ +struct sysfs_buffer_collection *set = node->i_private; +struct sysfs_buffer *buf; + +mutex_lock (&node->i_mutex); +if (node->i_private) { +list_for_each_entry (buf, &set->associates, associates) { +down (&buf->sem); + buf->orphaned =1 ; +up (&buf->sem); + } + } +mutex_unlock (&node->i_mutex); +} +/* * Unhashes the dentry corresponding to given sysfs_dirent
@@ -217,16 +234,23 @@ const unsigned char * sysfs_get_name(struct sysfs_dirent *sd)void sysfs_drop_dentry (struct sysfs_dirent * sd,struct dentry * parent) {struct dentry * dentry = sd->s_dentry; +struct inode *inode;if (dentry) {spin_lock (&dcache_lock);spin_lock (&dentry->d_lock);if (!(d_unhashed (dentry) && dentry->d_inode)) { + inode = dentry->d_inode; +spin_lock (&inode->i_lock); +__iget (inode); +spin_unlock (&inode->i_lock);dget_locked (dentry);__d_drop (dentry);spin_unlock (&dentry->d_lock);spin_unlock (&dcache_lock);simple_unlink (parent->d_inode, dentry); +orphan_all_buffers (inode); +iput (inode); }else {spin_unlock (&dentry->d_lock);spin_unlock (&dcache_lock);
fs/sysfs/mount.c +9 -0
@@ -8,6 +8,7 @@#include <linux/mount.h> #include <linux/pagemap.h> #include <linux/init.h> +#include <asm/semaphore.h> #include "sysfs.h"
@@ -18,9 +19,12 @@ struct vfsmount *sysfs_mount;struct super_block * sysfs_sb =NULL ;struct kmem_cache *sysfs_dir_cachep; +static void sysfs_clear_inode (struct inode *inode); +static struct super_operations sysfs_ops = { .statfs = simple_statfs, .drop_inode = generic_delete_inode, + .clear_inode = sysfs_clear_inode, };static struct sysfs_dirent sysfs_root = {
@@ -31,6 +35,11 @@ static struct sysfs_dirent sysfs_root = { .s_iattr = NULL, }; +static void sysfs_clear_inode (struct inode *inode) +{ +kfree (inode->i_private); +} +static int sysfs_fill_super (struct super_block *sb,void *data,int silent) {struct inode *inode;
fs/sysfs/symlink.c +1 -0
@@ -7,6 +7,7 @@#include <linux/module.h> #include <linux/kobject.h> #include <linux/namei.h> +#include <asm/semaphore.h> #include "sysfs.h"
fs/sysfs/sysfs.h +16 -0
@@ -33,6 +33,22 @@ struct sysfs_symlink {struct kobject * target_kobj; }; +struct sysfs_buffer { +struct list_head associates; +size_t count; +loff_t pos; +char * page; +struct sysfs_ops * ops; +struct semaphore sem; +int orphaned; +int needs_read_fill; +int event; +}; + +struct sysfs_buffer_collection { +struct list_head associates; +}; +static inline struct kobject *to_kobj (struct dentry * dentry) {struct sysfs_dirent * sd = dentry->d_fsdata;
Signature · 1 line
1.4.4.4
PATCH 18/28 sysfs: suppress lockdep warnings
From: Frederik Deweerdt <[email protected]>
Lockdep issues the following warning:
[ 9.064000] =============================================
[ 9.064000] [ INFO: possible recursive locking detected ]
[ 9.064000] 2.6.20-rc3-mm1 #3
[ 9.064000] ---------------------------------------------
[ 9.064000] init/1 is trying to acquire lock:
[ 9.064000] (&sysfs_inode_imutex_key){--..}, at: [<c03e6afc>] mutex_lock+0x1c/0x1f
[ 9.064000]
[ 9.064000] but task is already holding lock:
[ 9.064000] (&sysfs_inode_imutex_key){--..}, at: [<c03e6afc>] mutex_lock+0x1c/0x1f
[ 9.065000]
[ 9.065000] other info that might help us debug this:
[ 9.065000] 2 locks held by init/1:
[ 9.065000] #0: (tty_mutex){--..}, at: [<c03e6afc>] mutex_lock+0x1c/0x1f
[ 9.065000] #1: (&sysfs_inode_imutex_key){--..}, at: [<c03e6afc>] mutex_lock+0x1c/0x1f
[ 9.065000]
[ 9.065000] stack backtrace:
[ 9.065000] [<c010390d>] show_trace_log_lvl+0x1a/0x30
[ 9.066000] [<c0103935>] show_trace+0x12/0x14
[ 9.066000] [<c0103a2f>] dump_stack+0x16/0x18
[ 9.066000] [<c0138cb8>] print_deadlock_bug+0xb9/0xc3
[ 9.066000] [<c0138d17>] check_deadlock+0x55/0x5a
[ 9.066000] [<c013a953>] __lock_acquire+0x371/0xbf0
[ 9.066000] [<c013b7a9>] lock_acquire+0x69/0x83
[ 9.066000] [<c03e6b7e>] __mutex_lock_slowpath+0x75/0x2d1
[ 9.066000] [<c03e6afc>] mutex_lock+0x1c/0x1f
[ 9.066000] [<c01b249c>] sysfs_drop_dentry+0xb1/0x133
[ 9.066000] [<c01b25d1>] sysfs_hash_and_remove+0xb3/0x142
[ 9.066000] [<c01b30ed>] sysfs_remove_file+0xd/0x10
[ 9.067000] [<c02849e0>] device_remove_file+0x23/0x2e
[ 9.067000] [<c02850b2>] device_del+0x188/0x1e6
[ 9.067000] [<c028511b>] device_unregister+0xb/0x15
[ 9.067000] [<c0285318>] device_destroy+0x9c/0xa9
[ 9.067000] [<c0261431>] vcs_remove_sysfs+0x1c/0x3b
[ 9.067000] [<c0267a08>] con_close+0x5e/0x6b
[ 9.067000] [<c02598f2>] release_dev+0x4c4/0x6e5
[ 9.067000] [<c0259faa>] tty_release+0x12/0x1c
[ 9.067000] [<c0174872>] __fput+0x177/0x1a0
[ 9.067000] [<c01746f5>] fput+0x3b/0x41
[ 9.068000] [<c0172ee1>] filp_close+0x36/0x65
[ 9.068000] [<c0172f73>] sys_close+0x63/0xa4
[ 9.068000] [<c0102a96>] sysenter_past_esp+0x5f/0x99
[ 9.068000] =======================This is due to sysfs_hash_and_remove() holding dir->d_inode->i_mutex before calling sysfs_drop_dentry() which calls orphan_all_buffers() which in turn takes node->i_mutex.
--- fs/sysfs/inode.c | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-)
fs/sysfs/inode.c +2 -2
@@ -215,7 +215,7 @@ static inline void orphan_all_buffers(struct inode *node)struct sysfs_buffer_collection *set = node->i_private;struct sysfs_buffer *buf; -mutex_lock (&node->i_mutex); +mutex_lock_nested (&node->i_mutex,I_MUTEX_CHILD );if (node->i_private) {list_for_each_entry (buf, &set->associates, associates) {down (&buf->sem);
@@ -272,7 +272,7 @@ int sysfs_hash_and_remove(struct dentry * dir, const char * name)return -ENOENT ; parent_sd = dir->d_fsdata; -mutex_lock (&dir->d_inode->i_mutex); +mutex_lock_nested (&dir->d_inode->i_mutex,I_MUTEX_PARENT );list_for_each_entry (sd, &parent_sd->s_children, s_sibling) {if (!sd->s_element)continue ;
Signature · 1 line
1.4.4.4
PATCH 19/28 sysfs: kobject_put cleanup
From: Mariusz Kozlowski <[email protected]>
This patch removes redundant argument checks for kobject_put().
--- fs/sysfs/bin.c | 5 ++--- fs/sysfs/file.c | 5 ++--- 2 files changed, 4 insertions(+), 6 deletions(-)
fs/sysfs/bin.c +2 -3
@@ -147,7 +147,7 @@ static int open(struct inode * inode, struct file * file) Error:module_put (attr->attr.owner); Done: -if (error && kobj) +if (error)kobject_put (kobj);return error; }
@@ -158,8 +158,7 @@ static int release(struct inode * inode, struct file * file)struct bin_attribute * attr =to_bin_attr (file->f_path.dentry);u8 * buffer = file->private_data; -if (kobj) -kobject_put (kobj); +kobject_put (kobj);module_put (attr->attr.owner);kfree (buffer);return 0 ;
fs/sysfs/file.c +2 -3
@@ -361,7 +361,7 @@ static int sysfs_open_file(struct inode *inode, struct file *file) error = -EACCES ;module_put (attr->owner); Done: -if (error && kobj) +if (error)kobject_put (kobj);return error; }
@@ -375,8 +375,7 @@ static int sysfs_release(struct inode * inode, struct file * filp)if (buffer)remove_from_collection (buffer, inode); -if (kobj) -kobject_put (kobj); +kobject_put (kobj);/* After this point, attr should not be accessed. */ module_put (owner);
Signature · 1 line
1.4.4.4
PATCH 20/28 kobject: kobject_put cleanup
From: Mariusz Kozlowski <[email protected]>
This patch removes redundant argument checks for kobject_put().
--- lib/kobject.c | 6 ++---- 1 files changed, 2 insertions(+), 4 deletions(-)
lib/kobject.c +2 -4
@@ -195,8 +195,7 @@ int kobject_add(struct kobject * kobj)if (error) {/* unlink does the kobject_put() for us */ unlink (kobj); -if (parent) -kobject_put (parent); +kobject_put (parent);/* be noisy on error issues */ if (error == -EEXIST )
@@ -420,8 +419,7 @@ void kobject_cleanup(struct kobject * kobj) t->release (kobj);if (s)kset_put (s); -if (parent) -kobject_put (parent); +kobject_put (parent); }static void kobject_release (struct kref *kref)
Signature · 1 line
1.4.4.4
PATCH 21/28 sysfs: error handling in sysfs, fill_read_buffer()
From: Oliver Neukum <[email protected]>
if a driver returns an error in fill_read_buffer(), the buffer will be marked as filled. Subsequent reads will return eof. But there is no data because of an error, not because it has been read. Not marking the buffer filled is the obvious fix.
--- fs/sysfs/file.c | 10 ++++++---- 1 files changed, 6 insertions(+), 4 deletions(-)
fs/sysfs/file.c +6 -4
@@ -83,7 +83,8 @@ remove_from_collection(struct sysfs_buffer *buffer, struct inode *node)* Allocate @buffer->page, if it hasn't been already, then call the * kobject's show() method to fill the buffer with this attribute's * data. -* This is called only once, on the file's first read. +* This is called only once, on the file's first read unless an error +* is returned. */ static int fill_read_buffer (struct dentry * dentry,struct sysfs_buffer * buffer) {
@@ -101,12 +102,13 @@ static int fill_read_buffer(struct dentry * dentry, struct sysfs_buffer * buffer buffer->event =atomic_read (&sd->s_event); count = ops->show (kobj,attr,buffer->page); - buffer->needs_read_fill =0 ;BUG_ON (count > (ssize_t )PAGE_SIZE ); -if (count >=0 ) +if (count >=0 ) { + buffer->needs_read_fill =0 ; buffer->count = count; -else + }else { ret = count; + }return ret; }
Signature · 1 line
1.4.4.4
PATCH 22/28 HOWTO: Add a reference to Harbison and Steele
From: Robert P. J. Day <[email protected]>
Add a reference to Harbison and Steele's C book.
--- Documentation/HOWTO | 1 + 1 files changed, 1 insertions(+), 0 deletions(-)
Documentation/HOWTO +1 -0
@@ -30,6 +30,7 @@ are not a good substitute for a solid C education and/or years of experience, the following books are good for, if anything, reference: - "The C Programming Language" by Kernighan and Ritchie [Prentice Hall] - "Practical C Programming" by Steve Oualline [O'Reilly] + - "C: A Reference Manual" by Harbison and Steele [Prentice Hall] The kernel is written using GNU C and the GNU toolchain. While it adheres to the ISO C89 standard, it uses a number of extensions that are
Signature · 1 line
1.4.4.4
PATCH 23/28 SYSFS: Fix missing include of list.h in sysfs.h
From: Frank Haverkamp <[email protected]>
Sysfs.h uses definitions (e.g. struct list_head s_sibling) from list.h but does not include it.
--- include/linux/sysfs.h | 1 + 1 files changed, 1 insertions(+), 0 deletions(-)
include/linux/sysfs.h +1 -0
@@ -11,6 +11,7 @@#define _SYSFS_H_#include <linux/compiler.h> +#include <linux/list.h> #include <asm/atomic.h> struct kobject ;
Signature · 1 line
1.4.4.4
PATCH 24/28 Driver core: add uevent vars for devices of a class
From: Kay Sievers <[email protected]>
Devices converted from class_device to device should have the same uevent keys as the original class_device had. We search up the parents until we find the first bus device and add the (already deprecated) PHYDEV* values.
--- drivers/base/core.c | 46 ++++++++++++++++++++++++++++++++++------------ 1 files changed, 34 insertions(+), 12 deletions(-)
drivers/base/core.c +34 -12
@@ -154,25 +154,47 @@ static int dev_uevent(struct kset *kset, struct kobject *kobj, char **envp, "MINOR=%u", MINOR(dev->devt)); } -#ifdef CONFIG_SYSFS_DEPRECATED -/* add bus name (same as SUBSYSTEM, deprecated) */ -if (dev->bus) -add_uevent_var (envp, num_envp, &i, - buffer, buffer_size, &length, -"PHYSDEVBUS=%s" , dev->bus->name); -#endif - -/* add driver name (PHYSDEV* values are deprecated)*/ -if (dev->driver) { +if (dev->driver)add_uevent_var (envp, num_envp, &i, buffer, buffer_size, &length,"DRIVER=%s" , dev->driver->name); +#ifdef CONFIG_SYSFS_DEPRECATED +if (dev->class) { +struct device *parent = dev->parent; + +/* find first bus device in parent chain */ +while (parent && !parent->bus) + parent = parent->parent; +if (parent && parent->bus) { +const char *path; + + path =kobject_get_path (&parent->kobj,GFP_KERNEL ); +add_uevent_var (envp, num_envp, &i, + buffer, buffer_size, &length, +"PHYSDEVPATH=%s" , path); +kfree (path); + +add_uevent_var (envp, num_envp, &i, + buffer, buffer_size, &length, +"PHYSDEVBUS=%s" , parent->bus->name); + +if (parent->driver) +add_uevent_var (envp, num_envp, &i, + buffer, buffer_size, &length, +"PHYSDEVDRIVER=%s" , parent->driver->name); + } + }else if (dev->bus) {add_uevent_var (envp, num_envp, &i, buffer, buffer_size, &length, -"PHYSDEVDRIVER=%s" , dev->driver->name); -#endif +"PHYSDEVBUS=%s" , dev->bus->name); + +if (dev->driver) +add_uevent_var (envp, num_envp, &i, + buffer, buffer_size, &length, +"PHYSDEVDRIVER=%s" , dev->driver->name); } +#endif /* terminate, set to next free slot, shrink available space */ envp[i] =NULL ;
Signature · 1 line
1.4.4.4
PATCH 25/28 Driver core: add device_type to struct device
From: Kay Sievers <[email protected]>
This allows us to add type specific attributes, uevent vars and release funtions.
A subsystem can carry different types of devices like the "block" subsys has disks and partitions. Both types create a different set of attributes, but belong to the same subsystem.
This corresponds to the low level objects:
kobject -> device (object/device data) kobj_type -> device_type (type of object/device we are embedded in) kset -> class/bus (list of objects/devices of a subsystem)
--- drivers/base/core.c | 57 ++++++++++++++++++++++++++++------------- drivers/usb/input/hid-lgff.c | 4 +- include/linux/device.h | 8 ++++++ 3 files changed, 49 insertions(+), 20 deletions(-)
drivers/base/core.c +39 -18
@@ -95,6 +95,8 @@ static void device_release(struct kobject * kobj)if (dev->release) dev->release (dev); +else if (dev->type && dev->type->release) + dev->type->release (dev);else if (dev->class && dev->class->dev_release) dev->class->dev_release (dev);else {
@@ -206,19 +208,25 @@ static int dev_uevent(struct kset *kset, struct kobject *kobj, char **envp,if (dev->bus && dev->bus->uevent) {/* have the bus specific function add its stuff */ retval = dev->bus->uevent (dev, envp, num_envp, buffer, buffer_size); -if (retval) { -pr_debug ("%s - uevent() returned %d\n" , +if (retval) +pr_debug ("%s: bus uevent() returned %d\n" , __FUNCTION__, retval); - } }if (dev->class && dev->class->dev_uevent) {/* have the class specific function add its stuff */ retval = dev->class->dev_uevent (dev, envp, num_envp, buffer, buffer_size); -if (retval) { -pr_debug ("%s - dev_uevent() returned %d\n" , - __FUNCTION__, retval); - } +if (retval) +pr_debug ("%s: class uevent() returned %d\n" , + __FUNCTION__, retval); + } + +if (dev->type && dev->type->uevent) { +/* have the device type specific fuction add its stuff */ + retval = dev->type->uevent (dev, envp, num_envp, buffer, buffer_size); +if (retval) +pr_debug ("%s: dev_type uevent() returned %d\n" , + __FUNCTION__, retval); }return retval;
@@ -269,37 +277,50 @@ static void device_remove_groups(struct device *dev)static int device_add_attrs (struct device *dev) {struct class *class = dev->class; +struct device_type *type = dev->type;int error =0 ;int i; -if (!class) -return 0 ; - -if (class->dev_attrs) { +if (class && class->dev_attrs) {for (i =0 ;attr_name (class->dev_attrs[i]); i++) { error =device_create_file (dev, &class->dev_attrs[i]);if (error)break ; } +if (error) +while (--i >=0 ) +device_remove_file (dev, &class->dev_attrs[i]); } -if (error) -while (--i >=0 ) -device_remove_file (dev, &class->dev_attrs[i]); + +if (type && type->attrs) { +for (i =0 ;attr_name (type->attrs[i]); i++) { + error =device_create_file (dev, &type->attrs[i]); +if (error) +break ; + } +if (error) +while (--i >=0 ) +device_remove_file (dev, &type->attrs[i]); + } +return error; }static void device_remove_attrs (struct device *dev) {struct class *class = dev->class; +struct device_type *type = dev->type;int i; -if (!class) -return ; - -if (class->dev_attrs) { +if (class && class->dev_attrs) {for (i =0 ;attr_name (class->dev_attrs[i]); i++)device_remove_file (dev, &class->dev_attrs[i]); } + +if (type && type->attrs) { +for (i =0 ;attr_name (type->attrs[i]); i++) +device_remove_file (dev, &type->attrs[i]); + } }
drivers/usb/input/hid-lgff.c +2 -2
@@ -32,7 +32,7 @@#include <linux/hid.h> #include "usbhid.h" -struct device_type { +struct dev_type {u16 idVendor;u16 idProduct;const signed short *ff;
@@ -48,7 +48,7 @@ static const signed short ff_joystick[] = {-1 }; -static const struct device_type devices[] = { +static const struct dev_type devices[] = { {0x046d ,0xc211 , ff_rumble }, {0x046d ,0xc219 , ff_rumble }, {0x046d ,0xc283 , ff_joystick },
include/linux/device.h +8 -0
@@ -328,6 +328,13 @@ extern struct class_device *class_device_create(struct class *cls, __attribute__((format(printf,5,6)));extern void class_device_destroy (struct class *cls,dev_t devt); +struct device_type { +struct device_attribute *attrs; +int (*uevent)(struct device *dev,char **envp,int num_envp, +char *buffer,int buffer_size); +void (*release)(struct device *dev); +}; +/* interface for exporting device attributes */ struct device_attribute {struct attribute attr;
@@ -356,6 +363,7 @@ struct device {struct kobject kobj;char bus_id[BUS_ID_SIZE ];/* position on parent bus */ +struct device_type *type; unsigned is_registered:1;struct device_attribute uevent_attr;struct device_attribute *devt_attr;
Signature · 1 line
1.4.4.4
PATCH 26/28 Driver core: allow to delay the uevent at device creation time
From: Kay Sievers <[email protected]>
For the block subsystem, we want to delay all uevents until the disk has been scanned and allpartitons are already created before the first event is sent out.
--- drivers/base/core.c | 3 ++- include/linux/device.h | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-)
drivers/base/core.c +2 -1
@@ -589,7 +589,8 @@ int device_add(struct device *dev) goto PMError;if ((error =bus_add_device (dev))) goto BusError; -kobject_uevent (&dev->kobj,KOBJ_ADD ); +if (!dev->uevent_suppress) +kobject_uevent (&dev->kobj,KOBJ_ADD );if ((error =bus_attach_device (dev))) goto AttachError;if (parent)
include/linux/device.h +2 -1
@@ -399,9 +399,10 @@ struct device {/* class_device migration path */ struct list_head node; -struct class *class;/* optional*/ +struct class *class;dev_t devt;/* dev_t, creates the sysfs "dev" */ struct attribute_group **groups;/* optional groups */ +int uevent_suppress;void (*release)(struct device * dev); };
Signature · 1 line
1.4.4.4
PATCH 27/28 Driver Core: Increase the default timeout value of the firmware subsystem
From: Dave Jones <[email protected]>
https://bugzilla.redhat.com/bugzilla/show_bug.cgi?id=174589
The ipw driver sometimes takes a long time to load its firmware. Whilst the ipw driver should be using the async interface of the firmware loader to make this a non-issue, this is a minimal fix.
--- drivers/base/firmware_class.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
drivers/base/firmware_class.c +1 -1
@@ -35,7 +35,7 @@ enum { FW_STATUS_READY_NOHOTPLUG, }; -static int loading_timeout =10 ;/* In seconds */ +static int loading_timeout =60 ;/* In seconds */ /* fw_lock could be moved to 'struct firmware_priv' but since it is just * guarding for corner cases a global lock should be OK */
Signature · 1 line
1.4.4.4
PATCH 28/28 sysfs: Shadow directory support
From: Eric W. Biederman <[email protected]>
The problem. When implementing a network namespace I need to be able to have multiple network devices with the same name. Currently this is a problem for /sys/class/net/*.
What I want is a separate /sys/class/net directory in sysfs for each network namespace, and I want to name each of them /sys/class/net.
I looked and the VFS actually allows that. All that is needed is for /sys/class/net to implement a follow link method to redirect lookups to the real directory you want.
Implementing a follow link method that is sensitive to the current network namespace turns out to be 3 lines of code so it looks like a clean approach. Modifying sysfs so it doesn't get in my was is a bit trickier.
I am calling the concept of multiple directories all at the same path in the filesystem shadow directories. With the directory entry really at that location the shadow master.
The following patch modifies sysfs so it can handle a directory structure slightly different from the kobject tree so I can implement the shadow directories for handling /sys/class/net/.
--- fs/sysfs/dir.c | 207 +++++++++++++++++++++++++++++++++++++++-------- fs/sysfs/group.c | 1 + fs/sysfs/inode.c | 10 +++ fs/sysfs/mount.c | 2 +- fs/sysfs/sysfs.h | 5 + include/linux/kobject.h | 4 + include/linux/sysfs.h | 23 +++++- lib/kobject.c | 42 +++++++++- 8 files changed, 249 insertions(+), 45 deletions(-)
fs/sysfs/dir.c +172 -35
@@ -33,8 +33,7 @@ static struct dentry_operations sysfs_dentry_ops = {/* * Allocates a new sysfs_dirent and links it to the parent sysfs_dirent */ -static struct sysfs_dirent *sysfs_new_dirent (struct sysfs_dirent * parent_sd, -void * element) +static struct sysfs_dirent *__sysfs_new_dirent (void * element) {struct sysfs_dirent * sd;
@@ -46,12 +45,28 @@ static struct sysfs_dirent * sysfs_new_dirent(struct sysfs_dirent * parent_sd,atomic_set (&sd->s_count,1 );atomic_set (&sd->s_event,1 );INIT_LIST_HEAD (&sd->s_children); -list_add (&sd->s_sibling, &parent_sd->s_children); +INIT_LIST_HEAD (&sd->s_sibling); sd->s_element = element;return sd; } +static void __sysfs_list_dirent (struct sysfs_dirent *parent_sd, +struct sysfs_dirent *sd) +{ +if (sd) +list_add (&sd->s_sibling, &parent_sd->s_children); +} + +static struct sysfs_dirent *sysfs_new_dirent (struct sysfs_dirent *parent_sd, +void * element) +{ +struct sysfs_dirent *sd; + sd =__sysfs_new_dirent (element); +__sysfs_list_dirent (parent_sd, sd); +return sd; +} +/* * * Return -EEXIST if there is already a sysfs element with the same name for
@@ -78,14 +93,14 @@ int sysfs_dirent_exist(struct sysfs_dirent *parent_sd, } -int sysfs_make_dirent (struct sysfs_dirent * parent_sd,struct dentry * dentry, -void * element,umode_t mode,int type) +static struct sysfs_dirent * +__sysfs_make_dirent (struct dentry *dentry,void *element,mode_t mode,int type) {struct sysfs_dirent * sd; - sd =sysfs_new_dirent (parent_sd, element); + sd =__sysfs_new_dirent (element);if (!sd) -return -ENOMEM ; + goto out; sd->s_mode = mode; sd->s_type = type;
@@ -95,7 +110,19 @@ int sysfs_make_dirent(struct sysfs_dirent * parent_sd, struct dentry * dentry, dentry->d_op = &sysfs_dentry_ops; } -return 0 ; +out: +return sd; +} + +int sysfs_make_dirent (struct sysfs_dirent * parent_sd,struct dentry * dentry, +void * element,umode_t mode,int type) +{ +struct sysfs_dirent *sd; + + sd =__sysfs_make_dirent (dentry, element, mode, type); +__sysfs_list_dirent (parent_sd, sd); + +return sd ?0 : -ENOMEM ; }static int init_dir (struct inode * inode)
@@ -166,11 +193,11 @@ int sysfs_create_subdir(struct kobject * k, const char * n, struct dentry ** d)/** * sysfs_create_dir - create a directory for an object. -* @parent: parent parent object. * @kobj: object we're creating directory for. +* @shadow_parent: parent parent object. */ -int sysfs_create_dir (struct kobject * kobj) +int sysfs_create_dir (struct kobject * kobj,struct dentry *shadow_parent) {struct dentry * dentry =NULL ;struct dentry * parent;
@@ -178,7 +205,9 @@ int sysfs_create_dir(struct kobject * kobj)BUG_ON (!kobj); -if (kobj->parent) +if (shadow_parent) + parent = shadow_parent; +else if (kobj->parent) parent = kobj->parent->dentry;else if (sysfs_mount && sysfs_mount->mnt_sb) parent = sysfs_mount->mnt_sb->s_root;
@@ -299,21 +328,12 @@ void sysfs_remove_subdir(struct dentry * d) } -/** -* sysfs_remove_dir - remove an object's directory. -* @kobj: object. -* -* The only thing special about this is that we remove any files in -* the directory before we remove the directory, and we've inlined -* what used to be sysfs_rmdir() below, instead of calling separately. -*/ - -void sysfs_remove_dir (struct kobject * kobj) +static void __sysfs_remove_dir (struct dentry *dentry) { -struct dentry * dentry =dget (kobj->dentry);struct sysfs_dirent * parent_sd;struct sysfs_dirent * sd, * tmp; +dget (dentry);if (!dentry)return ;
@@ -334,32 +354,60 @@ void sysfs_remove_dir(struct kobject * kobj)* Drop reference from dget() on entrance. */ dput (dentry); +} + +/** +* sysfs_remove_dir - remove an object's directory. +* @kobj: object. +* +* The only thing special about this is that we remove any files in +* the directory before we remove the directory, and we've inlined +* what used to be sysfs_rmdir() below, instead of calling separately. +*/ + +void sysfs_remove_dir (struct kobject * kobj) +{ +__sysfs_remove_dir (kobj->dentry); kobj->dentry =NULL ; } -int sysfs_rename_dir (struct kobject * kobj,const char *new_name) +int sysfs_rename_dir (struct kobject * kobj,struct dentry *new_parent, +const char *new_name) {int error =0 ; -struct dentry * new_dentry, * parent; +struct dentry * new_dentry; -if (!strcmp (kobject_name (kobj), new_name)) -return -EINVAL ; - -if (!kobj->parent) -return -EINVAL ; +if (!new_parent) +return -EFAULT ;down_write (&sysfs_rename_sem); - parent = kobj->parent->dentry; +mutex_lock (&new_parent->d_inode->i_mutex); -mutex_lock (&parent->d_inode->i_mutex); - - new_dentry =lookup_one_len (new_name, parent,strlen (new_name)); + new_dentry =lookup_one_len (new_name, new_parent,strlen (new_name));if (!IS_ERR (new_dentry)) { -if (!new_dentry->d_inode) { +/* By allowing two different directories with the +* same d_parent we allow this routine to move +* between different shadows of the same directory +*/ +if (kobj->dentry->d_parent->d_inode != new_parent->d_inode) +return -EINVAL ; +else if (new_dentry->d_parent->d_inode != new_parent->d_inode) + error = -EINVAL ; +else if (new_dentry == kobj->dentry) + error = -EINVAL ; +else if (!new_dentry->d_inode) { error =kobject_set_name (kobj,"%s" , new_name);if (!error) { +struct sysfs_dirent *sd, *parent_sd; +d_add (new_dentry,NULL );d_move (kobj->dentry, new_dentry); + + sd = kobj->dentry->d_fsdata; + parent_sd = new_parent->d_fsdata; + +list_del_init (&sd->s_sibling); +list_add (&sd->s_sibling, &parent_sd->s_children); }else d_drop (new_dentry);
@@ -367,7 +415,7 @@ int sysfs_rename_dir(struct kobject * kobj, const char *new_name) error = -EEXIST ;dput (new_dentry); } -mutex_unlock (&parent->d_inode->i_mutex); +mutex_unlock (&new_parent->d_inode->i_mutex);up_write (&sysfs_rename_sem);return error;
@@ -546,6 +594,95 @@ static loff_t sysfs_dir_lseek(struct file * file, loff_t offset, int origin)return offset; } + +/** +* sysfs_make_shadowed_dir - Setup so a directory can be shadowed +* @kobj: object we're creating shadow of. +*/ + +int sysfs_make_shadowed_dir (struct kobject *kobj, +void * (*follow_link)(struct dentry *,struct nameidata *)) +{ +struct inode *inode; +struct inode_operations *i_op; + + inode = kobj->dentry->d_inode; +if (inode->i_op != &sysfs_dir_inode_operations) +return -EINVAL ; + + i_op =kmalloc (sizeof (*i_op),GFP_KERNEL ); +if (!i_op) +return -ENOMEM ; + +memcpy (i_op, &sysfs_dir_inode_operations,sizeof (*i_op)); + i_op->follow_link = follow_link; + +/* Locking of inode->i_op? +* Since setting i_op is a single word write and they +* are atomic we should be ok here. +*/ + inode->i_op = i_op; +return 0 ; +} + +/** +* sysfs_create_shadow_dir - create a shadow directory for an object. +* @kobj: object we're creating directory for. +* +* sysfs_make_shadowed_dir must already have been called on this +* directory. +*/ + +struct dentry *sysfs_create_shadow_dir (struct kobject *kobj) +{ +struct sysfs_dirent *sd; +struct dentry *parent, *dir, *shadow; +struct inode *inode; + + dir = kobj->dentry; + inode = dir->d_inode; + parent = dir->d_parent; + shadow =ERR_PTR (-EINVAL ); +if (!sysfs_is_shadowed_inode (inode)) + goto out; + + shadow =d_alloc (parent, &dir->d_name); +if (!shadow) + goto nomem; + + sd =__sysfs_make_dirent (shadow, kobj, inode->i_mode,SYSFS_DIR ); +if (!sd) + goto nomem; + +d_instantiate (shadow,igrab (inode)); +inc_nlink (inode); +inc_nlink (parent->d_inode); + shadow->d_op = &sysfs_dentry_ops; + +dget (shadow);/* Extra count - pin the dentry in core */ + +out: +return shadow; +nomem: +dput (shadow); + shadow =ERR_PTR (-ENOMEM ); + goto out; +} + +/** +* sysfs_remove_shadow_dir - remove an object's directory. +* @shadow: dentry of shadow directory +* +* The only thing special about this is that we remove any files in +* the directory before we remove the directory, and we've inlined +* what used to be sysfs_rmdir() below, instead of calling separately. +*/ + +void sysfs_remove_shadow_dir (struct dentry *shadow) +{ +__sysfs_remove_dir (shadow); +} +const struct file_operations sysfs_dir_operations = { .open = sysfs_dir_open, .release = sysfs_dir_close,
fs/sysfs/group.c +1 -0
@@ -13,6 +13,7 @@#include <linux/dcache.h> #include <linux/namei.h> #include <linux/err.h> +#include <linux/fs.h> #include <asm/semaphore.h> #include "sysfs.h"
fs/sysfs/inode.c +10 -0
@@ -33,6 +33,16 @@ static struct inode_operations sysfs_inode_operations ={ .setattr = sysfs_setattr, }; +void sysfs_delete_inode (struct inode *inode) +{ +/* Free the shadowed directory inode operations */ +if (sysfs_is_shadowed_inode (inode)) { +kfree (inode->i_op); + inode->i_op =NULL ; + } +return generic_delete_inode (inode); +} +int sysfs_setattr (struct dentry * dentry,struct iattr * iattr) {struct inode * inode = dentry->d_inode;
fs/sysfs/mount.c +1 -1
@@ -23,7 +23,7 @@ static void sysfs_clear_inode(struct inode *inode);static struct super_operations sysfs_ops = { .statfs = simple_statfs, - .drop_inode = generic_delete_inode, + .drop_inode = sysfs_delete_inode, .clear_inode = sysfs_clear_inode, };
fs/sysfs/sysfs.h +5 -0
@@ -2,6 +2,7 @@extern struct vfsmount * sysfs_mount;extern struct kmem_cache *sysfs_dir_cachep; +extern void sysfs_delete_inode (struct inode *inode);extern struct inode *sysfs_new_inode (mode_t mode,struct sysfs_dirent *);extern int sysfs_create (struct dentry *,int mode,int (*init)(struct inode *));
@@ -112,3 +113,7 @@ static inline void sysfs_put(struct sysfs_dirent * sd)release_sysfs_dirent (sd); } +static inline int sysfs_is_shadowed_inode (struct inode *inode) +{ +return S_ISDIR (inode->i_mode) && inode->i_op->follow_link; +}
include/linux/kobject.h +4 -0
@@ -74,9 +74,13 @@ extern void kobject_init(struct kobject *);extern void kobject_cleanup (struct kobject *);extern int __must_check kobject_add (struct kobject *); +extern int __must_check kobject_shadow_add (struct kobject *,struct dentry *);extern void kobject_del (struct kobject *);extern int __must_check kobject_rename (struct kobject *,const char *new_name); +extern int __must_check kobject_shadow_rename (struct kobject *kobj, +struct dentry *new_parent, +const char *new_name);extern int __must_check kobject_move (struct kobject *,struct kobject *);extern int __must_check kobject_register (struct kobject *);
include/linux/sysfs.h +19 -4
@@ -16,6 +16,7 @@struct kobject ;struct module ; +struct nameidata ;struct attribute {const char * name;
@@ -89,13 +90,13 @@ struct sysfs_dirent {#ifdef CONFIG_SYSFS extern int __must_check -sysfs_create_dir (struct kobject *); +sysfs_create_dir (struct kobject *,struct dentry *);extern void sysfs_remove_dir (struct kobject *);extern int __must_check -sysfs_rename_dir (struct kobject *,const char *new_name); +sysfs_rename_dir (struct kobject *,struct dentry *,const char *new_name);extern int __must_check sysfs_move_dir (struct kobject *,struct kobject *);
@@ -127,11 +128,17 @@ int __must_check sysfs_create_group(struct kobject *,void sysfs_remove_group (struct kobject *,const struct attribute_group *);void sysfs_notify (struct kobject * k,char *dir,char *attr); + +extern int sysfs_make_shadowed_dir (struct kobject *kobj, +void * (*follow_link)(struct dentry *,struct nameidata *)); +extern struct dentry *sysfs_create_shadow_dir (struct kobject *kobj); +extern void sysfs_remove_shadow_dir (struct dentry *dir); +extern int __must_check sysfs_init (void );#else /* CONFIG_SYSFS */ -static inline int sysfs_create_dir (struct kobject * k) +static inline int sysfs_create_dir (struct kobject * k,struct dentry *shadow) {return 0 ; }
@@ -141,7 +148,9 @@ static inline void sysfs_remove_dir(struct kobject * k) ; } -static inline int sysfs_rename_dir (struct kobject * k,const char *new_name) +static inline int sysfs_rename_dir (struct kobject * k, +struct dentry *new_parent, +const char *new_name) {return 0 ; }
@@ -205,6 +214,12 @@ static inline void sysfs_notify(struct kobject * k, char *dir, char *attr) { } +static inline int sysfs_make_shadowed_dir (struct kobject *kobj, +void * (*follow_link)(struct dentry *,struct nameidata *)) +{ +return 0 ; +} +static inline int __must_check sysfs_init (void ) {return 0 ;
lib/kobject.c +37 -5
77 lines not on this page · raw message
Signature · 1 line
1.4.4.4
Dmitry Torokhov
maintainerRe: [PATCH 10/28] SERIO: add the sysfs driver name to all modules
In reply to Greg KHHi Greg,
Quoted 5 lines · Greg KH
From: Greg Kroah-Hartman <[email protected]>
This adds the module name to all SERIO drivers, if they are built into the kernel or not. It will show up in
/sys/modules/MODULE_NAME/drivers/
What is this needed for?
Signature · 1 line
Dmitry
Re: [PATCH 10/28] SERIO: add the sysfs driver name to all modules
Quoted 10 lines · Dmitry Torokhov
Hi Greg,
Quoted 5 lines · Greg KH
From: Greg Kroah-Hartman <[email protected]>
This adds the module name to all SERIO drivers, if they are built into the kernel or not. It will show up in
/sys/modules/MODULE_NAME/drivers/What is this needed for?
All modules show up today in /sys/module/ no matter if they are built into the kernel or not.
But, if they are built as a module, the /sys/module/drivers/ link was present. This is not consistant, as we always want to see that link, no matter if the driver is built in or not. So with this change, we now always see the links.
I also fixed the PCI and USB drivers to do this as well.
Hope this helps explain it.
thanks,
greg k-h