Skip to contentSkip to conversation

Driver Core patches for 2.6.10-rc1

PATCH New Greg KH 1 participant 8 messages Oct 22, 2004 – Oct 23, 2004

Subsystems (5)
VFS PCI Library code Driver core +1 more subsystems
lore
Share & tools
lore

Greg KH

author
#0 lore raw

PATCH 1/1 Driver Core patches for 2.6.10-rc1

Hi,

Here are a few minot driver core changes for 2.6.10-rc1 that were laying around and didn't make it in the last big batch of merges. Most of these have been in the -mm tree for a while now.

No, they don't include the backing store sysfs patches, I'll get to those next week. I'll be in the same building as Maneesh, so I know he'll be hounding me about them... :)

Oh, and these patches will cause the wait_for_sysfs program in udev to start spiting out a lot more warnings. It's not a bug in the kernel, it's a userspace issue. I'll get that fixed up in the next udev release.

Please pull from:

	bk://kernel.bkbits.net/gregkh/linux/driver-2.6

thanks,

greg k-h

p.s. I'll send these as patches in response to this email to lkml for those who want to see them.

 drivers/base/bus.c                     |    4 +--
 drivers/base/class.c                   |    4 +--
 drivers/base/core.c                    |    2 -
 drivers/base/cpu.c                     |    2 +
 drivers/firmware/efivars.c             |    2 -
 drivers/pci/hotplug/pci_hotplug_core.c |    2 -
 fs/char_dev.c                          |    4 +--
 fs/sysfs/dir.c                         |    2 -
 include/linux/kobject_uevent.h         |    1 
 kernel/cpu.c                           |   35 ----------------------------
 kernel/module.c                        |    2 -
 lib/Kconfig.debug                      |    7 +++++
 lib/Makefile                           |    7 ++++-
 lib/kobject.c                          |    4 ---
 lib/kobject_uevent.c                   |   40 ++++++++++++++++++++-------------
 15 files changed, 53 insertions(+), 65 deletions(-)

-----

Andrew Morton:
o kobject_uevent warning fix
o kobject_hotplug: permit no hotplug_ops

Anil Keshavamurthy:
o remove cpu_run_sbin_hotplug()

Greg Kroah-Hartman:
o hotplug: prevent skips in sequence number from happening
o kobject: add CONFIG_DEBUG_KOBJECT

Stephen Hemminger:
o avoid problems with kobject_set_name and name with %
o cdev: protect against buggy drivers

author
#1 lore raw

PATCH 1/1 Driver Core patches for 2.6.10-rc1

ChangeSet 1.2000.6.1, 2004/10/20 15:38:19-07:00, [email protected]

kobject: add CONFIG_DEBUG_KOBJECT

 lib/Kconfig.debug |    7 +++++++
 lib/Makefile      |    6 +++++-
 lib/kobject.c     |    4 +---
 3 files changed, 13 insertions(+), 4 deletions(-)
lib/Kconfig.debug +7 -0
diff -Nru a/lib/Kconfig.debug b/lib/Kconfig.debug
@@ -64,6 +64,13 @@
 	  If you say Y here, various routines which may sleep will become very
 	  noisy if they are called with a spinlock held.
 
+config DEBUG_KOBJECT
+	bool "kobject debugging"
+	depends on DEBUG_KERNEL
+	help
+	  If you say Y here, some extra kobject debugging messages will be sent
+	  to the syslog. 
+
 config DEBUG_HIGHMEM
 	bool "Highmem debugging"
 	depends on DEBUG_KERNEL && HIGHMEM && (X86 || PPC32 || MIPS || SPARC32)
lib/Makefile +5 -1
diff -Nru a/lib/Makefile b/lib/Makefile
@@ -2,11 +2,15 @@
 # Makefile for some libs needed in the kernel.
 #
 
-
 lib-y := errno.o ctype.o string.o vsprintf.o cmdline.o \
 	 bust_spinlocks.o rbtree.o radix-tree.o dump_stack.o \
 	 kobject.o kref.o idr.o div64.o parser.o int_sqrt.o \
 	 bitmap.o extable.o kobject_uevent.o
+
+ifeq ($(CONFIG_DEBUG_KOBJECT),y)
+CFLAGS_kobject.o += -DDEBUG
+CFLAGS_kobject_uevent.o += -DDEBUG
+endif
 
 lib-$(CONFIG_RWSEM_GENERIC_SPINLOCK) += rwsem-spinlock.o
 lib-$(CONFIG_RWSEM_XCHGADD_ALGORITHM) += rwsem.o
lib/kobject.c +1 -3
diff -Nru a/lib/kobject.c b/lib/kobject.c
@@ -10,8 +10,6 @@
  * about using the kobject interface.
  */
 
-#undef DEBUG
-
 #include <linux/kobject.h>
 #include <linux/string.h>
 #include <linux/module.h>
@@ -123,7 +121,7 @@
  */
 void kobject_init(struct kobject * kobj)
 {
- 	kref_init(&kobj->kref);
+	kref_init(&kobj->kref);
 	INIT_LIST_HEAD(&kobj->entry);
 	kobj->kset = kset_get(kobj->kset);
 }
author
#2 lore raw

ChangeSet 1.2018, 2004/10/22 13:55:29-07:00, [email protected]

[PATCH] cdev: protect against buggy drivers

Here is a better fix (thanks Greg) that allows long names for character device objects.

 fs/char_dev.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
fs/char_dev.c +2 -2
diff -Nru a/fs/char_dev.c b/fs/char_dev.c
@@ -207,8 +207,8 @@
 
 	cdev->owner = fops->owner;
 	cdev->ops = fops;
-	strcpy(cdev->kobj.name, name);
-	for (s = strchr(cdev->kobj.name, '/'); s; s = strchr(s, '/'))
+	kobject_set_name(&cdev->kobj, "%s", name);
+	for (s = strchr(kobject_name(&cdev->kobj),'/'); s; s = strchr(s, '/'))
 		*s = '!';
 		
 	err = cdev_add(cdev, MKDEV(cd->major, 0), 256);
author
#3 lore raw

ChangeSet 1.2019, 2004/10/22 14:01:16-07:00, [email protected]

[PATCH] avoid problems with kobject_set_name and name with %

kobject_set_name takes a printf style argument list. There are many callers that pass only one string, if this string contained a '%' character than bad things would happen. The fix is simple.

 drivers/base/bus.c                     |    4 ++--
 drivers/base/class.c                   |    4 ++--
 drivers/base/core.c                    |    2 +-
 drivers/firmware/efivars.c             |    2 +-
 drivers/pci/hotplug/pci_hotplug_core.c |    2 +-
 fs/sysfs/dir.c                         |    2 +-
 kernel/module.c                        |    2 +-
 7 files changed, 9 insertions(+), 9 deletions(-)
drivers/base/bus.c +2 -2
diff -Nru a/drivers/base/bus.c b/drivers/base/bus.c
@@ -515,7 +515,7 @@
 
 	if (bus) {
 		pr_debug("bus %s: add driver %s\n", bus->name, drv->name);
-		error = kobject_set_name(&drv->kobj, drv->name);
+		error = kobject_set_name(&drv->kobj, "%s", drv->name);
 		if (error) {
 			put_bus(bus);
 			return error;
@@ -666,7 +666,7 @@
 {
 	int retval;
 
-	retval = kobject_set_name(&bus->subsys.kset.kobj, bus->name);
+	retval = kobject_set_name(&bus->subsys.kset.kobj, "%s", bus->name);
 	if (retval)
 		goto out;
 
drivers/base/class.c +2 -2
diff -Nru a/drivers/base/class.c b/drivers/base/class.c
@@ -139,7 +139,7 @@
 
 	INIT_LIST_HEAD(&cls->children);
 	INIT_LIST_HEAD(&cls->interfaces);
-	error = kobject_set_name(&cls->subsys.kset.kobj, cls->name);
+	error = kobject_set_name(&cls->subsys.kset.kobj, "%s", cls->name);
 	if (error)
 		return error;
 
@@ -368,7 +368,7 @@
 		 class_dev->class_id);
 
 	/* first, register with generic layer. */
-	kobject_set_name(&class_dev->kobj, class_dev->class_id);
+	kobject_set_name(&class_dev->kobj, "%s", class_dev->class_id);
 	if (parent)
 		class_dev->kobj.parent = &parent->subsys.kset.kobj;
 
drivers/base/core.c +1 -1
diff -Nru a/drivers/base/core.c b/drivers/base/core.c
@@ -221,7 +221,7 @@
 	pr_debug("DEV: registering device: ID = '%s'\n", dev->bus_id);
 
 	/* first, register with generic layer. */
-	kobject_set_name(&dev->kobj, dev->bus_id);
+	kobject_set_name(&dev->kobj, "%s", dev->bus_id);
 	if (parent)
 		dev->kobj.parent = &parent->kobj;
 
drivers/firmware/efivars.c +1 -1
diff -Nru a/drivers/firmware/efivars.c b/drivers/firmware/efivars.c
@@ -640,7 +640,7 @@
 	*(short_name + strlen(short_name)) = '-';
 	efi_guid_unparse(vendor_guid, short_name + strlen(short_name));
 
-	kobject_set_name(&new_efivar->kobj, short_name);
+	kobject_set_name(&new_efivar->kobj, "%s", short_name);
 	kobj_set_kset_s(new_efivar, vars_subsys);
 	kobject_register(&new_efivar->kobj);
 
drivers/pci/hotplug/pci_hotplug_core.c +1 -1
diff -Nru a/drivers/pci/hotplug/pci_hotplug_core.c b/drivers/pci/hotplug/pci_hotplug_core.c
@@ -568,7 +568,7 @@
 	if ((slot->info == NULL) || (slot->ops == NULL))
 		return -EINVAL;
 
-	kobject_set_name(&slot->kobj, slot->name);
+	kobject_set_name(&slot->kobj, "%s", slot->name);
 	kobj_set_kset_s(slot, pci_hotplug_slots_subsys);
 
 	/* this can fail if we have already registered a slot with the same name */
fs/sysfs/dir.c +1 -1
diff -Nru a/fs/sysfs/dir.c b/fs/sysfs/dir.c
@@ -181,7 +181,7 @@
 	new_dentry = sysfs_get_dentry(parent, new_name);
 	if (!IS_ERR(new_dentry)) {
   		if (!new_dentry->d_inode) {
-			error = kobject_set_name(kobj,new_name);
+			error = kobject_set_name(kobj, "%s", new_name);
 			if (!error)
 				d_move(kobj->dentry, new_dentry);
 		}
kernel/module.c +1 -1
diff -Nru a/kernel/module.c b/kernel/module.c
@@ -1120,7 +1120,7 @@
 		return -ENOMEM;
 
 	memset(&mod->mkobj->kobj, 0, sizeof(mod->mkobj->kobj));
-	err = kobject_set_name(&mod->mkobj->kobj, mod->name);
+	err = kobject_set_name(&mod->mkobj->kobj, "%s", mod->name);
 	if (err)
 		goto out;
 	kobj_set_kset_s(mod->mkobj, module_subsys);
author
#4 lore raw

ChangeSet 1.2020, 2004/10/22 14:29:19-07:00, [email protected]

[PATCH] kobject_hotplug: permit no hotplug_ops

Make kobject_hotplug() work even if the kobject's kset doesn't implement any hotplug_ops.

 lib/kobject_uevent.c |   19 ++++++++++++-------
 1 files changed, 12 insertions(+), 7 deletions(-)
lib/kobject_uevent.c +12 -7
diff -Nru a/lib/kobject_uevent.c b/lib/kobject_uevent.c
@@ -187,6 +187,8 @@
 	u64 seq;
 	struct kobject *top_kobj = kobj;
 	struct kset *kset;
+	static struct kset_hotplug_ops null_hotplug_ops;
+	struct kset_hotplug_ops *hotplug_ops = &null_hotplug_ops;
 
 	if (!top_kobj->kset && top_kobj->parent) {
 		do {
@@ -194,15 +196,18 @@
 		} while (!top_kobj->kset && top_kobj->parent);
 	}
 
-	if (top_kobj->kset && top_kobj->kset->hotplug_ops)
+	if (top_kobj->kset)
 		kset = top_kobj->kset;
 	else
 		return;
 
+	if (kset->hotplug_ops)
+		hotplug_ops = kset->hotplug_ops;
+
 	/* If the kset has a filter operation, call it.
 	   Skip the event, if the filter returns zero. */
-	if (kset->hotplug_ops->filter) {
-		if (!kset->hotplug_ops->filter(kset, kobj))
+	if (hotplug_ops->filter) {
+		if (!hotplug_ops->filter(kset, kobj))
 			return;
 	}
 
@@ -221,8 +226,8 @@
 	if (!buffer)
 		goto exit;
 
-	if (kset->hotplug_ops->name)
-		name = kset->hotplug_ops->name(kset, kobj);
+	if (hotplug_ops->name)
+		name = hotplug_ops->name(kset, kobj);
 	if (name == NULL)
 		name = kset->kobj.name;
 
@@ -256,9 +261,9 @@
 	envp [i++] = scratch;
 	scratch += sprintf(scratch, "SUBSYSTEM=%s", name) + 1;
 
-	if (kset->hotplug_ops->hotplug) {
+	if (hotplug_ops->hotplug) {
 		/* have the kset specific function add its stuff */
-		retval = kset->hotplug_ops->hotplug (kset, kobj,
+		retval = hotplug_ops->hotplug (kset, kobj,
 				  &envp[i], NUM_ENVP - i, scratch,
 				  BUFFER_SIZE - (scratch - buffer));
 		if (retval) {
author
#5 lore raw

ChangeSet 1.2021, 2004/10/22 14:29:57-07:00, [email protected]

[PATCH] remove cpu_run_sbin_hotplug()

From: Keshavamurthy Anil S <[email protected]>

Remove cpu_run_sbin_hotplug() - use kobject_hotplug() instead.

 drivers/base/cpu.c             |    2 ++
 include/linux/kobject_uevent.h |    1 +
 kernel/cpu.c                   |   35 -----------------------------------
 lib/kobject_uevent.c           |    2 ++
 4 files changed, 5 insertions(+), 35 deletions(-)
drivers/base/cpu.c +2 -0
diff -Nru a/drivers/base/cpu.c b/drivers/base/cpu.c
@@ -32,6 +32,8 @@
 	switch (buf[0]) {
 	case '0':
 		ret = cpu_down(cpu->sysdev.id);
+		if (!ret)
+			kobject_hotplug(&dev->kobj, KOBJ_OFFLINE);
 		break;
 	case '1':
 		ret = cpu_up(cpu->sysdev.id);
include/linux/kobject_uevent.h +1 -0
diff -Nru a/include/linux/kobject_uevent.h b/include/linux/kobject_uevent.h
@@ -22,6 +22,7 @@
 	KOBJ_CHANGE	= (__force kobject_action_t) 0x03,	/* a sysfs attribute file has changed */
 	KOBJ_MOUNT	= (__force kobject_action_t) 0x04,	/* mount event for block devices */
 	KOBJ_UMOUNT	= (__force kobject_action_t) 0x05,	/* umount event for block devices */
+	KOBJ_OFFLINE	= (__force kobject_action_t) 0x06,	/* offline event for hotplug devices */
 };
 
 
kernel/cpu.c +0 -35
diff -Nru a/kernel/cpu.c b/kernel/cpu.c
@@ -57,34 +57,6 @@
 	write_unlock_irq(&tasklist_lock);
 }
 
-/* Notify userspace when a cpu event occurs, by running '/sbin/hotplug
- * cpu' with certain environment variables set.  */
-static int cpu_run_sbin_hotplug(unsigned int cpu, const char *action)
-{
-	char *argv[3], *envp[6], cpu_str[12], action_str[32], devpath_str[40];
-	int i;
-
-	sprintf(cpu_str, "CPU=%d", cpu);
-	sprintf(action_str, "ACTION=%s", action);
-	sprintf(devpath_str, "DEVPATH=devices/system/cpu/cpu%d", cpu);
-	
-	i = 0;
-	argv[i++] = hotplug_path;
-	argv[i++] = "cpu";
-	argv[i] = NULL;
-
-	i = 0;
-	/* minimal command environment */
-	envp[i++] = "HOME=/";
-	envp[i++] = "PATH=/sbin:/bin:/usr/sbin:/usr/bin";
-	envp[i++] = cpu_str;
-	envp[i++] = action_str;
-	envp[i++] = devpath_str;
-	envp[i] = NULL;
-
-	return call_usermodehelper(argv[0], argv, envp, 0);
-}
-
 /* Take this CPU down. */
 static int take_cpu_down(void *unused)
 {
@@ -170,8 +142,6 @@
 
 	check_for_tasks(cpu);
 
-	cpu_run_sbin_hotplug(cpu, "offline");
-
 out_thread:
 	err = kthread_stop(p);
 out_allowed:
@@ -179,11 +149,6 @@
 out:
 	unlock_cpu_hotplug();
 	return err;
-}
-#else
-static inline int cpu_run_sbin_hotplug(unsigned int cpu, const char *action)
-{
-	return 0;
 }
 #endif /*CONFIG_HOTPLUG_CPU*/
 
lib/kobject_uevent.c +2 -0
diff -Nru a/lib/kobject_uevent.c b/lib/kobject_uevent.c
@@ -36,6 +36,8 @@
 		return "mount";
 	case KOBJ_UMOUNT:
 		return "umount";
+	case KOBJ_OFFLINE:
+		return "offline";
 	default:
 		return NULL;
 	}
author
#6 lore raw

ChangeSet 1.2022, 2004/10/22 14:30:22-07:00, [email protected]

[PATCH] kobject_uevent warning fix

lib/kobject_uevent.c:39: warning: `action_to_string' defined but not used

 lib/kobject_uevent.c |    2 ++
 1 files changed, 2 insertions(+)
lib/kobject_uevent.c +2 -0
diff -Nru a/lib/kobject_uevent.c b/lib/kobject_uevent.c
@@ -23,6 +23,7 @@
 #include <linux/kobject.h>
 #include <net/sock.h>
 
+#if defined(CONFIG_KOBJECT_UEVENT) || defined(CONFIG_HOTPLUG)
 static char *action_to_string(enum kobject_action action)
 {
 	switch (action) {
@@ -42,6 +43,7 @@
 		return NULL;
 	}
 }
+#endif
 
 #ifdef CONFIG_KOBJECT_UEVENT
 static struct sock *uevent_sock;
author
#7 lore raw

ChangeSet 1.2023, 2004/10/22 15:43:17-07:00, [email protected]

hotplug: prevent skips in sequence number from happening

 lib/kobject_uevent.c |   17 +++++++++--------
 1 files changed, 9 insertions(+), 8 deletions(-)
lib/kobject_uevent.c +9 -8
diff -Nru a/lib/kobject_uevent.c b/lib/kobject_uevent.c
@@ -255,13 +255,6 @@
 	envp [i++] = scratch;
 	scratch += sprintf (scratch, "DEVPATH=%s", kobj_path) + 1;
 
-	spin_lock(&sequence_lock);
-	seq = ++hotplug_seqnum;
-	spin_unlock(&sequence_lock);
-
-	envp [i++] = scratch;
-	scratch += sprintf(scratch, "SEQNUM=%lld", (long long)seq) + 1;
-
 	envp [i++] = scratch;
 	scratch += sprintf(scratch, "SUBSYSTEM=%s", name) + 1;
 
@@ -277,7 +270,15 @@
 		}
 	}
 
-	pr_debug ("%s: %s %s %s %s %s %s %s\n", __FUNCTION__, argv[0], argv[1],
+	spin_lock(&sequence_lock);
+	seq = ++hotplug_seqnum;
+	spin_unlock(&sequence_lock);
+
+	envp [i++] = scratch;
+	scratch += sprintf(scratch, "SEQNUM=%lld", (long long)seq) + 1;
+
+	pr_debug ("%s: %s %s seq=%lld %s %s %s %s %s\n",
+		  __FUNCTION__, argv[0], argv[1], (long long)seq,
 		  envp[0], envp[1], envp[2], envp[3], envp[4]);
 
 	send_uevent(action_string, kobj_path, buffer, scratch - buffer, GFP_KERNEL);