Skip to contentSkip to conversation

driver core patches against 2.6.24

PATCH In review Greg KH 27 participants 272 messages Jan 25, 2008 – Jan 29, 2008 Page 3 of 3

Subsystems (67)
lore
Share & tools
lore
#230 lore raw

Re: [PATCH 183/196] driver core: fix build with SYSFS=n

In reply to Greg KH
Quoted 5 lines · Greg KH
Quoted 1 line

Please! :-)

Yes, I do agree that this is important, I'll work to not let this happen again. Especially now that I have your build scripts, I'm working on setting up something like that myself here.

btw., Harvey Harrison has cleaned them up some more, and has told me about KCONFIG_ALLCONFIG, which is very useful when you want to tailor randconfig builds to different testsystems (which might have different minimum driver requirements and different distro requirements for kernel features). Harvey, could you send the latest version of those auto-Kconfig cleanups?

Ingo

#231 lore raw

Re: [PATCH 183/196] driver core: fix build with SYSFS=n

Quoted 8 lines · Ingo Molnar
Quoted 5 lines · Greg KH
Quoted 1 line

Please! :-)

Yes, I do agree that this is important, I'll work to not let this happen again. Especially now that I have your build scripts, I'm working on setting up something like that myself here.

Quoted 6 lines

btw., Harvey Harrison has cleaned them up some more, and has told me about KCONFIG_ALLCONFIG, which is very useful when you want to tailor randconfig builds to different testsystems (which might have different minimum driver requirements and different distro requirements for kernel features). Harvey, could you send the latest version of those auto-Kconfig cleanups?

Sorry, I've been a bit laid up with illness to pull out any upstreamable pieces. Attached is the original version I sent to you that still has the Ingo-specific need_config file. Hopefully I'll be back in action and can finish this soon.

This is functionally equivalent to Ingo's patch at:

http://people.redhat.com/mingo/auto-qa-patches/Kconfig-qa.patch

Instead, create a need_config file and invoke randconfig as:

make randconfig KCONFIG_ALLCONFIG=need_config

---
Ingo, your QA patch ends up being much smaller and works exactly the same as long as you invoke randconfig with the above. I've included a need_config file that has all of the options I removed from your patch suitable for the above KCONFIG_ALLCONFIG use.

Cheers,

Harvey

 arch/x86/Kconfig        |   74 +++++++++++++++++++++++++++++++++++
 arch/x86/Kconfig.needed |   99
+++++++++++++++++++++++++++++++++++++++++++++++
 drivers/atm/Kconfig     |    1 +
 drivers/base/core.c     |    3 +
 init/Kconfig            |   13 ++++++
 init/main.c             |   56 ++++++++++++++++++++++++++
 kernel/time/Kconfig     |   13 ++++++
 lib/Kconfig             |    3 +
 need_config             |   85 ++++++++++++++++++++++++++++++++++++++++
 9 files changed, 347 insertions(+), 0 deletions(-)
arch/x86/Kconfig +41 -0
index 665e4b1..9061f77 100644
@@ -164,6 +164,12 @@ config X86_TRAMPOLINE
 
 config KTIME_SCALAR
        def_bool X86_32
+
+config BOOTPARAM_SUPPORT
+       bool "bootparam support"
+       help
+         support for boot command-line parameters via .config
+
 source "init/Kconfig"
 
 menu "Processor type and features"
@@ -1204,6 +1210,66 @@ config COMPAT_VDSO
 
          If unsure, say Y.
 
+config BOOTPARAM_NMI_WATCHDOG_BIT_0
+       bool "bootparam: nmi_watchdog=X default value - bit 0"
+       depends on BOOTPARAM_SUPPORT
+       help
+         NMI watchdog default, bit 0. Useful for automated testing.
+
+config BOOTPARAM_NMI_WATCHDOG_BIT_1
+       bool "bootparam: nmi_watchdog=X default value - bit 1"
+       depends on BOOTPARAM_SUPPORT
+       help
+         NMI watchdog default, bit 1. Useful for automated testing.
+
+config BOOTPARAM_NOAPIC
+       bool "bootparam: noapic"
+       depends on BOOTPARAM_SUPPORT
+       help
+         if enabled, it has the effect as "noapic" on the boot line
+
+config BOOTPARAM_NOLAPIC
+       bool "bootparam: nolapic"
+       depends on BOOTPARAM_SUPPORT
+       help
+         if enabled, it has the effect as "nolapic" on the boot line
+
+config BOOTPARAM_LAPIC
+       bool "bootparam: lapic"
+       depends on BOOTPARAM_SUPPORT
+       help
+         if enabled, it has the effect as "lapic" on the boot line
+
+config BOOTPARAM_HPET_DISABLE
+       bool "bootparam: hpet=disable"
+       depends on BOOTPARAM_SUPPORT
+       help
+         if enabled, it has the effect as "hpet=disable" on the boot

line
+
+config BOOTPARAM_IDLE_MWAIT

+       bool "bootparam: idle=mwait"
+       depends on BOOTPARAM_SUPPORT
+       help
+         if enabled, it has the effect as "idle=mwait" on the boot line
+
+config BOOTPARAM_IDLE_POLL
+       bool "bootparam: idle=poll"
+       depends on BOOTPARAM_SUPPORT
+       help
+         if enabled, it has the effect as "idle=poll" on the boot line
+
+config BOOTPARAM_HIGHMEM_512M
+       bool "bootparam: highmem=512m"
+       depends on BOOTPARAM_SUPPORT
+       help
+         highmem=512m boot parameter. Useful for automated testing.
+
+config BOOTPARAM_NOPAT
+       bool "bootparam: nopat"
+       depends on BOOTPARAM_SUPPORT
+       help

+ if enabled, it has the effect as "nopat" on the boot line
+
endmenu

config ARCH_ENABLE_MEMORY_HOTPLUG
@@ -1612,3 +1678,11 @@ source "security/Kconfig"
source "crypto/Kconfig"

source "lib/Kconfig"
+
+config X86_32_ALWAYS_ON

+       bool
+       default y
+       depends on X86_32
+       select X86_PC
+       select PCI_GOANY

+

arch/x86/Kconfig.needed new file +99 -0

99 lines not on this page · raw message

drivers/atm/Kconfig +1 -0
index b554eda..caf4d20 100644
@@ -344,6 +344,7 @@ config ATM_FORE200E_MAYBE
 config ATM_FORE200E_PCA
        bool "PCA-200E support"
        depends on ATM_FORE200E_MAYBE && PCI
+       select ATM_FORE200E_PCA_DEFAULT_FW if PREVENT_FIRMWARE_BUILD
        help
          Say Y here if you want your PCA-200E cards to be probed.
 
drivers/base/core.c +0 -0
index 2683eac..84e61f5 100644
@@ -104,7 +104,10 @@ static void device_release(struct kobject * kobj)
                printk(KERN_ERR "Device '%s' does not have a release()

function, "
"it is broken and must be fixed.\n", dev->bus_id);
+#if 0
+ // not a real bug:

                WARN_ON(1);
+#endif
        }

}

init/Kconfig +13 -0
index b9d11a8..add6333 100644
@@ -324,6 +324,19 @@ config CPUSETS
 
          Say N if unsure.
 
+config BOOTPARAM_MAXCPUS_1
+       bool "bootparam: maxcpus=1"
+       depends on BOOTPARAM_SUPPORT
+       help
+         if enabled, it has the effect as "maxcpus=1" on the boot line
+
+config BOOTPARAM_NOSMP
+       bool "bootparam: nosmp"
+       depends on BOOTPARAM_SUPPORT
+       help
+         if enabled, it has the effect as "nosmp" on the boot line
+
+
 config FAIR_GROUP_SCHED
        bool "Fair group CPU scheduler"
        default y
init/main.c +52 -0

61 lines not on this page · raw message

do_early_param);
+

        done = 1;

}

@@ -511,6 +564,9 @@ asmlinkage void __init start_kernel(void)

        smp_setup_processor_id();

+ /* Build-time simulated boot parameters: */
+ strncat(boot_command_line, bootparam_command_line,
COMMAND_LINE_SIZE);
+
/*
* Need to run as early as possible, to initialize the
* lockdep hash:

kernel/time/Kconfig +13 -0
index 8d53106..a6b3b23 100644
@@ -14,6 +14,12 @@ config NO_HZ
          only trigger on an as-needed basis both when the system is
          busy and when the system is idle.
 
+config BOOTPARAM_NO_HZ_OFF
+       bool "bootparam: no_hz"
+       depends on BOOTPARAM_SUPPORT
+       help
+         if enabled, it has the effect as "no_hz=off" on the boot line
+
 config HIGH_RES_TIMERS
        bool "High Resolution Timer Support"
        depends on GENERIC_TIME && GENERIC_CLOCKEVENTS
@@ -28,3 +34,10 @@ config GENERIC_CLOCKEVENTS_BUILD
        default y
        depends on GENERIC_CLOCKEVENTS || GENERIC_CLOCKEVENTS_MIGR
 
+config BOOTPARAM_HIGHRES_OFF
+       bool "bootparam: highres=0"
+       depends on BOOTPARAM_SUPPORT
+       help
+         if enabled, it has the effect as "highres=0" on the boot line
+
+
lib/Kconfig +3 -0
index ba3d104..a4537df 100644
@@ -142,3 +142,6 @@ config CHECK_SIGNATURE
        bool
 
 endmenu
+
+source "arch/x86/Kconfig.needed"
+
need_config new file +85 -0

85 lines not on this page · raw message

Signature · 1 line
1.5.4.rc3.1118.gf6754c
#232 lore raw

PATCH 184/196 Driver Core: constify the name passed to platform_device_register_simple

In reply to Greg KH

From: Stephen Rothwell <[email protected]>

This name is just passed to platform_device_alloc which has its parameter declared const.

---
 drivers/base/platform.c         |    2 +-
 include/linux/platform_device.h |    2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
drivers/base/platform.c +1 -1
index bdd59e8..48d5db4 100644
@@ -360,7 +360,7 @@ EXPORT_SYMBOL_GPL(platform_device_unregister);
  *	the Linux driver model.  In particular, when such drivers are built
  *	as modules, they can't be "hotplugged".
  */
-struct platform_device *platform_device_register_simple(char *name, int id,
+struct platform_device *platform_device_register_simple(const char *name, int id,
 							struct resource *res, unsigned int num)
 {
 	struct platform_device *pdev;
include/linux/platform_device.h +1 -1
index e808043..3261681 100644
@@ -35,7 +35,7 @@ extern struct resource *platform_get_resource_byname(struct platform_device *, u
 extern int platform_get_irq_byname(struct platform_device *, char *);
 extern int platform_add_devices(struct platform_device **, int);
 
-extern struct platform_device *platform_device_register_simple(char *, int id,
+extern struct platform_device *platform_device_register_simple(const char *, int id,
 					struct resource *, unsigned int);
 
 extern struct platform_device *platform_device_alloc(const char *name, int id);
Signature · 1 line
1.5.3.8
#233 lore raw

PATCH 185/196 UIO: constify function pointer tables

In reply to Greg KH

From: Jan Engelhardt <[email protected]>

---
 drivers/uio/uio.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
drivers/uio/uio.c +2 -2
index 03b66fb..cc246fa 100644
@@ -39,7 +39,7 @@ struct uio_device {
 
 static int uio_major;
 static DEFINE_IDR(uio_idr);
-static struct file_operations uio_fops;
+static const struct file_operations uio_fops;
 
 /* UIO class infrastructure */
 static struct uio_class {
@@ -508,7 +508,7 @@ static int uio_mmap(struct file *filep, struct vm_area_struct *vma)
 	}
 }
 
-static struct file_operations uio_fops = {
+static const struct file_operations uio_fops = {
 	.owner		= THIS_MODULE,
 	.open		= uio_open,
 	.release	= uio_release,
Signature · 1 line
1.5.3.8
#234 lore raw

Re: [PATCH 185/196] UIO: constify function pointer tables

Am Thu, 24 Jan 2008 23:33:34 -0800
schrieb Greg Kroah-Hartman <[email protected]>:

Quoted 4 lines

From: Jan Engelhardt <[email protected]>

Quoted 26 lines
---
 drivers/uio/uio.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
drivers/uio/uio.c +2 -2
index 03b66fb..cc246fa 100644
@@ -39,7 +39,7 @@ struct uio_device {
 
 static int uio_major;
 static DEFINE_IDR(uio_idr);
-static struct file_operations uio_fops;
+static const struct file_operations uio_fops;
 
 /* UIO class infrastructure */
 static struct uio_class {
@@ -508,7 +508,7 @@ static int uio_mmap(struct file *filep, struct
 vm_area_struct *vma) }
 }
 
-static struct file_operations uio_fops = {
+static const struct file_operations uio_fops = {
 	.owner		= THIS_MODULE,
 	.open		= uio_open,
 	.release	= uio_release,
#235 lore raw

PATCH 186/196 Driver core: Cleanup get_device_parent() in device_add() and device_move()

In reply to Greg KH

From: Cornelia Huck <[email protected]>

Make setup_parent() void as get_device_parent() will always return either a valid kobject or NULL.
Introduce cleanup_glue_dir() to drop reference grabbed on "glue" directory by get_device_parent(). Use it for cleanup in device_move() and device_add() on errors.

This should fix the refcounting problem reported in
http://marc.info/?l=linux-kernel&m=120052487909200&w=2

Cc Dave Young <[email protected]>
Cc Gabor Gombas <[email protected]>
Cc Tejun Heo <[email protected]>
Cc Al Viro <[email protected]>
Cc Marcel Holtmann <[email protected]>
Cc David Miller <[email protected]>
Cc Kay Sievers <[email protected]>
---
 drivers/base/core.c |   29 ++++++++++++++---------------
 1 files changed, 14 insertions(+), 15 deletions(-)
drivers/base/core.c +14 -15
index d5d542d..f09dde3 100644
@@ -552,6 +552,8 @@ static struct kobject *get_device_parent(struct device *dev,
 }
 
 static inline void cleanup_device_parent(struct device *dev) {}
+static inline void cleanup_glue_dir(struct device *dev,
+				    struct kobject *glue_dir) {}
 #else
 static struct kobject *virtual_device_parent(struct device *dev)
 {
@@ -616,27 +618,27 @@ static struct kobject *get_device_parent(struct device *dev,
 	return NULL;
 }
 
-static void cleanup_device_parent(struct device *dev)
+static void cleanup_glue_dir(struct device *dev, struct kobject *glue_dir)
 {
-	struct kobject *glue_dir = dev->kobj.parent;
-
 	/* see if we live in a "glue" directory */
 	if (!dev->class || glue_dir->kset != &dev->class->class_dirs)
 		return;
 
 	kobject_put(glue_dir);
 }
+
+static void cleanup_device_parent(struct device *dev)
+{
+	cleanup_glue_dir(dev, dev->kobj.parent);
+}
 #endif
 
-static int setup_parent(struct device *dev, struct device *parent)
+static void 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;
 }
 
 static int device_add_class_symlinks(struct device *dev)
@@ -784,9 +786,7 @@ int device_add(struct device *dev)
 	pr_debug("device: '%s': %s\n", dev->bus_id, __FUNCTION__);
 
 	parent = get_device(dev->parent);
-	error = setup_parent(dev, parent);
-	if (error)
-		goto Error;
+	setup_parent(dev, parent);
 
 	/* first, register with generic layer. */
 	error = kobject_add(&dev->kobj, dev->kobj.parent, "%s", dev->bus_id);
@@ -864,6 +864,7 @@ int device_add(struct device *dev)
 	kobject_uevent(&dev->kobj, KOBJ_REMOVE);
 	kobject_del(&dev->kobj);
  Error:
+	cleanup_device_parent(dev);
 	if (parent)
 		put_device(parent);
 	goto Done;
@@ -1344,15 +1345,12 @@ int device_move(struct device *dev, struct device *new_parent)
 
 	new_parent = get_device(new_parent);
 	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: '%s': %s: moving to '%s'\n", dev->bus_id,
 		 __FUNCTION__, new_parent ? new_parent->bus_id : "<NULL>");
 	error = kobject_move(&dev->kobj, new_parent_kobj);
 	if (error) {
+		cleanup_glue_dir(dev, new_parent_kobj);
 		put_device(new_parent);
 		goto out;
 	}
@@ -1375,6 +1373,7 @@ int device_move(struct device *dev, struct device *new_parent)
 				klist_add_tail(&dev->knode_parent,
 					       &old_parent->klist_children);
 		}
+		cleanup_glue_dir(dev, new_parent_kobj);
 		put_device(new_parent);
 		goto out;
 	}
Signature · 1 line
1.5.3.8
#236 lore raw

PATCH 187/196 Driver Core: add class iteration api

In reply to Greg KH

From: Dave Young <[email protected]>

Add the following class iteration functions for driver use:
class_for_each_device
class_find_device
class_for_each_child
class_find_child

---
 drivers/base/class.c   |  133 ++++++++++++++++++++++++++++++++++++++++++++++++
 include/linux/device.h |    9 +++-
 2 files changed, 140 insertions(+), 2 deletions(-)
drivers/base/class.c +133 -0
index b962a76..9f737ff 100644
@@ -809,6 +809,139 @@ void class_device_put(struct class_device *class_dev)
 		kobject_put(&class_dev->kobj);
 }
 
+/**
+ * class_for_each_device - device iterator
+ * @class: the class we're iterating
+ * @data: data for the callback
+ * @fn: function to be called for each device
+ *
+ * Iterate over @class's list of devices, and call @fn for each,
+ * passing it @data.
+ *
+ * We check the return of @fn each time. If it returns anything
+ * other than 0, we break out and return that value.
+ *
+ * Note, we hold class->sem in this function, so it can not be
+ * re-acquired in @fn, otherwise it will self-deadlocking. For
+ * example, calls to add or remove class members would be verboten.
+ */
+int class_for_each_device(struct class *class, void *data,
+			   int (*fn)(struct device *, void *))
+{
+	struct device *dev;
+	int error = 0;
+
+	if (!class)
+		return -EINVAL;
+	down(&class->sem);
+	list_for_each_entry(dev, &class->devices, node) {
+		dev = get_device(dev);
+		if (dev) {
+			error = fn(dev, data);
+			put_device(dev);
+		} else
+			error = -ENODEV;
+		if (error)
+			break;
+	}
+	up(&class->sem);
+
+	return error;
+}
+EXPORT_SYMBOL_GPL(class_for_each_device);
+
+/**
+ * class_find_device - device iterator for locating a particular device
+ * @class: the class we're iterating
+ * @data: data for the match function
+ * @match: function to check device
+ *
+ * This is similar to the class_for_each_dev() function above, but it
+ * returns a reference to a device that is 'found' for later use, as
+ * determined by the @match callback.
+ *
+ * The callback should return 0 if the device doesn't match and non-zero
+ * if it does.  If the callback returns non-zero, this function will
+ * return to the caller and not iterate over any more devices.
+
+ * Note, you will need to drop the reference with put_device() after use.
+ *
+ * We hold class->sem in this function, so it can not be
+ * re-acquired in @match, otherwise it will self-deadlocking. For
+ * example, calls to add or remove class members would be verboten.
+ */
+struct device *class_find_device(struct class *class, void *data,
+				   int (*match)(struct device *, void *))
+{
+	struct device *dev;
+	int found = 0;
+
+	if (!class)
+		return NULL;
+
+	down(&class->sem);
+	list_for_each_entry(dev, &class->devices, node) {
+		dev = get_device(dev);
+		if (dev) {
+			if (match(dev, data)) {
+				found = 1;
+				break;
+			} else
+				put_device(dev);
+		} else
+			break;
+	}
+	up(&class->sem);
+
+	return found ? dev : NULL;
+}
+EXPORT_SYMBOL_GPL(class_find_device);
+
+/**
+ * class_find_child - device iterator for locating a particular class_device
+ * @class: the class we're iterating
+ * @data: data for the match function
+ * @match: function to check class_device
+ *
+ * This function returns a reference to a class_device that is 'found' for
+ * later use, as determined by the @match callback.
+ *
+ * The callback should return 0 if the class_device doesn't match and non-zero
+ * if it does.  If the callback returns non-zero, this function will
+ * return to the caller and not iterate over any more class_devices.
+ *
+ * Note, you will need to drop the reference with class_device_put() after use.
+ *
+ * We hold class->sem in this function, so it can not be
+ * re-acquired in @match, otherwise it will self-deadlocking. For
+ * example, calls to add or remove class members would be verboten.
+ */
+struct class_device *class_find_child(struct class *class, void *data,
+				   int (*match)(struct class_device *, void *))
+{
+	struct class_device *dev;
+	int found = 0;
+
+	if (!class)
+		return NULL;
+
+	down(&class->sem);
+	list_for_each_entry(dev, &class->children, node) {
+		dev = class_device_get(dev);
+		if (dev) {
+			if (match(dev, data)) {
+				found = 1;
+				break;
+			} else
+				class_device_put(dev);
+		} else
+			break;
+	}
+	up(&class->sem);
+
+	return found ? dev : NULL;
+}
+EXPORT_SYMBOL_GPL(class_find_child);
 
 int class_interface_register(struct class_interface *class_intf)
 {
include/linux/device.h +7 -2
index 92ba3a8..cdaf57b 100644
@@ -177,8 +177,7 @@ struct class {
 	struct list_head	devices;
 	struct list_head	interfaces;
 	struct kset		class_dirs;
-	struct semaphore	sem;	/* locks both the children and interfaces lists */
-
+	struct semaphore	sem; /* locks children, devices, interfaces */
 	struct class_attribute		* class_attrs;
 	struct class_device_attribute	* class_dev_attrs;
 	struct device_attribute		* dev_attrs;
@@ -196,6 +195,12 @@ struct class {
 
 extern int __must_check class_register(struct class *);
 extern void class_unregister(struct class *);
+extern int class_for_each_device(struct class *class, void *data,
+				 int (*fn)(struct device *dev, void *data));
+extern struct device *class_find_device(struct class *class, void *data,
+					int (*match)(struct device *, void *));
+extern struct class_device *class_find_child(struct class *class, void *data,
+				   int (*match)(struct class_device *, void *));
 
 
 struct class_attribute {
Signature · 1 line
1.5.3.8
#237 lore raw

PATCH 188/196 ieee1394: use class iteration api

In reply to Greg KH

From: Dave Young <[email protected]>

Convert to use the class iteration api.

---
 drivers/ieee1394/nodemgr.c |  314 +++++++++++++++++++++++++-------------------
 1 files changed, 176 insertions(+), 138 deletions(-)
drivers/ieee1394/nodemgr.c +176 -138
index 90dc75b..511e432 100644
@@ -727,33 +727,31 @@ static int nodemgr_bus_match(struct device * dev, struct device_driver * drv)
 
 static DEFINE_MUTEX(nodemgr_serialize_remove_uds);
 
+static int __match_ne(struct device *dev, void *data)
+{
+	struct unit_directory *ud;
+	struct node_entry *ne = (struct node_entry *)data;
+
+	ud = container_of(dev, struct unit_directory, unit_dev);
+	return ud->ne == ne;
+}
+
 static void nodemgr_remove_uds(struct node_entry *ne)
 {
 	struct device *dev;
-	struct unit_directory *tmp, *ud;
-
-	/* Iteration over nodemgr_ud_class.devices has to be protected by
-	 * nodemgr_ud_class.sem, but device_unregister() will eventually
-	 * take nodemgr_ud_class.sem too. Therefore pick out one ud at a time,
-	 * release the semaphore, and then unregister the ud. Since this code
-	 * may be called from other contexts besides the knodemgrds, protect the
-	 * gap after release of the semaphore by nodemgr_serialize_remove_uds.
+	struct unit_directory *ud;
+
+	/* Use class_find device to iterate the devices. Since this code
+	 * may be called from other contexts besides the knodemgrds,
+	 * protect it by nodemgr_serialize_remove_uds.
 	 */
 	mutex_lock(&nodemgr_serialize_remove_uds);
 	for (;;) {
-		ud = NULL;
-		down(&nodemgr_ud_class.sem);
-		list_for_each_entry(dev, &nodemgr_ud_class.devices, node) {
-			tmp = container_of(dev, struct unit_directory,
-					   unit_dev);
-			if (tmp->ne == ne) {
-				ud = tmp;
-				break;
-			}
-		}
-		up(&nodemgr_ud_class.sem);
-		if (ud == NULL)
+		dev = class_find_device(&nodemgr_ud_class, ne, __match_ne);
+		if (!dev)
 			break;
+		ud = container_of(dev, struct unit_directory, unit_dev);
+		put_device(dev);
 		device_unregister(&ud->unit_dev);
 		device_unregister(&ud->device);
 	}
@@ -882,45 +880,66 @@ fail_alloc:
 	return NULL;
 }
 
+static int __match_ne_guid(struct device *dev, void *data)
+{
+	struct node_entry *ne;
+	u64 *guid = (u64 *)data;
+
+	ne = container_of(dev, struct node_entry, node_dev);
+	return ne->guid == *guid;
+}
 
 static struct node_entry *find_entry_by_guid(u64 guid)
 {
 	struct device *dev;
-	struct node_entry *ne, *ret_ne = NULL;
-
-	down(&nodemgr_ne_class.sem);
-	list_for_each_entry(dev, &nodemgr_ne_class.devices, node) {
-		ne = container_of(dev, struct node_entry, node_dev);
+	struct node_entry *ne;
 
-		if (ne->guid == guid) {
-			ret_ne = ne;
-			break;
-		}
-	}
-	up(&nodemgr_ne_class.sem);
+	dev = class_find_device(&nodemgr_ne_class, &guid, __match_ne_guid);
+	if (!dev)
+		return NULL;
+	ne = container_of(dev, struct node_entry, node_dev);
+	put_device(dev);
 
-	return ret_ne;
+	return ne;
 }
 
+struct match_nodeid_param {
+	struct hpsb_host *host;
+	nodeid_t nodeid;
+};
+
+static int __match_ne_nodeid(struct device *dev, void *data)
+{
+	int found = 0;
+	struct node_entry *ne;
+	struct match_nodeid_param *param = (struct match_nodeid_param *)data;
+
+	if (!dev)
+		goto ret;
+	ne = container_of(dev, struct node_entry, node_dev);
+	if (ne->host == param->host && ne->nodeid == param->nodeid)
+		found = 1;
+ret:
+	return found;
+}
 
 static struct node_entry *find_entry_by_nodeid(struct hpsb_host *host,
 					       nodeid_t nodeid)
 {
 	struct device *dev;
-	struct node_entry *ne, *ret_ne = NULL;
+	struct node_entry *ne;
+	struct match_nodeid_param param;
 
-	down(&nodemgr_ne_class.sem);
-	list_for_each_entry(dev, &nodemgr_ne_class.devices, node) {
-		ne = container_of(dev, struct node_entry, node_dev);
+	param.host = host;
+	param.nodeid = nodeid;
 
-		if (ne->host == host && ne->nodeid == nodeid) {
-			ret_ne = ne;
-			break;
-		}
-	}
-	up(&nodemgr_ne_class.sem);
+	dev = class_find_device(&nodemgr_ne_class, &param, __match_ne_nodeid);
+	if (!dev)
+		return NULL;
+	ne = container_of(dev, struct node_entry, node_dev);
+	put_device(dev);
 
-	return ret_ne;
+	return ne;
 }
 
 
@@ -1370,107 +1389,109 @@ static void nodemgr_node_scan(struct host_info *hi, int generation)
 	}
 }
 
-
-static void nodemgr_suspend_ne(struct node_entry *ne)
+static int __nodemgr_driver_suspend(struct device *dev, void *data)
 {
-	struct device *dev;
 	struct unit_directory *ud;
 	struct device_driver *drv;
+	struct node_entry *ne = (struct node_entry *)data;
 	int error;
 
-	HPSB_DEBUG("Node suspended: ID:BUS[" NODE_BUS_FMT "]  GUID[%016Lx]",
-		   NODE_BUS_ARGS(ne->host, ne->nodeid), (unsigned long long)ne->guid);
+	ud = container_of(dev, struct unit_directory, unit_dev);
+	if (ud->ne == ne) {
+		drv = get_driver(ud->device.driver);
+		if (drv) {
+			error = 1; /* release if suspend is not implemented */
+			if (drv->suspend) {
+				down(&ud->device.sem);
+				error = drv->suspend(&ud->device, PMSG_SUSPEND);
+				up(&ud->device.sem);
+			}
+			if (error)
+				device_release_driver(&ud->device);
+			put_driver(drv);
+		}
+	}
 
-	ne->in_limbo = 1;
-	WARN_ON(device_create_file(&ne->device, &dev_attr_ne_in_limbo));
+	return 0;
+}
 
-	down(&nodemgr_ud_class.sem);
-	list_for_each_entry(dev, &nodemgr_ud_class.devices, node) {
-		ud = container_of(dev, struct unit_directory, unit_dev);
-		if (ud->ne != ne)
-			continue;
+static int __nodemgr_driver_resume(struct device *dev, void *data)
+{
+	struct unit_directory *ud;
+	struct device_driver *drv;
+	struct node_entry *ne = (struct node_entry *)data;
 
+	ud = container_of(dev, struct unit_directory, unit_dev);
+	if (ud->ne == ne) {
 		drv = get_driver(ud->device.driver);
-		if (!drv)
-			continue;
-
-		error = 1; /* release if suspend is not implemented */
-		if (drv->suspend) {
-			down(&ud->device.sem);
-			error = drv->suspend(&ud->device, PMSG_SUSPEND);
-			up(&ud->device.sem);
+		if (drv) {
+			if (drv->resume) {
+				down(&ud->device.sem);
+				drv->resume(&ud->device);
+				up(&ud->device.sem);
+			}
+			put_driver(drv);
 		}
-		if (error)
-			device_release_driver(&ud->device);
-		put_driver(drv);
 	}
-	up(&nodemgr_ud_class.sem);
-}
 
+	return 0;
+}
 
-static void nodemgr_resume_ne(struct node_entry *ne)
+static void nodemgr_suspend_ne(struct node_entry *ne)
 {
-	struct device *dev;
-	struct unit_directory *ud;
-	struct device_driver *drv;
+	HPSB_DEBUG("Node suspended: ID:BUS[" NODE_BUS_FMT "]  GUID[%016Lx]",
+		   NODE_BUS_ARGS(ne->host, ne->nodeid),
+		   (unsigned long long)ne->guid);
 
-	ne->in_limbo = 0;
-	device_remove_file(&ne->device, &dev_attr_ne_in_limbo);
+	ne->in_limbo = 1;
+	WARN_ON(device_create_file(&ne->device, &dev_attr_ne_in_limbo));
 
-	down(&nodemgr_ud_class.sem);
-	list_for_each_entry(dev, &nodemgr_ud_class.devices, node) {
-		ud = container_of(dev, struct unit_directory, unit_dev);
-		if (ud->ne != ne)
-			continue;
+	class_for_each_device(&nodemgr_ud_class, ne, __nodemgr_driver_suspend);
+}
 
-		drv = get_driver(ud->device.driver);
-		if (!drv)
-			continue;
 
-		if (drv->resume) {
-			down(&ud->device.sem);
-			drv->resume(&ud->device);
-			up(&ud->device.sem);
-		}
-		put_driver(drv);
-	}
-	up(&nodemgr_ud_class.sem);
+static void nodemgr_resume_ne(struct node_entry *ne)
+{
+	ne->in_limbo = 0;
+	device_remove_file(&ne->device, &dev_attr_ne_in_limbo);
 
+	class_for_each_device(&nodemgr_ud_class, ne, __nodemgr_driver_resume);
 	HPSB_DEBUG("Node resumed: ID:BUS[" NODE_BUS_FMT "]  GUID[%016Lx]",
 		   NODE_BUS_ARGS(ne->host, ne->nodeid), (unsigned long long)ne->guid);
 }
 
-
-static void nodemgr_update_pdrv(struct node_entry *ne)
+static int __nodemgr_update_pdrv(struct device *dev, void *data)
 {
-	struct device *dev;
 	struct unit_directory *ud;
 	struct device_driver *drv;
 	struct hpsb_protocol_driver *pdrv;
+	struct node_entry *ne = (struct node_entry *)data;
 	int error;
 
-	down(&nodemgr_ud_class.sem);
-	list_for_each_entry(dev, &nodemgr_ud_class.devices, node) {
-		ud = container_of(dev, struct unit_directory, unit_dev);
-		if (ud->ne != ne)
-			continue;
-
+	ud = container_of(dev, struct unit_directory, unit_dev);
+	if (ud->ne == ne) {
 		drv = get_driver(ud->device.driver);
-		if (!drv)
-			continue;
-
-		error = 0;
-		pdrv = container_of(drv, struct hpsb_protocol_driver, driver);
-		if (pdrv->update) {
-			down(&ud->device.sem);
-			error = pdrv->update(ud);
-			up(&ud->device.sem);
+		if (drv) {
+			error = 0;
+			pdrv = container_of(drv, struct hpsb_protocol_driver,
+					    driver);
+			if (pdrv->update) {
+				down(&ud->device.sem);
+				error = pdrv->update(ud);
+				up(&ud->device.sem);
+			}
+			if (error)
+				device_release_driver(&ud->device);
+			put_driver(drv);
 		}
-		if (error)
-			device_release_driver(&ud->device);
-		put_driver(drv);
 	}
-	up(&nodemgr_ud_class.sem);
+
+	return 0;
+}
+
+static void nodemgr_update_pdrv(struct node_entry *ne)
+{
+	class_for_each_device(&nodemgr_ud_class, ne, __nodemgr_update_pdrv);
 }
 
 
@@ -1529,13 +1550,31 @@ static void nodemgr_probe_ne(struct host_info *hi, struct node_entry *ne, int ge
 	put_device(dev);
 }
 
+struct probe_param {
+	struct host_info *hi;
+	int generation;
+};
+
+static int __nodemgr_node_probe(struct device *dev, void *data)
+{
+	struct probe_param *param = (struct probe_param *)data;
+	struct node_entry *ne;
+
+	ne = container_of(dev, struct node_entry, node_dev);
+	if (!ne->needs_probe)
+		nodemgr_probe_ne(param->hi, ne, param->generation);
+	if (ne->needs_probe)
+		nodemgr_probe_ne(param->hi, ne, param->generation);
+	return 0;
+}
 
 static void nodemgr_node_probe(struct host_info *hi, int generation)
 {
 	struct hpsb_host *host = hi->host;
-	struct device *dev;
-	struct node_entry *ne;
+	struct probe_param param;
 
+	param.hi = hi;
+	param.generation = generation;
 	/* Do some processing of the nodes we've probed. This pulls them
 	 * into the sysfs layer if needed, and can result in processing of
 	 * unit-directories, or just updating the node and it's
@@ -1545,19 +1584,7 @@ static void nodemgr_node_probe(struct host_info *hi, int generation)
 	 * while probes are time-consuming. (Well, those probes need some
 	 * improvement...) */
 
-	down(&nodemgr_ne_class.sem);
-	list_for_each_entry(dev, &nodemgr_ne_class.devices, node) {
-		ne = container_of(dev, struct node_entry, node_dev);
-		if (!ne->needs_probe)
-			nodemgr_probe_ne(hi, ne, generation);
-	}
-	list_for_each_entry(dev, &nodemgr_ne_class.devices, node) {
-		ne = container_of(dev, struct node_entry, node_dev);
-		if (ne->needs_probe)
-			nodemgr_probe_ne(hi, ne, generation);
-	}
-	up(&nodemgr_ne_class.sem);
-
+	class_for_each_device(&nodemgr_ne_class, &param, __nodemgr_node_probe);
 
 	/* If we had a bus reset while we were scanning the bus, it is
 	 * possible that we did not probe all nodes.  In that case, we
@@ -1757,6 +1784,22 @@ exit:
 	return 0;
 }
 
+struct host_iter_param {
+	void *data;
+	int (*cb)(struct hpsb_host *, void *);
+};
+
+static int __nodemgr_for_each_host(struct device *dev, void *data)
+{
+	struct hpsb_host *host;
+	struct host_iter_param *hip = (struct host_iter_param *)data;
+	int error = 0;
+
+	host = container_of(dev, struct hpsb_host, host_dev);
+	error = hip->cb(host, hip->data);
+
+	return error;
+}
 /**
  * nodemgr_for_each_host - call a function for each IEEE 1394 host
  * @data: an address to supply to the callback
@@ -1771,18 +1814,13 @@ exit:
  */
 int nodemgr_for_each_host(void *data, int (*cb)(struct hpsb_host *, void *))
 {
-	struct device *dev;
-	struct hpsb_host *host;
-	int error = 0;
-
-	down(&hpsb_host_class.sem);
-	list_for_each_entry(dev, &hpsb_host_class.devices, node) {
-		host = container_of(dev, struct hpsb_host, host_dev);
+	struct host_iter_param hip;
+	int error;
 
-		if ((error = cb(host, data)))
-			break;
-	}
-	up(&hpsb_host_class.sem);
+	hip.cb = cb;
+	hip.data = data;
+	error = class_for_each_device(&hpsb_host_class, &hip,
+				      __nodemgr_for_each_host);
 
 	return error;
 }
Signature · 1 line
1.5.3.8
#238 lore raw

PATCH 189/196 power supply : use class iteration api

In reply to Greg KH

From: Dave Young <[email protected]>

Convert to use the class iteration api.

---
 drivers/power/apm_power.c         |  116 +++++++++++++++++++++---------------
 drivers/power/power_supply_core.c |   74 ++++++++++++-----------
 2 files changed, 107 insertions(+), 83 deletions(-)
drivers/power/apm_power.c +68 -48
index bbf3ee1..7e29b90 100644
@@ -13,6 +13,7 @@
 #include <linux/power_supply.h>
 #include <linux/apm-emulation.h>
 
+static DEFINE_MUTEX(apm_mutex);
 #define PSY_PROP(psy, prop, val) psy->get_property(psy, \
 			 POWER_SUPPLY_PROP_##prop, val)
 
@@ -23,67 +24,86 @@
 
 static struct power_supply *main_battery;
 
-static void find_main_battery(void)
-{
-	struct device *dev;
-	struct power_supply *bat = NULL;
-	struct power_supply *max_charge_bat = NULL;
-	struct power_supply *max_energy_bat = NULL;
+struct find_bat_param {
+	struct power_supply *main;
+	struct power_supply *bat;
+	struct power_supply *max_charge_bat;
+	struct power_supply *max_energy_bat;
 	union power_supply_propval full;
-	int max_charge = 0;
-	int max_energy = 0;
+	int max_charge;
+	int max_energy;
+};
 
-	main_battery = NULL;
+static int __find_main_battery(struct device *dev, void *data)
+{
+	struct find_bat_param *bp = (struct find_bat_param *)data;
 
-	list_for_each_entry(dev, &power_supply_class->devices, node) {
-		bat = dev_get_drvdata(dev);
+	bp->bat = dev_get_drvdata(dev);
 
-		if (bat->use_for_apm) {
-			/* nice, we explicitly asked to report this battery. */
-			main_battery = bat;
-			return;
-		}
+	if (bp->bat->use_for_apm) {
+		/* nice, we explicitly asked to report this battery. */
+		bp->main = bp->bat;
+		return 1;
+	}
 
-		if (!PSY_PROP(bat, CHARGE_FULL_DESIGN, &full) ||
-				!PSY_PROP(bat, CHARGE_FULL, &full)) {
-			if (full.intval > max_charge) {
-				max_charge_bat = bat;
-				max_charge = full.intval;
-			}
-		} else if (!PSY_PROP(bat, ENERGY_FULL_DESIGN, &full) ||
-				!PSY_PROP(bat, ENERGY_FULL, &full)) {
-			if (full.intval > max_energy) {
-				max_energy_bat = bat;
-				max_energy = full.intval;
-			}
+	if (!PSY_PROP(bp->bat, CHARGE_FULL_DESIGN, &bp->full) ||
+			!PSY_PROP(bp->bat, CHARGE_FULL, &bp->full)) {
+		if (bp->full.intval > bp->max_charge) {
+			bp->max_charge_bat = bp->bat;
+			bp->max_charge = bp->full.intval;
+		}
+	} else if (!PSY_PROP(bp->bat, ENERGY_FULL_DESIGN, &bp->full) ||
+			!PSY_PROP(bp->bat, ENERGY_FULL, &bp->full)) {
+		if (bp->full.intval > bp->max_energy) {
+			bp->max_energy_bat = bp->bat;
+			bp->max_energy = bp->full.intval;
 		}
 	}
+	return 0;
+}
+
+static void find_main_battery(void)
+{
+	struct find_bat_param bp;
+	int error;
+
+	memset(&bp, 0, sizeof(struct find_bat_param));
+	main_battery = NULL;
+	bp.main = main_battery;
+
+	error = class_for_each_device(power_supply_class, &bp,
+				      __find_main_battery);
+	if (error) {
+		main_battery = bp.main;
+		return;
+	}
 
-	if ((max_energy_bat && max_charge_bat) &&
-			(max_energy_bat != max_charge_bat)) {
+	if ((bp.max_energy_bat && bp.max_charge_bat) &&
+			(bp.max_energy_bat != bp.max_charge_bat)) {
 		/* try guess battery with more capacity */
-		if (!PSY_PROP(max_charge_bat, VOLTAGE_MAX_DESIGN, &full)) {
-			if (max_energy > max_charge * full.intval)
-				main_battery = max_energy_bat;
+		if (!PSY_PROP(bp.max_charge_bat, VOLTAGE_MAX_DESIGN,
+			      &bp.full)) {
+			if (bp.max_energy > bp.max_charge * bp.full.intval)
+				main_battery = bp.max_energy_bat;
 			else
-				main_battery = max_charge_bat;
-		} else if (!PSY_PROP(max_energy_bat, VOLTAGE_MAX_DESIGN,
-								  &full)) {
-			if (max_charge > max_energy / full.intval)
-				main_battery = max_charge_bat;
+				main_battery = bp.max_charge_bat;
+		} else if (!PSY_PROP(bp.max_energy_bat, VOLTAGE_MAX_DESIGN,
+								  &bp.full)) {
+			if (bp.max_charge > bp.max_energy / bp.full.intval)
+				main_battery = bp.max_charge_bat;
 			else
-				main_battery = max_energy_bat;
+				main_battery = bp.max_energy_bat;
 		} else {
 			/* give up, choice any */
-			main_battery = max_energy_bat;
+			main_battery = bp.max_energy_bat;
 		}
-	} else if (max_charge_bat) {
-		main_battery = max_charge_bat;
-	} else if (max_energy_bat) {
-		main_battery = max_energy_bat;
+	} else if (bp.max_charge_bat) {
+		main_battery = bp.max_charge_bat;
+	} else if (bp.max_energy_bat) {
+		main_battery = bp.max_energy_bat;
 	} else {
 		/* give up, try the last if any */
-		main_battery = bat;
+		main_battery = bp.bat;
 	}
 }
 
@@ -207,10 +227,10 @@ static void apm_battery_apm_get_power_status(struct apm_power_info *info)
 	union power_supply_propval status;
 	union power_supply_propval capacity, time_to_full, time_to_empty;
 
-	down(&power_supply_class->sem);
+	mutex_lock(&apm_mutex);
 	find_main_battery();
 	if (!main_battery) {
-		up(&power_supply_class->sem);
+		mutex_unlock(&apm_mutex);
 		return;
 	}
 
@@ -278,7 +298,7 @@ static void apm_battery_apm_get_power_status(struct apm_power_info *info)
 		}
 	}
 
-	up(&power_supply_class->sem);
+	mutex_unlock(&apm_mutex);
 }
 
 static int __init apm_battery_init(void)
drivers/power/power_supply_core.c +39 -35

99 lines not on this page · raw message

Signature · 1 line
1.5.3.8
#239 lore raw

PATCH 190/196 rtc: use class iteration api

In reply to Greg KH

From: Dave Young <[email protected]>

Convert to use the class iteration api.

---
 drivers/rtc/interface.c |   22 ++++++++++++----------
 1 files changed, 12 insertions(+), 10 deletions(-)
drivers/rtc/interface.c +12 -10
index f1e00ff..7e3ad4f 100644
@@ -251,20 +251,23 @@ void rtc_update_irq(struct rtc_device *rtc,
 }
 EXPORT_SYMBOL_GPL(rtc_update_irq);
 
+static int __rtc_match(struct device *dev, void *data)
+{
+	char *name = (char *)data;
+
+	if (strncmp(dev->bus_id, name, BUS_ID_SIZE) == 0)
+		return 1;
+	return 0;
+}
+
 struct rtc_device *rtc_class_open(char *name)
 {
 	struct device *dev;
 	struct rtc_device *rtc = NULL;
 
-	down(&rtc_class->sem);
-	list_for_each_entry(dev, &rtc_class->devices, node) {
-		if (strncmp(dev->bus_id, name, BUS_ID_SIZE) == 0) {
-			dev = get_device(dev);
-			if (dev)
-				rtc = to_rtc_device(dev);
-			break;
-		}
-	}
+	dev = class_find_device(rtc_class, name, __rtc_match);
+	if (dev)
+		rtc = to_rtc_device(dev);
 
 	if (rtc) {
 		if (!try_module_get(rtc->owner)) {
@@ -272,7 +275,6 @@ struct rtc_device *rtc_class_open(char *name)
 			rtc = NULL;
 		}
 	}
-	up(&rtc_class->sem);
 
 	return rtc;
 }
Signature · 1 line
1.5.3.8
#240 lore raw

PATCH 191/196 scsi: use class iteration api

In reply to Greg KH

From: Dave Young <[email protected]>

Convert to use the class iteration api.

---
 drivers/scsi/hosts.c |   24 +++++++++++++-----------
 1 files changed, 13 insertions(+), 11 deletions(-)
drivers/scsi/hosts.c +13 -11
index 24271a8..6325115 100644
@@ -429,6 +429,15 @@ void scsi_unregister(struct Scsi_Host *shost)
 }
 EXPORT_SYMBOL(scsi_unregister);
 
+static int __scsi_host_match(struct class_device *cdev, void *data)
+{
+	struct Scsi_Host *p;
+	unsigned short *hostnum = (unsigned short *)data;
+
+	p = class_to_shost(cdev);
+	return p->host_no == *hostnum;
+}
+
 /**
  * scsi_host_lookup - get a reference to a Scsi_Host by host no
  *
@@ -439,19 +448,12 @@ EXPORT_SYMBOL(scsi_unregister);
  **/
 struct Scsi_Host *scsi_host_lookup(unsigned short hostnum)
 {
-	struct class *class = &shost_class;
 	struct class_device *cdev;
-	struct Scsi_Host *shost = ERR_PTR(-ENXIO), *p;
+	struct Scsi_Host *shost = ERR_PTR(-ENXIO);
 
-	down(&class->sem);
-	list_for_each_entry(cdev, &class->children, node) {
-		p = class_to_shost(cdev);
-		if (p->host_no == hostnum) {
-			shost = scsi_host_get(p);
-			break;
-		}
-	}
-	up(&class->sem);
+	cdev = class_find_child(&shost_class, &hostnum, __scsi_host_match);
+	if (cdev)
+		shost = scsi_host_get(class_to_shost(cdev));
 
 	return shost;
 }
Signature · 1 line
1.5.3.8
#242 lore raw

PATCH 192/196 spi: use class iteration api

In reply to Greg KH

From: Dave Young <[email protected]>

Convert to use the class iteration api.

---
 drivers/spi/spi.c |   26 +++++++++++++++-----------
 1 files changed, 15 insertions(+), 11 deletions(-)
drivers/spi/spi.c +15 -11
index 93e9de4..682a6a4 100644
@@ -485,6 +485,15 @@ void spi_unregister_master(struct spi_master *master)
 }
 EXPORT_SYMBOL_GPL(spi_unregister_master);
 
+static int __spi_master_match(struct device *dev, void *data)
+{
+	struct spi_master *m;
+	u16 *bus_num = data;
+
+	m = container_of(dev, struct spi_master, dev);
+	return m->bus_num == *bus_num;
+}
+
 /**
  * spi_busnum_to_master - look up master associated with bus_num
  * @bus_num: the master's bus number
@@ -499,17 +508,12 @@ struct spi_master *spi_busnum_to_master(u16 bus_num)
 {
 	struct device		*dev;
 	struct spi_master	*master = NULL;
-	struct spi_master	*m;
-
-	down(&spi_master_class.sem);
-	list_for_each_entry(dev, &spi_master_class.children, node) {
-		m = container_of(dev, struct spi_master, dev);
-		if (m->bus_num == bus_num) {
-			master = spi_master_get(m);
-			break;
-		}
-	}
-	up(&spi_master_class.sem);
+
+	dev = class_find_device(&spi_master_class, &bus_num,
+				__spi_master_match);
+	if (dev)
+		master = container_of(dev, struct spi_master, dev);
+	/* reference got in class_find_device */
 	return master;
 }
 EXPORT_SYMBOL_GPL(spi_busnum_to_master);
Signature · 1 line
1.5.3.8
#243 lore raw

PATCH 193/196 Driver core: fix coding style issues in device.h

In reply to Greg KH

Finally clean up the odd spaces and other mess in device.h

---
 include/linux/device.h |  283 +++++++++++++++++++++++++-----------------------
 1 files changed, 145 insertions(+), 138 deletions(-)
include/linux/device.h +145 -138
index cdaf57b..1880208 100644
@@ -25,7 +25,8 @@
 #include <asm/device.h>
 
 #define DEVICE_NAME_SIZE	50
-#define DEVICE_NAME_HALF	__stringify(20)	/* Less than half to accommodate slop */
+/* DEVICE_NAME_HALF is really less than half to accommodate slop */
+#define DEVICE_NAME_HALF	__stringify(20)
 #define DEVICE_ID_SIZE		32
 #define BUS_ID_SIZE		KOBJ_NAME_LEN
 
@@ -40,52 +41,53 @@ struct bus_type_private;
 
 struct bus_attribute {
 	struct attribute	attr;
-	ssize_t (*show)(struct bus_type *, char * buf);
-	ssize_t (*store)(struct bus_type *, const char * buf, size_t count);
+	ssize_t (*show)(struct bus_type *bus, char *buf);
+	ssize_t (*store)(struct bus_type *bus, const char *buf, size_t count);
 };
 
-#define BUS_ATTR(_name,_mode,_show,_store)	\
-struct bus_attribute bus_attr_##_name = __ATTR(_name,_mode,_show,_store)
+#define BUS_ATTR(_name, _mode, _show, _store)	\
+struct bus_attribute bus_attr_##_name = __ATTR(_name, _mode, _show, _store)
 
 extern int __must_check bus_create_file(struct bus_type *,
 					struct bus_attribute *);
 extern void bus_remove_file(struct bus_type *, struct bus_attribute *);
 
 struct bus_type {
-	const char		* name;
-	struct bus_attribute	* bus_attrs;
-	struct device_attribute	* dev_attrs;
-	struct driver_attribute	* drv_attrs;
-
-	int		(*match)(struct device * dev, struct device_driver * drv);
-	int		(*uevent)(struct device *dev, struct kobj_uevent_env *env);
-	int		(*probe)(struct device * dev);
-	int		(*remove)(struct device * dev);
-	void		(*shutdown)(struct device * dev);
-
-	int (*suspend)(struct device * dev, pm_message_t state);
-	int (*suspend_late)(struct device * dev, pm_message_t state);
-	int (*resume_early)(struct device * dev);
-	int (*resume)(struct device * dev);
+	const char		*name;
+	struct bus_attribute	*bus_attrs;
+	struct device_attribute	*dev_attrs;
+	struct driver_attribute	*drv_attrs;
+
+	int (*match)(struct device *dev, struct device_driver *drv);
+	int (*uevent)(struct device *dev, struct kobj_uevent_env *env);
+	int (*probe)(struct device *dev);
+	int (*remove)(struct device *dev);
+	void (*shutdown)(struct device *dev);
+
+	int (*suspend)(struct device *dev, pm_message_t state);
+	int (*suspend_late)(struct device *dev, pm_message_t state);
+	int (*resume_early)(struct device *dev);
+	int (*resume)(struct device *dev);
 
 	struct bus_type_private *p;
 };
 
-extern int __must_check bus_register(struct bus_type * bus);
-extern void bus_unregister(struct bus_type * bus);
+extern int __must_check bus_register(struct bus_type *bus);
+extern void bus_unregister(struct bus_type *bus);
 
-extern int __must_check bus_rescan_devices(struct bus_type * bus);
+extern int __must_check bus_rescan_devices(struct bus_type *bus);
 
 /* iterator helpers for buses */
 
-int bus_for_each_dev(struct bus_type * bus, struct device * start, void * data,
-		     int (*fn)(struct device *, void *));
-struct device * bus_find_device(struct bus_type *bus, struct device *start,
-				void *data, int (*match)(struct device *, void *));
+int bus_for_each_dev(struct bus_type *bus, struct device *start, void *data,
+		     int (*fn)(struct device *dev, void *data));
+struct device *bus_find_device(struct bus_type *bus, struct device *start,
+			       void *data,
+			       int (*match)(struct device *dev, void *data));
 
 int __must_check bus_for_each_drv(struct bus_type *bus,
-		struct device_driver *start, void *data,
-		int (*fn)(struct device_driver *, void *));
+				  struct device_driver *start, void *data,
+				  int (*fn)(struct device_driver *, void *));
 
 /*
  * Bus notifiers: Get notified of addition/removal of devices
@@ -120,57 +122,63 @@ struct device_driver {
 	struct module		*owner;
 	const char 		*mod_name;	/* used for built-in modules */
 
-	int	(*probe)	(struct device * dev);
-	int	(*remove)	(struct device * dev);
-	void	(*shutdown)	(struct device * dev);
-	int	(*suspend)	(struct device * dev, pm_message_t state);
-	int	(*resume)	(struct device * dev);
+	int (*probe) (struct device *dev);
+	int (*remove) (struct device *dev);
+	void (*shutdown) (struct device *dev);
+	int (*suspend) (struct device *dev, pm_message_t state);
+	int (*resume) (struct device *dev);
 	struct attribute_group **groups;
 
 	struct driver_private *p;
 };
 
 
-extern int __must_check driver_register(struct device_driver * drv);
-extern void driver_unregister(struct device_driver * drv);
+extern int __must_check driver_register(struct device_driver *drv);
+extern void driver_unregister(struct device_driver *drv);
 
-extern struct device_driver * get_driver(struct device_driver * drv);
-extern void put_driver(struct device_driver * drv);
-extern struct device_driver *driver_find(const char *name, struct bus_type *bus);
+extern struct device_driver *get_driver(struct device_driver *drv);
+extern void put_driver(struct device_driver *drv);
+extern struct device_driver *driver_find(const char *name,
+					 struct bus_type *bus);
 extern int driver_probe_done(void);
 
 /* sysfs interface for exporting driver attributes */
 
 struct driver_attribute {
-	struct attribute	attr;
-	ssize_t (*show)(struct device_driver *, char * buf);
-	ssize_t (*store)(struct device_driver *, const char * buf, size_t count);
+	struct attribute attr;
+	ssize_t (*show)(struct device_driver *driver, char *buf);
+	ssize_t (*store)(struct device_driver *driver, const char *buf,
+			 size_t count);
 };
 
-#define DRIVER_ATTR(_name,_mode,_show,_store)	\
-struct driver_attribute driver_attr_##_name = __ATTR(_name,_mode,_show,_store)
+#define DRIVER_ATTR(_name, _mode, _show, _store)	\
+struct driver_attribute driver_attr_##_name =		\
+	__ATTR(_name, _mode, _show, _store)
 
-extern int __must_check driver_create_file(struct device_driver *,
-					struct driver_attribute *);
-extern void driver_remove_file(struct device_driver *, struct driver_attribute *);
+extern int __must_check driver_create_file(struct device_driver *driver,
+					   struct driver_attribute *attr);
+extern void driver_remove_file(struct device_driver *driver,
+			       struct driver_attribute *attr);
 
 extern int __must_check driver_add_kobj(struct device_driver *drv,
 					struct kobject *kobj,
 					const char *fmt, ...);
 
-extern int __must_check driver_for_each_device(struct device_driver * drv,
-		struct device *start, void *data,
-		int (*fn)(struct device *, void *));
-struct device * driver_find_device(struct device_driver *drv,
-				   struct device *start, void *data,
-				   int (*match)(struct device *, void *));
+extern int __must_check driver_for_each_device(struct device_driver *drv,
+					       struct device *start,
+					       void *data,
+					       int (*fn)(struct device *dev,
+							 void *));
+struct device *driver_find_device(struct device_driver *drv,
+				  struct device *start, void *data,
+				  int (*match)(struct device *dev, void *data));
 
 /*
  * device classes
  */
 struct class {
-	const char		* name;
-	struct module		* owner;
+	const char		*name;
+	struct module		*owner;
 
 	struct kset		subsys;
 	struct list_head	children;
@@ -178,23 +186,23 @@ struct class {
 	struct list_head	interfaces;
 	struct kset		class_dirs;
 	struct semaphore	sem; /* locks children, devices, interfaces */
-	struct class_attribute		* class_attrs;
-	struct class_device_attribute	* class_dev_attrs;
-	struct device_attribute		* dev_attrs;
+	struct class_attribute		*class_attrs;
+	struct class_device_attribute	*class_dev_attrs;
+	struct device_attribute		*dev_attrs;
 
-	int	(*uevent)(struct class_device *dev, struct kobj_uevent_env *env);
-	int	(*dev_uevent)(struct device *dev, struct kobj_uevent_env *env);
+	int (*uevent)(struct class_device *dev, struct kobj_uevent_env *env);
+	int (*dev_uevent)(struct device *dev, struct kobj_uevent_env *env);
 
-	void	(*release)(struct class_device *dev);
-	void	(*class_release)(struct class *class);
-	void	(*dev_release)(struct device *dev);
+	void (*release)(struct class_device *dev);
+	void (*class_release)(struct class *class);
+	void (*dev_release)(struct device *dev);
 
-	int	(*suspend)(struct device *, pm_message_t state);
-	int	(*resume)(struct device *);
+	int (*suspend)(struct device *dev, pm_message_t state);
+	int (*resume)(struct device *dev);
 };
 
-extern int __must_check class_register(struct class *);
-extern void class_unregister(struct class *);
+extern int __must_check class_register(struct class *class);
+extern void class_unregister(struct class *class);
 extern int class_for_each_device(struct class *class, void *data,
 				 int (*fn)(struct device *dev, void *data));
 extern struct device *class_find_device(struct class *class, void *data,
@@ -204,27 +212,28 @@ extern struct class_device *class_find_child(struct class *class, void *data,
 
 
 struct class_attribute {
-	struct attribute	attr;
-	ssize_t (*show)(struct class *, char * buf);
-	ssize_t (*store)(struct class *, const char * buf, size_t count);
+	struct attribute attr;
+	ssize_t (*show)(struct class *class, char *buf);
+	ssize_t (*store)(struct class *class, const char *buf, size_t count);
 };
 
-#define CLASS_ATTR(_name,_mode,_show,_store)			\
-struct class_attribute class_attr_##_name = __ATTR(_name,_mode,_show,_store) 
+#define CLASS_ATTR(_name, _mode, _show, _store)			\
+struct class_attribute class_attr_##_name = __ATTR(_name, _mode, _show, _store)
 
-extern int __must_check class_create_file(struct class *,
-					const struct class_attribute *);
-extern void class_remove_file(struct class *, const struct class_attribute *);
+extern int __must_check class_create_file(struct class *class,
+					  const struct class_attribute *attr);
+extern void class_remove_file(struct class *class,
+			      const struct class_attribute *attr);
 
 struct class_device_attribute {
-	struct attribute	attr;
-	ssize_t (*show)(struct class_device *, char * buf);
-	ssize_t (*store)(struct class_device *, const char * buf, size_t count);
+	struct attribute attr;
+	ssize_t (*show)(struct class_device *, char *buf);
+	ssize_t (*store)(struct class_device *, const char *buf, size_t count);
 };
 
-#define CLASS_DEVICE_ATTR(_name,_mode,_show,_store)		\
+#define CLASS_DEVICE_ATTR(_name, _mode, _show, _store)		\
 struct class_device_attribute class_device_attr_##_name = 	\
-	__ATTR(_name,_mode,_show,_store)
+	__ATTR(_name, _mode, _show, _store)
 
 extern int __must_check class_device_create_file(struct class_device *,
 				    const struct class_device_attribute *);
@@ -257,26 +266,24 @@ struct class_device {
 	struct list_head	node;
 
 	struct kobject		kobj;
-	struct class		* class;	/* required */
-	dev_t			devt;		/* dev_t, creates the sysfs "dev" */
-	struct device		* dev;		/* not necessary, but nice to have */
-	void			* class_data;	/* class-specific data */
-	struct class_device	*parent;	/* parent of this child device, if there is one */
-	struct attribute_group  ** groups;	/* optional groups */
-
-	void	(*release)(struct class_device *dev);
-	int	(*uevent)(struct class_device *dev, struct kobj_uevent_env *env);
-	char	class_id[BUS_ID_SIZE];	/* unique to this class */
+	struct class		*class;
+	dev_t			devt;
+	struct device		*dev;
+	void			*class_data;
+	struct class_device	*parent;
+	struct attribute_group  **groups;
+
+	void (*release)(struct class_device *dev);
+	int (*uevent)(struct class_device *dev, struct kobj_uevent_env *env);
+	char class_id[BUS_ID_SIZE];
 };
 
-static inline void *
-class_get_devdata (struct class_device *dev)
+static inline void *class_get_devdata(struct class_device *dev)
 {
 	return dev->class_data;
 }
 
-static inline void
-class_set_devdata (struct class_device *dev, void *data)
+static inline void class_set_devdata(struct class_device *dev, void *data)
 {
 	dev->class_data = data;
 }
@@ -288,10 +295,10 @@ extern void class_device_initialize(struct class_device *);
 extern int __must_check class_device_add(struct class_device *);
 extern void class_device_del(struct class_device *);
 
-extern struct class_device * class_device_get(struct class_device *);
+extern struct class_device *class_device_get(struct class_device *);
 extern void class_device_put(struct class_device *);
 
-extern void class_device_remove_file(struct class_device *, 
+extern void class_device_remove_file(struct class_device *,
 				     const struct class_device_attribute *);
 extern int __must_check class_device_create_bin_file(struct class_device *,
 					struct bin_attribute *);
@@ -318,7 +325,7 @@ extern struct class_device *class_device_create(struct class *cls,
 						dev_t devt,
 						struct device *device,
 						const char *fmt, ...)
-					__attribute__((format(printf,5,6)));
+					__attribute__((format(printf, 5, 6)));
 extern void class_device_destroy(struct class *cls, dev_t devt);
 
 /*
@@ -335,8 +342,8 @@ struct device_type {
 	struct attribute_group **groups;
 	int (*uevent)(struct device *dev, struct kobj_uevent_env *env);
 	void (*release)(struct device *dev);
-	int (*suspend)(struct device * dev, pm_message_t state);
-	int (*resume)(struct device * dev);
+	int (*suspend)(struct device *dev, pm_message_t state);
+	int (*resume)(struct device *dev);
 };
 
 /* interface for exporting device attributes */
@@ -348,18 +355,19 @@ struct device_attribute {
 			 const char *buf, size_t count);
 };
 
-#define DEVICE_ATTR(_name,_mode,_show,_store) \
-struct device_attribute dev_attr_##_name = __ATTR(_name,_mode,_show,_store)
+#define DEVICE_ATTR(_name, _mode, _show, _store) \
+struct device_attribute dev_attr_##_name = __ATTR(_name, _mode, _show, _store)
 
 extern int __must_check device_create_file(struct device *device,
-					struct device_attribute * entry);
-extern void device_remove_file(struct device * dev, struct device_attribute * attr);
+					   struct device_attribute *entry);
+extern void device_remove_file(struct device *dev,
+			       struct device_attribute *attr);
 extern int __must_check device_create_bin_file(struct device *dev,
 					       struct bin_attribute *attr);
 extern void device_remove_bin_file(struct device *dev,
 				   struct bin_attribute *attr);
 extern int device_schedule_callback_owner(struct device *dev,
-		void (*func)(struct device *), struct module *owner);
+		void (*func)(struct device *dev), struct module *owner);
 
 /* This is a macro to avoid include problems with THIS_MODULE */
 #define device_schedule_callback(dev, func)			\
@@ -370,21 +378,21 @@ typedef void (*dr_release_t)(struct device *dev, void *res);
 typedef int (*dr_match_t)(struct device *dev, void *res, void *match_data);
 
 #ifdef CONFIG_DEBUG_DEVRES
-extern void * __devres_alloc(dr_release_t release, size_t size, gfp_t gfp,
+extern void *__devres_alloc(dr_release_t release, size_t size, gfp_t gfp,
 			     const char *name);
 #define devres_alloc(release, size, gfp) \
 	__devres_alloc(release, size, gfp, #release)
 #else
-extern void * devres_alloc(dr_release_t release, size_t size, gfp_t gfp);
+extern void *devres_alloc(dr_release_t release, size_t size, gfp_t gfp);
 #endif
 extern void devres_free(void *res);
 extern void devres_add(struct device *dev, void *res);
-extern void * devres_find(struct device *dev, dr_release_t release,
-			  dr_match_t match, void *match_data);
-extern void * devres_get(struct device *dev, void *new_res,
+extern void *devres_find(struct device *dev, dr_release_t release,
 			 dr_match_t match, void *match_data);
-extern void * devres_remove(struct device *dev, dr_release_t release,
-			    dr_match_t match, void *match_data);
+extern void *devres_get(struct device *dev, void *new_res,
+			dr_match_t match, void *match_data);
+extern void *devres_remove(struct device *dev, dr_release_t release,
+			   dr_match_t match, void *match_data);
 extern int devres_destroy(struct device *dev, dr_release_t release,
 			  dr_match_t match, void *match_data);
 
@@ -401,7 +409,7 @@ extern void devm_kfree(struct device *dev, void *p);
 
 struct device {
 	struct klist		klist_children;
-	struct klist_node	knode_parent;		/* node in sibling list */
+	struct klist_node	knode_parent;	/* node in sibling list */
 	struct klist_node	knode_driver;
 	struct klist_node	knode_bus;
 	struct device		*parent;
@@ -416,7 +424,7 @@ struct device {
 					 * its driver.
 					 */
 
-	struct bus_type	* bus;		/* type of bus device is on */
+	struct bus_type	*bus;		/* type of bus device is on */
 	struct device_driver *driver;	/* which driver has allocated this
 					   device */
 	void		*driver_data;	/* data private to the driver */
@@ -447,10 +455,10 @@ struct device {
 	/* class_device migration path */
 	struct list_head	node;
 	struct class		*class;
-	dev_t			devt;		/* dev_t, creates the sysfs "dev" */
+	dev_t			devt;	/* dev_t, creates the sysfs "dev" */
 	struct attribute_group	**groups;	/* optional groups */
 
-	void	(*release)(struct device * dev);
+	void	(*release)(struct device *dev);
 };
 
 #ifdef CONFIG_NUMA
@@ -472,14 +480,12 @@ static inline void set_dev_node(struct device *dev, int node)
 }
 #endif
 
-static inline void *
-dev_get_drvdata (struct device *dev)
+static inline void *dev_get_drvdata(struct device *dev)
 {
 	return dev->driver_data;
 }
 
-static inline void
-dev_set_drvdata (struct device *dev, void *data)
+static inline void dev_set_drvdata(struct device *dev, void *data)
 {
 	dev->driver_data = data;
 }
@@ -494,15 +500,15 @@ void driver_init(void);
 /*
  * High level routines for use by the bus drivers
  */
-extern int __must_check device_register(struct device * dev);
-extern void device_unregister(struct device * dev);
-extern void device_initialize(struct device * dev);
-extern int __must_check device_add(struct device * dev);
-extern void device_del(struct device * dev);
-extern int device_for_each_child(struct device *, void *,
-		     int (*fn)(struct device *, void *));
-extern struct device *device_find_child(struct device *, void *data,
-					int (*match)(struct device *, void *));
+extern int __must_check device_register(struct device *dev);
+extern void device_unregister(struct device *dev);
+extern void device_initialize(struct device *dev);
+extern int __must_check device_add(struct device *dev);
+extern void device_del(struct device *dev);
+extern int device_for_each_child(struct device *dev, void *data,
+		     int (*fn)(struct device *dev, void *data));
+extern struct device *device_find_child(struct device *dev, void *data,
+				int (*match)(struct device *dev, void *data));
 extern int device_rename(struct device *dev, char *new_name);
 extern int device_move(struct device *dev, struct device *new_parent);
 
@@ -511,8 +517,8 @@ extern int device_move(struct device *dev, struct device *new_parent);
  * for information on use.
  */
 extern int __must_check device_bind_driver(struct device *dev);
-extern void device_release_driver(struct device * dev);
-extern int  __must_check device_attach(struct device * dev);
+extern void device_release_driver(struct device *dev);
+extern int  __must_check device_attach(struct device *dev);
 extern int __must_check driver_attach(struct device_driver *drv);
 extern int __must_check device_reprobe(struct device *dev);
 
@@ -521,7 +527,7 @@ extern int __must_check device_reprobe(struct device *dev);
  */
 extern struct device *device_create(struct class *cls, struct device *parent,
 				    dev_t devt, const char *fmt, ...)
-				    __attribute__((format(printf,4,5)));
+				    __attribute__((format(printf, 4, 5)));
 extern void device_destroy(struct class *cls, dev_t devt);
 #ifdef CONFIG_PM_SLEEP
 extern void destroy_suspended_device(struct class *cls, dev_t devt);
@@ -538,17 +544,17 @@ static inline void destroy_suspended_device(struct class *cls, dev_t devt)
  * know about.
  */
 /* Notify platform of device discovery */
-extern int (*platform_notify)(struct device * dev);
+extern int (*platform_notify)(struct device *dev);
 
-extern int (*platform_notify_remove)(struct device * dev);
+extern int (*platform_notify_remove)(struct device *dev);
 
 
 /**
  * get_device - atomically increment the reference count for the device.
  *
  */
-extern struct device * get_device(struct device * dev);
-extern void put_device(struct device * dev);
+extern struct device *get_device(struct device *dev);
+extern void put_device(struct device *dev);
 
 
 /* drivers/base/power/shutdown.c */
@@ -560,7 +566,8 @@ extern void sysdev_shutdown(void);
 /* debugging and troubleshooting/diagnostic helpers. */
 extern const char *dev_driver_string(struct device *dev);
 #define dev_printk(level, dev, format, arg...)	\
-	printk(level "%s %s: " format , dev_driver_string(dev) , (dev)->bus_id , ## arg)
+	printk(level "%s %s: " format , dev_driver_string(dev) , \
+	       (dev)->bus_id , ## arg)
 
 #define dev_emerg(dev, format, arg...)		\
 	dev_printk(KERN_EMERG , dev , format , ## arg)
@@ -582,7 +589,7 @@ extern const char *dev_driver_string(struct device *dev);
 	dev_printk(KERN_DEBUG , dev , format , ## arg)
 #else
 static inline int __attribute__ ((format (printf, 2, 3)))
-dev_dbg(struct device * dev, const char * fmt, ...)
+dev_dbg(struct device *dev, const char *fmt, ...)
 {
 	return 0;
 }
@@ -592,7 +599,7 @@ dev_dbg(struct device * dev, const char * fmt, ...)
 #define dev_vdbg	dev_dbg
 #else
 static inline int __attribute__ ((format (printf, 2, 3)))
-dev_vdbg(struct device * dev, const char * fmt, ...)
+dev_vdbg(struct device *dev, const char *fmt, ...)
 {
 	return 0;
 }
Signature · 1 line
1.5.3.8
#244 lore raw

PATCH 194/196 Kobject: fix coding style issues in kobject.h

In reply to Greg KH

Finally clean up the odd spaces and other mess in kobject.h

---
 include/linux/kobject.h |   67 ++++++++++++++++++++++++-----------------------
 1 files changed, 34 insertions(+), 33 deletions(-)
include/linux/kobject.h +34 -33
index 4adbe1d..caa3f41 100644
@@ -3,15 +3,14 @@
  *
  * Copyright (c) 2002-2003 Patrick Mochel
  * Copyright (c) 2002-2003 Open Source Development Labs
- * Copyright (c) 2006-2007 Greg Kroah-Hartman <[email protected]>
- * Copyright (c) 2006-2007 Novell Inc.
+ * Copyright (c) 2006-2008 Greg Kroah-Hartman <[email protected]>
+ * Copyright (c) 2006-2008 Novell Inc.
  *
  * This file is released under the GPLv2.
  *
- * 
  * Please read Documentation/kobject.txt before using the kobject
  * interface, ESPECIALLY the parts about reference counts and object
- * destructors. 
+ * destructors.
  */
 
 #ifndef _KOBJECT_H_
@@ -64,20 +63,20 @@ struct kobject {
 	const char		*name;
 	struct kref		kref;
 	struct list_head	entry;
-	struct kobject		* parent;
-	struct kset		* kset;
-	struct kobj_type	* ktype;
-	struct sysfs_dirent	* sd;
+	struct kobject		*parent;
+	struct kset		*kset;
+	struct kobj_type	*ktype;
+	struct sysfs_dirent	*sd;
 	unsigned int state_initialized:1;
 	unsigned int state_in_sysfs:1;
 	unsigned int state_add_uevent_sent:1;
 	unsigned int state_remove_uevent_sent:1;
 };
 
-extern int kobject_set_name(struct kobject *, const char *, ...)
-	__attribute__((format(printf,2,3)));
+extern int kobject_set_name(struct kobject *kobj, const char *name, ...)
+			    __attribute__((format(printf, 2, 3)));
 
-static inline const char * kobject_name(const struct kobject * kobj)
+static inline const char *kobject_name(const struct kobject *kobj)
 {
 	return kobj->name;
 }
@@ -91,7 +90,7 @@ extern int __must_check kobject_init_and_add(struct kobject *kobj,
 					     struct kobject *parent,
 					     const char *fmt, ...);
 
-extern void kobject_del(struct kobject *);
+extern void kobject_del(struct kobject *kobj);
 
 extern struct kobject * __must_check kobject_create(void);
 extern struct kobject * __must_check kobject_create_and_add(const char *name,
@@ -100,15 +99,15 @@ extern struct kobject * __must_check kobject_create_and_add(const char *name,
 extern int __must_check kobject_rename(struct kobject *, const char *new_name);
 extern int __must_check kobject_move(struct kobject *, struct kobject *);
 
-extern struct kobject * kobject_get(struct kobject *);
-extern void kobject_put(struct kobject *);
+extern struct kobject *kobject_get(struct kobject *kobj);
+extern void kobject_put(struct kobject *kobj);
 
-extern char * kobject_get_path(struct kobject *, gfp_t);
+extern char *kobject_get_path(struct kobject *kobj, gfp_t flag);
 
 struct kobj_type {
-	void (*release)(struct kobject *);
-	struct sysfs_ops	* sysfs_ops;
-	struct attribute	** default_attrs;
+	void (*release)(struct kobject *kobj);
+	struct sysfs_ops *sysfs_ops;
+	struct attribute **default_attrs;
 };
 
 struct kobj_uevent_env {
@@ -153,30 +152,30 @@ extern struct sysfs_ops kobj_sysfs_ops;
  * desired.
  */
 struct kset {
-	struct list_head	list;
-	spinlock_t		list_lock;
-	struct kobject		kobj;
-	struct kset_uevent_ops	*uevent_ops;
+	struct list_head list;
+	spinlock_t list_lock;
+	struct kobject kobj;
+	struct kset_uevent_ops *uevent_ops;
 };
 
-extern void kset_init(struct kset * k);
-extern int __must_check kset_register(struct kset * k);
-extern void kset_unregister(struct kset * k);
+extern void kset_init(struct kset *kset);
+extern int __must_check kset_register(struct kset *kset);
+extern void kset_unregister(struct kset *kset);
 extern struct kset * __must_check kset_create_and_add(const char *name,
 						struct kset_uevent_ops *u,
 						struct kobject *parent_kobj);
 
-static inline struct kset * to_kset(struct kobject * kobj)
+static inline struct kset *to_kset(struct kobject *kobj)
 {
-	return kobj ? container_of(kobj,struct kset,kobj) : NULL;
+	return kobj ? container_of(kobj, struct kset, kobj) : NULL;
 }
 
-static inline struct kset * kset_get(struct kset * k)
+static inline struct kset *kset_get(struct kset *k)
 {
 	return k ? to_kset(kobject_get(&k->kobj)) : NULL;
 }
 
-static inline void kset_put(struct kset * k)
+static inline void kset_put(struct kset *k)
 {
 	kobject_put(&k->kobj);
 }
@@ -186,7 +185,7 @@ static inline struct kobj_type *get_ktype(struct kobject *kobj)
 	return kobj->ktype;
 }
 
-extern struct kobject * kset_find_obj(struct kset *, const char *);
+extern struct kobject *kset_find_obj(struct kset *, const char *);
 
 /* The global /sys/kernel/ kobject for people to chain off of */
 extern struct kobject *kernel_kobj;
@@ -208,18 +207,20 @@ int add_uevent_var(struct kobj_uevent_env *env, const char *format, ...)
 int kobject_action_type(const char *buf, size_t count,
 			enum kobject_action *type);
 #else
-static inline int kobject_uevent(struct kobject *kobj, enum kobject_action action)
+static inline int kobject_uevent(struct kobject *kobj,
+				 enum kobject_action action)
 { return 0; }
 static inline int kobject_uevent_env(struct kobject *kobj,
 				      enum kobject_action action,
 				      char *envp[])
 { return 0; }
 
-static inline int add_uevent_var(struct kobj_uevent_env *env, const char *format, ...)
+static inline int add_uevent_var(struct kobj_uevent_env *env,
+				 const char *format, ...)
 { return 0; }
 
 static inline int kobject_action_type(const char *buf, size_t count,
-			enum kobject_action *type)
+				      enum kobject_action *type)
 { return -EINVAL; }
 #endif
 
Signature · 1 line
1.5.3.8
#245 lore raw

PATCH 195/196 Kobject: fix coding style issues in kobject c files

In reply to Greg KH

Clean up the kobject.c and kobject_uevent.c files to follow the proper coding style rules.

---
 lib/kobject.c        |  139 +++++++++++++++++++++++---------------------------
 lib/kobject_uevent.c |    7 +--
 2 files changed, 67 insertions(+), 79 deletions(-)
lib/kobject.c +64 -75
index 8dc3245..1d63ead 100644
@@ -18,58 +18,57 @@
 #include <linux/stat.h>
 #include <linux/slab.h>
 
-/**
- *	populate_dir - populate directory with attributes.
- *	@kobj:	object we're working on.
- *
- *	Most subsystems have a set of default attributes that 
- *	are associated with an object that registers with them.
- *	This is a helper called during object registration that 
- *	loops through the default attributes of the subsystem 
- *	and creates attributes files for them in sysfs.
+/*
+ * populate_dir - populate directory with attributes.
+ * @kobj: object we're working on.
  *
+ * Most subsystems have a set of default attributes that are associated
+ * with an object that registers with them.  This is a helper called during
+ * object registration that loops through the default attributes of the
+ * subsystem and creates attributes files for them in sysfs.
  */
-
-static int populate_dir(struct kobject * kobj)
+static int populate_dir(struct kobject *kobj)
 {
-	struct kobj_type * t = get_ktype(kobj);
-	struct attribute * attr;
+	struct kobj_type *t = get_ktype(kobj);
+	struct attribute *attr;
 	int error = 0;
 	int i;
-	
+
 	if (t && t->default_attrs) {
 		for (i = 0; (attr = t->default_attrs[i]) != NULL; i++) {
-			if ((error = sysfs_create_file(kobj,attr)))
+			error = sysfs_create_file(kobj, attr);
+			if (error)
 				break;
 		}
 	}
 	return error;
 }
 
-static int create_dir(struct kobject * kobj)
+static int create_dir(struct kobject *kobj)
 {
 	int error = 0;
 	if (kobject_name(kobj)) {
 		error = sysfs_create_dir(kobj);
 		if (!error) {
-			if ((error = populate_dir(kobj)))
+			error = populate_dir(kobj);
+			if (error)
 				sysfs_remove_dir(kobj);
 		}
 	}
 	return error;
 }
 
-static inline struct kobject * to_kobj(struct list_head * entry)
+static inline struct kobject *to_kobj(struct list_head *entry)
 {
-	return container_of(entry,struct kobject,entry);
+	return container_of(entry, struct kobject, entry);
 }
 
 static int get_kobj_path_length(struct kobject *kobj)
 {
 	int length = 1;
-	struct kobject * parent = kobj;
+	struct kobject *parent = kobj;
 
-	/* walk up the ancestors until we hit the one pointing to the 
+	/* walk up the ancestors until we hit the one pointing to the
 	 * root.
 	 * Add 1 to strlen for leading '/' of each level.
 	 */
@@ -84,19 +83,19 @@ static int get_kobj_path_length(struct kobject *kobj)
 
 static void fill_kobj_path(struct kobject *kobj, char *path, int length)
 {
-	struct kobject * parent;
+	struct kobject *parent;
 
 	--length;
 	for (parent = kobj; parent; parent = parent->parent) {
 		int cur = strlen(kobject_name(parent));
 		/* back up enough to print this name with '/' */
 		length -= cur;
-		strncpy (path + length, kobject_name(parent), cur);
+		strncpy(path + length, kobject_name(parent), cur);
 		*(path + --length) = '/';
 	}
 
 	pr_debug("kobject: '%s' (%p): %s: path = '%s'\n", kobject_name(kobj),
-		 kobj, __FUNCTION__,path);
+		 kobj, __FUNCTION__, path);
 }
 
 /**
@@ -148,7 +147,7 @@ static void kobj_kset_leave(struct kobject *kobj)
 	kset_put(kobj->kset);
 }
 
-static void kobject_init_internal(struct kobject * kobj)
+static void kobject_init_internal(struct kobject *kobj)
 {
 	if (!kobj)
 		return;
@@ -160,7 +159,7 @@ static void kobject_init_internal(struct kobject * kobj)
 static int kobject_add_internal(struct kobject *kobj)
 {
 	int error = 0;
-	struct kobject * parent;
+	struct kobject *parent;
 
 	if (!kobj)
 		return -ENOENT;
@@ -185,7 +184,7 @@ static int kobject_add_internal(struct kobject *kobj)
 	pr_debug("kobject: '%s' (%p): %s: parent: '%s', set: '%s'\n",
 		 kobject_name(kobj), kobj, __FUNCTION__,
 		 parent ? kobject_name(parent) : "<NULL>",
-		 kobj->kset ? kobject_name(&kobj->kset->kobj) : "<NULL>" );
+		 kobj->kset ? kobject_name(&kobj->kset->kobj) : "<NULL>");
 
 	error = create_dir(kobj);
 	if (error) {
@@ -399,12 +398,11 @@ int kobject_init_and_add(struct kobject *kobj, struct kobj_type *ktype,
 EXPORT_SYMBOL_GPL(kobject_init_and_add);
 
 /**
- *	kobject_rename - change the name of an object
- *	@kobj:	object in question.
- *	@new_name: object's new name
+ * kobject_rename - change the name of an object
+ * @kobj: object in question.
+ * @new_name: object's new name
  */
-
-int kobject_rename(struct kobject * kobj, const char *new_name)
+int kobject_rename(struct kobject *kobj, const char *new_name)
 {
 	int error = 0;
 	const char *devpath = NULL;
@@ -461,11 +459,10 @@ out:
 }
 
 /**
- *	kobject_move - move object to another parent
- *	@kobj:	object in question.
- *	@new_parent: object's new parent (can be NULL)
+ * kobject_move - move object to another parent
+ * @kobj: object in question.
+ * @new_parent: object's new parent (can be NULL)
  */
-
 int kobject_move(struct kobject *kobj, struct kobject *new_parent)
 {
 	int error;
@@ -513,11 +510,10 @@ out:
 }
 
 /**
- *	kobject_del - unlink kobject from hierarchy.
- * 	@kobj:	object.
+ * kobject_del - unlink kobject from hierarchy.
+ * @kobj: object.
  */
-
-void kobject_del(struct kobject * kobj)
+void kobject_del(struct kobject *kobj)
 {
 	if (!kobj)
 		return;
@@ -530,11 +526,10 @@ void kobject_del(struct kobject * kobj)
 }
 
 /**
- *	kobject_get - increment refcount for object.
- *	@kobj:	object.
+ * kobject_get - increment refcount for object.
+ * @kobj: object.
  */
-
-struct kobject * kobject_get(struct kobject * kobj)
+struct kobject *kobject_get(struct kobject *kobj)
 {
 	if (kobj)
 		kref_get(&kobj->kref);
@@ -591,12 +586,12 @@ static void kobject_release(struct kref *kref)
 }
 
 /**
- *	kobject_put - decrement refcount for object.
- *	@kobj:	object.
+ * kobject_put - decrement refcount for object.
+ * @kobj: object.
  *
- *	Decrement the refcount, and if 0, call kobject_cleanup().
+ * Decrement the refcount, and if 0, call kobject_cleanup().
  */
-void kobject_put(struct kobject * kobj)
+void kobject_put(struct kobject *kobj)
 {
 	if (kobj)
 		kref_put(&kobj->kref, kobject_release);
@@ -670,11 +665,10 @@ struct kobject *kobject_create_and_add(const char *name, struct kobject *parent)
 EXPORT_SYMBOL_GPL(kobject_create_and_add);
 
 /**
- *	kset_init - initialize a kset for use
- *	@k:	kset 
+ * kset_init - initialize a kset for use
+ * @k: kset
  */
-
-void kset_init(struct kset * k)
+void kset_init(struct kset *k)
 {
 	kobject_init_internal(&k->kobj);
 	INIT_LIST_HEAD(&k->list);
@@ -712,11 +706,10 @@ struct sysfs_ops kobj_sysfs_ops = {
 };
 
 /**
- *	kset_register - initialize and add a kset.
- *	@k:	kset.
+ * kset_register - initialize and add a kset.
+ * @k: kset.
  */
-
-int kset_register(struct kset * k)
+int kset_register(struct kset *k)
 {
 	int err;
 
@@ -731,39 +724,35 @@ int kset_register(struct kset * k)
 	return 0;
 }
 
-
 /**
- *	kset_unregister - remove a kset.
- *	@k:	kset.
+ * kset_unregister - remove a kset.
+ * @k: kset.
  */
-
-void kset_unregister(struct kset * k)
+void kset_unregister(struct kset *k)
 {
 	if (!k)
 		return;
 	kobject_put(&k->kobj);
 }
 
-
 /**
- *	kset_find_obj - search for object in kset.
- *	@kset:	kset we're looking in.
- *	@name:	object's name.
+ * kset_find_obj - search for object in kset.
+ * @kset: kset we're looking in.
+ * @name: object's name.
  *
- *	Lock kset via @kset->subsys, and iterate over @kset->list,
- *	looking for a matching kobject. If matching object is found
- *	take a reference and return the object.
+ * Lock kset via @kset->subsys, and iterate over @kset->list,
+ * looking for a matching kobject. If matching object is found
+ * take a reference and return the object.
  */
-
-struct kobject * kset_find_obj(struct kset * kset, const char * name)
+struct kobject *kset_find_obj(struct kset *kset, const char *name)
 {
-	struct list_head * entry;
-	struct kobject * ret = NULL;
+	struct list_head *entry;
+	struct kobject *ret = NULL;
 
 	spin_lock(&kset->list_lock);
-	list_for_each(entry,&kset->list) {
-		struct kobject * k = to_kobj(entry);
-		if (kobject_name(k) && !strcmp(kobject_name(k),name)) {
+	list_for_each(entry, &kset->list) {
+		struct kobject *k = to_kobj(entry);
+		if (kobject_name(k) && !strcmp(kobject_name(k), name)) {
 			ret = kobject_get(k);
 			break;
 		}
lib/kobject_uevent.c +3 -4
index b021e67..5a402e2 100644
@@ -238,11 +238,12 @@ int kobject_uevent_env(struct kobject *kobj, enum kobject_action action,
 		retval = add_uevent_var(env, "HOME=/");
 		if (retval)
 			goto exit;
-		retval = add_uevent_var(env, "PATH=/sbin:/bin:/usr/sbin:/usr/bin");
+		retval = add_uevent_var(env,
+					"PATH=/sbin:/bin:/usr/sbin:/usr/bin");
 		if (retval)
 			goto exit;
 
-		call_usermodehelper (argv[0], argv, env->envp, UMH_WAIT_EXEC);
+		call_usermodehelper(argv[0], argv, env->envp, UMH_WAIT_EXEC);
 	}
 
 exit:
@@ -250,7 +251,6 @@ exit:
 	kfree(env);
 	return retval;
 }
-
 EXPORT_SYMBOL_GPL(kobject_uevent_env);
 
 /**
@@ -266,7 +266,6 @@ int kobject_uevent(struct kobject *kobj, enum kobject_action action)
 {
 	return kobject_uevent_env(kobj, action, NULL);
 }
-
 EXPORT_SYMBOL_GPL(kobject_uevent);
 
 /**
Signature · 1 line
1.5.3.8
#246 lore raw

PATCH 196/196 Driver core: coding style fixes

In reply to Greg KH

Fix up a number of coding style issues in the drivers/base/ directory that have annoyed me over the years. checkpatch.pl is now very happy.

---
 drivers/base/base.h     |   14 +-
 drivers/base/bus.c      |  290 +++++++++++++++++++++++------------------------
 drivers/base/class.c    |  140 +++++++++++-----------
 drivers/base/core.c     |  203 +++++++++++++++------------------
 drivers/base/dd.c       |  119 ++++++++++----------
 drivers/base/driver.c   |  120 +++++++++-----------
 drivers/base/init.c     |    9 +-
 drivers/base/platform.c |  233 +++++++++++++++++++-------------------
 8 files changed, 545 insertions(+), 583 deletions(-)
drivers/base/base.h +7 -7
index f7ad65a..c044414 100644
@@ -50,15 +50,15 @@ extern int platform_bus_init(void);
 extern int system_bus_init(void);
 extern int cpu_dev_init(void);
 
-extern int bus_add_device(struct device * dev);
-extern void bus_attach_device(struct device * dev);
-extern void bus_remove_device(struct device * dev);
+extern int bus_add_device(struct device *dev);
+extern void bus_attach_device(struct device *dev);
+extern void bus_remove_device(struct device *dev);
 
-extern int bus_add_driver(struct device_driver *);
-extern void bus_remove_driver(struct device_driver *);
+extern int bus_add_driver(struct device_driver *drv);
+extern void bus_remove_driver(struct device_driver *drv);
 
-extern void driver_detach(struct device_driver * drv);
-extern int driver_probe_device(struct device_driver *, struct device *);
+extern void driver_detach(struct device_driver *drv);
+extern int driver_probe_device(struct device_driver *drv, struct device *dev);
 
 extern void sysdev_shutdown(void);
 extern int sysdev_suspend(pm_message_t state);
drivers/base/bus.c +140 -150

566 lines not on this page · raw message

drivers/base/class.c +70 -70

328 lines not on this page · raw message

drivers/base/core.c +95 -108

363 lines not on this page · raw message

drivers/base/dd.c +58 -61

209 lines not on this page · raw message

drivers/base/driver.c +55 -65

226 lines not on this page · raw message

drivers/base/init.c +3 -6
index 1da88a1..7bd9b6a 100644
@@ -1,10 +1,8 @@
 /*
- *
  * Copyright (c) 2002-3 Patrick Mochel
  * Copyright (c) 2002-3 Open Source Development Labs
  *
  * This file is released under the GPLv2
- *
  */
 
 #include <linux/device.h>
@@ -14,12 +12,11 @@
 #include "base.h"
 
 /**
- *	driver_init - initialize driver model.
+ * driver_init - initialize driver model.
  *
- *	Call the driver model init functions to initialize their
- *	subsystems. Called early from init/main.c.
+ * Call the driver model init functions to initialize their
+ * subsystems. Called early from init/main.c.
  */
-
 void __init driver_init(void)
 {
 	/* These are the core pieces */
drivers/base/platform.c +117 -116

405 lines not on this page · raw message

Signature · 1 line
1.5.3.8
#247 lore raw
In reply to Greg KH
Quoted 3 lines · Greg KH

Here are a pretty large number of kobject, documentation, and driver core patches against your 2.6.24 git tree.

I've merged it all, but it causes lots of scary warnings:

- from the purely broken ones:

ehci_hcd: no version for "struct_module" found: kernel tainted.

- to the scary ones:

	sysfs: duplicate filename 'ehci_hcd' can not be created
	WARNING: at fs/sysfs/dir.c:424 sysfs_add_one()
	Pid: 610, comm: insmod Tainted: GF       2.6.24-gb47711bf #28
	
	Call Trace:
	 [<ffffffff802bd63c>] sysfs_add_one+0x54/0xbd
	 [<ffffffff802bdbc0>] create_dir+0x4f/0x87
	 [<ffffffff802bdc2d>] sysfs_create_dir+0x35/0x4a
	 [<ffffffff803154c8>] kobject_get+0x12/0x17
	 [<ffffffff80315607>] kobject_add_internal+0xd9/0x194
	 [<ffffffff8031579c>] kobject_add_varg+0x54/0x61
	 [<ffffffff80261efe>] __alloc_pages+0x66/0x2ee
	 [<ffffffff80315321>] kobject_init+0x42/0x82
	 [<ffffffff80315843>] kobject_init_and_add+0x9a/0xa7
	 [<ffffffff802722c0>] __vmalloc_area_node+0x111/0x135
	 [<ffffffff8025546b>] mod_sysfs_init+0x6e/0x83
	 [<ffffffff802561e8>] sys_init_module+0xa3d/0x1833
	 [<ffffffff8028ebd5>] dput+0x1c/0x10b
	 [<ffffffff8020b3be>] system_call+0x7e/0x83

and the problem seems to be that it does all these checks even for modules that will never be loaded, because I use my own kernel, but with the default Fedora initrd (which is trying to load modules for stuff that I already have built in).

Very annoying.

Can we please do that *after* the module loading symbol checks have run, so that when you try to load a module that will not load, it won't complain about these silly things?

(You can probably trigger this by simply trying to load a module that was compiled for another kernel version - it will fail fine, but in failing it will then generate all these incorrect warnings!)

Now it incorrectly taints my kernel, for no good reason.

Linus

author
#248 lore raw
Quoted 35 lines · Linus Torvalds
Quoted 3 lines · Greg KH

Here are a pretty large number of kobject, documentation, and driver core patches against your 2.6.24 git tree.

I've merged it all, but it causes lots of scary warnings:

- from the purely broken ones:

ehci_hcd: no version for "struct_module" found: kernel tainted.

- to the scary ones:

	sysfs: duplicate filename 'ehci_hcd' can not be created
	WARNING: at fs/sysfs/dir.c:424 sysfs_add_one()
	Pid: 610, comm: insmod Tainted: GF       2.6.24-gb47711bf #28
	
	Call Trace:
	 [<ffffffff802bd63c>] sysfs_add_one+0x54/0xbd
	 [<ffffffff802bdbc0>] create_dir+0x4f/0x87
	 [<ffffffff802bdc2d>] sysfs_create_dir+0x35/0x4a
	 [<ffffffff803154c8>] kobject_get+0x12/0x17
	 [<ffffffff80315607>] kobject_add_internal+0xd9/0x194
	 [<ffffffff8031579c>] kobject_add_varg+0x54/0x61
	 [<ffffffff80261efe>] __alloc_pages+0x66/0x2ee
	 [<ffffffff80315321>] kobject_init+0x42/0x82
	 [<ffffffff80315843>] kobject_init_and_add+0x9a/0xa7
	 [<ffffffff802722c0>] __vmalloc_area_node+0x111/0x135
	 [<ffffffff8025546b>] mod_sysfs_init+0x6e/0x83
	 [<ffffffff802561e8>] sys_init_module+0xa3d/0x1833
	 [<ffffffff8028ebd5>] dput+0x1c/0x10b
	 [<ffffffff8020b3be>] system_call+0x7e/0x83
Quoted 6 lines

and the problem seems to be that it does all these checks even for modules that will never be loaded, because I use my own kernel, but with the default Fedora initrd (which is trying to load modules for stuff that I already have built in).

Very annoying.

That's really wierd, I don't see that at all here just running with your 2.6.24 + my git tree and lots of USB drivers built into the kernel also (like ehci_hcd).

I'll try to reproduce it on your merged git tree now...

Quoted 9 lines

Can we please do that *after* the module loading symbol checks have run, so that when you try to load a module that will not load, it won't complain about these silly things?

(You can probably trigger this by simply trying to load a module that was compiled for another kernel version - it will fail fine, but in failing it will then generate all these incorrect warnings!)

Now it incorrectly taints my kernel, for no good reason.

$ cat /proc/sys/kernel/tainted
0

Odd...

$ uname -r
2.6.24-ge374a2bf-dirty

Strange, I thought that the uname id would show the git version that you were running, but that doesn't show a valid id. But that's probably a different issue in the build system somewhere...

thanks,

greg k-h

#249 lore raw
Quoted 4 lines · Greg KH

That's really wierd, I don't see that at all here just running with your 2.6.24 + my git tree and lots of USB drivers built into the kernel also (like ehci_hcd).

But do you use an initrd that tries to load the same driver too?

I'm too lazy to want to do my own initrd. I just use the prepackaged ones and rely on the fact that my private kernel will refuse to load modules that aren't meant for it anyway.

Quoted 2 lines
$ cat /proc/sys/kernel/tainted
0

Mine says "2".

Quoted 6 lines
$ uname -r
2.6.24-ge374a2bf-dirty

Strange, I thought that the uname id would show the git version that you were running, but that doesn't show a valid id. But that's probably a different issue in the build system somewhere...

That *is* the git version you're running: e374a2bf.

The "-g" is for "git" and the "-dirty" is because you have some non-checked-in changes in addition.

I works for me:

	[torvalds@hp linux]$ git show --abbrev-commit -s --pretty=oneline e374a2bf
	e374a2b... Kobject: fix coding style issues in kobject c files

so that looks like a valid version..

Linus

author
#250 lore raw
Quoted 8 lines · Linus Torvalds
Quoted 4 lines · Greg KH

That's really wierd, I don't see that at all here just running with your 2.6.24 + my git tree and lots of USB drivers built into the kernel also (like ehci_hcd).

Quoted 5 lines

But do you use an initrd that tries to load the same driver too?

I'm too lazy to want to do my own initrd. I just use the prepackaged ones and rely on the fact that my private kernel will refuse to load modules that aren't meant for it anyway.

No, I don't use any initrd at all.

You should just get a message saying that the version magic doesn't match, so the initrd modules will not load. That's what happens to me when I try to force old modules to load.

Quoted 17 lines
Quoted 2 lines
$ cat /proc/sys/kernel/tainted
0

Mine says "2".

Quoted 6 lines
$ uname -r
2.6.24-ge374a2bf-dirty

Strange, I thought that the uname id would show the git version that you were running, but that doesn't show a valid id. But that's probably a different issue in the build system somewhere...

That *is* the git version you're running: e374a2bf.

The "-g" is for "git" and the "-dirty" is because you have some non-checked-in changes in addition.

Quoted 6 lines

I works for me:

	[torvalds@hp linux]$ git show --abbrev-commit -s --pretty=oneline e374a2bf
	e374a2b... Kobject: fix coding style issues in kobject c files

so that looks like a valid version..

Ah taking the "g" off the search works, didn't realize that.

And I didn't have any unchecked in files, 'git status' shows no modified files, but other stuff in the main directory, like patches that shouldn't matter, but perhaps they do.
But oh well, I'm still building your tree now to try to reproduce this...

thanks,

greg k-h

author
#251 lore raw
In reply to Linus Torvalds
Quoted 9 lines · Linus Torvalds
Quoted 4 lines · Greg KH

That's really wierd, I don't see that at all here just running with your 2.6.24 + my git tree and lots of USB drivers built into the kernel also (like ehci_hcd).

But do you use an initrd that tries to load the same driver too?

Ah, now I get it, sorry, I'll go check that error path, not exactly a normal one :)

thanks,

greg k-h

#252 lore raw
In reply to Linus Torvalds
Quoted 2 lines · Linus Torvalds

I'm too lazy to want to do my own initrd. I just use the prepackaged ones and rely on the fact that my private kernel will refuse to load modules that aren't meant for it anyway.

initrds generally aren't prepackaged, but generated on install (at least with Fedora). You can regenerate them with "mkinitrd -f /boot/initrd-2.6.24.img 2.6.24". Also, I find that "make modules_install install" does it automatically from a kernel build.

J

#253 lore raw
Quoted 9 lines · Jeremy Fitzhardinge
Quoted 3 lines · Linus Torvalds

I'm too lazy to want to do my own initrd. I just use the prepackaged ones and rely on the fact that my private kernel will refuse to load modules that aren't meant for it anyway.

initrds generally aren't prepackaged, but generated on install (at least with Fedora). You can regenerate them with "mkinitrd -f /boot/initrd-2.6.24.img 2.6.24". Also, I find that "make modules_install install" does it automatically from a kernel build.

Right. I assumed that Linus was calling mkinitrd but was being bitten by one of the occasional assumptions (I believe we make in that script) that certain things are always modular. I just mailed the maintainer, suggesting we screen against the one of the Modules.* files (perhaps Modules.order might become a good candidate in due course...).

Jon.

#254 lore raw
Quoted 3 lines · Jon Masters

Right. I assumed that Linus was calling mkinitrd but was being bitten by one of the occasional assumptions (I believe we make in that script)

No. I really am not. My /etc/grub.conf looks like this:

	title Linux
	        root (hd0,0)
	        kernel /vmlinuz ro root=/dev/VolGroup00/LogVol00 rhgb quiet
	        initrd /initrd-2.6.23.14-107.fc8.img

ie I literally run the fedora initrd.

I switch kernels, not initrd's. I don't even want to know if the initrd contains some distro-specific setup...

Linus

#255 lore raw
Quoted 8 lines · Linus Torvalds
Quoted 3 lines · Jon Masters

Right. I assumed that Linus was calling mkinitrd but was being bitten by one of the occasional assumptions (I believe we make in that script)

No. I really am not. My /etc/grub.conf looks like this:

Quoted 8 lines
	title Linux
	        root (hd0,0)
	        kernel /vmlinuz ro root=/dev/VolGroup00/LogVol00 rhgb quiet
	        initrd /initrd-2.6.23.14-107.fc8.img

ie I literally run the fedora initrd.

I switch kernels, not initrd's. I don't even want to know if the initrd contains some distro-specific setup...

The distro mkinird can reconstruct it containing your freshly built modules (if any) and any other distro goo which needs to go in there. /initrd-2.6.23.14-107.fc8.img doesn't come out of an rpm; its built by an installer script when you install the kernel, and you can run the same script on your kernels.

Does you use "make modules_install install" when you build the kernel? It just does the right thing for me under F8, including rebuilding initrd and updating grub.conf.

J

#256 lore raw
Quoted 25 lines · Jeremy Fitzhardinge
Quoted 13 lines · Linus Torvalds
Quoted 3 lines · Jon Masters

Right. I assumed that Linus was calling mkinitrd but was being bitten by one of the occasional assumptions (I believe we make in that script)

No. I really am not. My /etc/grub.conf looks like this:

	title Linux
	        root (hd0,0)
	        kernel /vmlinuz ro root=/dev/VolGroup00/LogVol00 rhgb quiet
	        initrd /initrd-2.6.23.14-107.fc8.img
Quoted 4 lines

ie I literally run the fedora initrd.

I switch kernels, not initrd's. I don't even want to know if the initrd contains some distro-specific setup...

The distro mkinird can reconstruct it containing your freshly built modules (if any) and any other distro goo which needs to go in there. /initrd-2.6.23.14-107.fc8.img doesn't come out of an rpm; its built by an installer script when you install the kernel, and you can run the same script on your kernels.

Quoted 3 lines

Does you use "make modules_install install" when you build the kernel? It just does the right thing for me under F8, including rebuilding initrd and updating grub.conf.

My wish is that distros would just boot without requiring an initrd. I know how to make them for redhat and debian based distros, but the fact that you can't (easily) cross-build them makes it a very tedious construct.

I can butcher the distros into booting and ignore the errors on bootup that whine that modules are missing, but really.

#257 lore raw
Quoted 4 lines · Peter Zijlstra

My wish is that distros would just boot without requiring an initrd. I know how to make them for redhat and debian based distros, but the fact that you can't (easily) cross-build them makes it a very tedious construct.

all it takes for me on Fedora is to boot a modular distro kernel once, then copy the /dev to the real (persistent) /dev:

mkdir /tmp2
mount /dev/sda1 /tmp2
cp -a /dev/* /tmp2/dev/

and from that point on a bzImage/vmlinuz can boot up on Fedora without any problems (as long as it has the right drivers built in), and the initrd line can be removed from grub.conf.

Ingo

#258 lore raw
Quoted 10 lines · Ingo Molnar
Quoted 4 lines · Peter Zijlstra

My wish is that distros would just boot without requiring an initrd. I know how to make them for redhat and debian based distros, but the fact that you can't (easily) cross-build them makes it a very tedious construct.

all it takes for me on Fedora is to boot a modular distro kernel once, then copy the /dev to the real (persistent) /dev:

Quoted 7 lines

mkdir /tmp2
mount /dev/sda1 /tmp2
cp -a /dev/* /tmp2/dev/

and from that point on a bzImage/vmlinuz can boot up on Fedora without any problems (as long as it has the right drivers built in), and the initrd line can be removed from grub.conf.

Yeah, I usually do the same but with a bind mount, still it would be grand if such things would not be needed.

#259 lore raw
Quoted 15 lines · Peter Zijlstra
Quoted 14 lines · Ingo Molnar
Quoted 4 lines · Peter Zijlstra

My wish is that distros would just boot without requiring an initrd. I know how to make them for redhat and debian based distros, but the fact that you can't (easily) cross-build them makes it a very tedious construct.

all it takes for me on Fedora is to boot a modular distro kernel once, then copy the /dev to the real (persistent) /dev:

mkdir /tmp2
mount /dev/sda1 /tmp2
cp -a /dev/* /tmp2/dev/

Quoted 6 lines
Quoted 3 lines

and from that point on a bzImage/vmlinuz can boot up on Fedora without any problems (as long as it has the right drivers built in), and the initrd line can be removed from grub.conf.

Yeah, I usually do the same but with a bind mount, still it would be grand if such things would not be needed.

Agreed. But it's not likely to be a priority - all the vendors want completely modular kernels. But now we see what Linus wants to do, perhaps we can try to be a bit more friendly toward that. It's not actually rocket science, after all. I was concerned that he wanted to use the modules in the initrd, but now I see Linus, and everyone else, just want to do what I also secretly do, and just not use an initrd.

Isn't it funny. We all secretly hate using initrds ourselves :)

Jon.

#260 lore raw
In reply to Ingo Molnar
Quoted 10 lines · Ingo Molnar

all it takes for me on Fedora is to boot a modular distro kernel once, then copy the /dev to the real (persistent) /dev:

mkdir /tmp2
mount /dev/sda1 /tmp2
cp -a /dev/* /tmp2/dev/

and from that point on a bzImage/vmlinuz can boot up on Fedora without any problems (as long as it has the right drivers built in), and the initrd line can be removed from grub.conf.

Tried something like that once - it didn't play nice with the fact that I have root-on-LVM, so you need an initrd to do the 'lvm vgchange -a' and get it online.

#261 lore raw
In reply to Peter Zijlstra
Quoted 5 lines · Peter Zijlstra

My wish is that distros would just boot without requiring an initrd. I know how to make them for redhat and debian based distros, but the fact that you can't (easily) cross-build them makes it a very tedious construct.

Debian is easy enough - make sure the drivers for the root device and root fs is built-in, and you can drop the initrd. Takes a second or two off the boot, and some more off the build.

Helge Hafting

#262 lore raw
In reply to Linus Torvalds
Quoted 8 lines · On Fri, 25 Jan 2008 11:11:48 -0800 (PST) Linus Torvalds…
Quoted 4 lines · Greg KH

That's really wierd, I don't see that at all here just running with your 2.6.24 + my git tree and lots of USB drivers built into the kernel also (like ehci_hcd).

Quoted 6 lines

But do you use an initrd that tries to load the same driver too?

I'm too lazy to want to do my own initrd. I just use the prepackaged ones and rely on the fact that my private kernel will refuse to load modules that aren't meant for it anyway.

you know about "make install" right? That copies the needed files to /boot, adds them to grub AND makes an initrd for you.. all for free ;)

Signature · 3 lines
If you want to reach me at my work email, use [email protected]
For development, discussion and tips for power savings, 
visit http://www.lesswatts.org
author
#263 lore raw
In reply to Linus Torvalds
Quoted 4 lines · Linus Torvalds
Quoted 1 line · Greg KH
Quoted 8 lines
Quoted 2 lines

Here are a pretty large number of kobject, documentation, and driver core patches against your 2.6.24 git tree.

I've merged it all, but it causes lots of scary warnings:

- from the purely broken ones:

ehci_hcd: no version for "struct_module" found: kernel tainted.

Ok, in looking at the code, this should also be showing up for you on a "clean" 2.6.24 release, I didn't change anything in this code path.

That is what taints your kernel with the "F" flag.

Quoted 13 lines

- to the scary ones:

	sysfs: duplicate filename 'ehci_hcd' can not be created
	WARNING: at fs/sysfs/dir.c:424 sysfs_add_one()
	Pid: 610, comm: insmod Tainted: GF       2.6.24-gb47711bf #28
	
	Call Trace:
	 [<ffffffff802bd63c>] sysfs_add_one+0x54/0xbd
	 [<ffffffff802bdbc0>] create_dir+0x4f/0x87
	 [<ffffffff802bdc2d>] sysfs_create_dir+0x35/0x4a
	 [<ffffffff803154c8>] kobject_get+0x12/0x17
	 [<ffffffff80315607>] kobject_add_internal+0xd9/0x194
	 [<ffffffff8031579c>] kobject_add_varg+0x54/0x61
Quoted 8 lines
	 [<ffffffff80261efe>] __alloc_pages+0x66/0x2ee
	 [<ffffffff80315321>] kobject_init+0x42/0x82
	 [<ffffffff80315843>] kobject_init_and_add+0x9a/0xa7
	 [<ffffffff802722c0>] __vmalloc_area_node+0x111/0x135
	 [<ffffffff8025546b>] mod_sysfs_init+0x6e/0x83
	 [<ffffffff802561e8>] sys_init_module+0xa3d/0x1833
	 [<ffffffff8028ebd5>] dput+0x1c/0x10b
	 [<ffffffff8020b3be>] system_call+0x7e/0x83

This is the sysfs core telling you that someone did something stupid :)

Yes, that's new, but the "error" was always there, I just made the warning more visible to get people to pay attention to it, and find the real errors where this happens (and it has found them, which is a good thing.)

But in this case, it doesn't look like the module loading code will detect that we are trying to load a module that is already present until the kobjects are set up here. It's been this way for a long time :(

Rusty, any ideas of us adding a different check for "duplicate" modules like this earlier in the load_module() function, so we don't spend so much effort in building everything up when we don't need to?

I think it's down in the apply_relocate() function where we would finally figure out that something bad is going on here, which seems a bit late to me.

I guess we could just check the list of module names loaded when we try to set up the kobject, that would be simple and easy.

Linus, does the patch below (built tested only) fix the above call trace noise for you? It shouldn't change the taint flag, that's a different issue it seems.

thanks,

greg k-h

---------------------

From: Greg Kroah-Hartman <[email protected]>
Subject: module: bail out of loading duplicate modules early

This should fix the long calltrace when trying to load a module that has been built into the kernel allready.

kernel/module.c +10 -0
index dcb8a2c..3a76a4d 100644
@@ -1210,6 +1210,7 @@ void module_remove_modinfo_attrs(struct module *mod)
 int mod_sysfs_init(struct module *mod)
 {
 	int err;
+	struct kobject *kobj;
 
 	if (!module_sysfs_initialized) {
 		printk(KERN_ERR "%s: module sysfs not initialized\n",
@@ -1217,6 +1218,15 @@ int mod_sysfs_init(struct module *mod)
 		err = -EINVAL;
 		goto out;
 	}
+
+	kobj = kset_find_obj(module_kset, mod->name);
+	if (kobj) {
+		printk(KERN_ERR "%s: module is already loaded\n", mod->name);
+		kobject_put(kobj);
+		err = -EINVAL;
+		goto out;
+	}
+
 	mod->mkobj.mod = mod;
 
 	memset(&mod->mkobj.kobj, 0, sizeof(mod->mkobj.kobj));
#264 lore raw
Quoted 8 lines · Greg KH
Quoted 4 lines · Linus Torvalds

- from the purely broken ones:

ehci_hcd: no version for "struct_module" found: kernel tainted.

Ok, in looking at the code, this should also be showing up for you on a "clean" 2.6.24 release, I didn't change anything in this code path.

Ok, I just never noticed, because without any warnings or oopses, it didn't much matter...

Quoted 3 lines

Linus, does the patch below (built tested only) fix the above call trace noise for you? It shouldn't change the taint flag, that's a different issue it seems.

Sadly, I'm now in the process of shutting down all my machines to prepare for "the flight from hell(tm)", so I won't have time to check this right now.

Linus

author
#265 lore raw
Quoted 8 lines · Linus Torvalds
Quoted 3 lines · Greg KH

Linus, does the patch below (built tested only) fix the above call trace noise for you? It shouldn't change the taint flag, that's a different issue it seems.

Sadly, I'm now in the process of shutting down all my machines to prepare for "the flight from hell(tm)", so I won't have time to check this right now.

Ok, I'll queue it up myself in my trees and send it to you in a few days.

Have a nice trip,

greg k-h

#266 lore raw
In reply to Greg KH
Quoted 45 lines · On Saturday 26 January 2008 06:42:19 Greg KH wrote:
Quoted 9 lines · Linus Torvalds
Quoted 2 lines · Greg KH

Here are a pretty large number of kobject, documentation, and driver core patches against your 2.6.24 git tree.

I've merged it all, but it causes lots of scary warnings:

- from the purely broken ones:

ehci_hcd: no version for "struct_module" found: kernel tainted.

Ok, in looking at the code, this should also be showing up for you on a "clean" 2.6.24 release, I didn't change anything in this code path.

That is what taints your kernel with the "F" flag.

Quoted 13 lines

- to the scary ones:

	sysfs: duplicate filename 'ehci_hcd' can not be created
	WARNING: at fs/sysfs/dir.c:424 sysfs_add_one()
	Pid: 610, comm: insmod Tainted: GF       2.6.24-gb47711bf #28

	Call Trace:
	 [<ffffffff802bd63c>] sysfs_add_one+0x54/0xbd
	 [<ffffffff802bdbc0>] create_dir+0x4f/0x87
	 [<ffffffff802bdc2d>] sysfs_create_dir+0x35/0x4a
	 [<ffffffff803154c8>] kobject_get+0x12/0x17
	 [<ffffffff80315607>] kobject_add_internal+0xd9/0x194
	 [<ffffffff8031579c>] kobject_add_varg+0x54/0x61
Quoted 8 lines
	 [<ffffffff80261efe>] __alloc_pages+0x66/0x2ee
	 [<ffffffff80315321>] kobject_init+0x42/0x82
	 [<ffffffff80315843>] kobject_init_and_add+0x9a/0xa7
	 [<ffffffff802722c0>] __vmalloc_area_node+0x111/0x135
	 [<ffffffff8025546b>] mod_sysfs_init+0x6e/0x83
	 [<ffffffff802561e8>] sys_init_module+0xa3d/0x1833
	 [<ffffffff8028ebd5>] dput+0x1c/0x10b
	 [<ffffffff8020b3be>] system_call+0x7e/0x83

This is the sysfs core telling you that someone did something stupid :)

Yes, that's new, but the "error" was always there, I just made the warning more visible to get people to pay attention to it, and find the real errors where this happens (and it has found them, which is a good thing.)

Quoted 7 lines

But in this case, it doesn't look like the module loading code will detect that we are trying to load a module that is already present until the kobjects are set up here. It's been this way for a long time :(

Rusty, any ideas of us adding a different check for "duplicate" modules like this earlier in the load_module() function, so we don't spend so much effort in building everything up when we don't need to?

module.c:1832 (in load_module)

	if (find_module(mod->name)) {
		err = -EEXIST;
		goto free_mod;
	}

That's pretty early, and before this backtrace.

Even for simultaneous loads, there's a mutex which protects from here to the list insertion.

Puzzled,
Rusty.

author
#267 lore raw
Quoted 54 lines · Rusty Russell
Quoted 45 lines · On Saturday 26 January 2008 06:42:19 Greg KH wrote:
Quoted 9 lines · Linus Torvalds
Quoted 2 lines · Greg KH

Here are a pretty large number of kobject, documentation, and driver core patches against your 2.6.24 git tree.

I've merged it all, but it causes lots of scary warnings:

- from the purely broken ones:

ehci_hcd: no version for "struct_module" found: kernel tainted.

Ok, in looking at the code, this should also be showing up for you on a "clean" 2.6.24 release, I didn't change anything in this code path.

That is what taints your kernel with the "F" flag.

Quoted 13 lines

- to the scary ones:

	sysfs: duplicate filename 'ehci_hcd' can not be created
	WARNING: at fs/sysfs/dir.c:424 sysfs_add_one()
	Pid: 610, comm: insmod Tainted: GF       2.6.24-gb47711bf #28

	Call Trace:
	 [<ffffffff802bd63c>] sysfs_add_one+0x54/0xbd
	 [<ffffffff802bdbc0>] create_dir+0x4f/0x87
	 [<ffffffff802bdc2d>] sysfs_create_dir+0x35/0x4a
	 [<ffffffff803154c8>] kobject_get+0x12/0x17
	 [<ffffffff80315607>] kobject_add_internal+0xd9/0x194
	 [<ffffffff8031579c>] kobject_add_varg+0x54/0x61
Quoted 8 lines
	 [<ffffffff80261efe>] __alloc_pages+0x66/0x2ee
	 [<ffffffff80315321>] kobject_init+0x42/0x82
	 [<ffffffff80315843>] kobject_init_and_add+0x9a/0xa7
	 [<ffffffff802722c0>] __vmalloc_area_node+0x111/0x135
	 [<ffffffff8025546b>] mod_sysfs_init+0x6e/0x83
	 [<ffffffff802561e8>] sys_init_module+0xa3d/0x1833
	 [<ffffffff8028ebd5>] dput+0x1c/0x10b
	 [<ffffffff8020b3be>] system_call+0x7e/0x83

This is the sysfs core telling you that someone did something stupid :)

Yes, that's new, but the "error" was always there, I just made the warning more visible to get people to pay attention to it, and find the real errors where this happens (and it has found them, which is a good thing.)

Quoted 7 lines

But in this case, it doesn't look like the module loading code will detect that we are trying to load a module that is already present until the kobjects are set up here. It's been this way for a long time :(

Rusty, any ideas of us adding a different check for "duplicate" modules like this earlier in the load_module() function, so we don't spend so much effort in building everything up when we don't need to?

Quoted 8 lines

module.c:1832 (in load_module)

	if (find_module(mod->name)) {
		err = -EEXIST;
		goto free_mod;
	}

That's pretty early, and before this backtrace.

But that doesn't catch the case here, of trying to load a module when the code itself is already built into the kernel. For that we are relying on the sysfs core to tell us we have a duplicate name problem, which happens much later.

Is there any test you can do sooner, or is relying on the sysfs test acceptable?

thanks,

greg k-h

#268 lore raw
Quoted 5 lines · On Saturday 26 January 2008 16:35:09 Greg KH wrote:
Quoted 1 line · Rusty Russell

That's pretty early, and before this backtrace.

But that doesn't catch the case here, of trying to load a module when the code itself is already built into the kernel.

Ah, I missed that, sorry.

Quoted 6 lines

For that we are
relying on the sysfs core to tell us we have a duplicate name problem, which happens much later.

Is there any test you can do sooner, or is relying on the sysfs test acceptable?

As you pointed out, that's always been a "configure your kernel correctly, stupid" kind of bug. Nicer would be to have a list of in-kernel "modules" generated by the build system, but sysfs is there and it's easy to hang our hats off...

So, no objections to this with that as a FIXME, and a change so the message says "module is already built into the kernel".

Thanks,
Rusty.

#269 lore raw
In reply to Rusty Russell
Quoted 8 lines · Rusty Russell

module.c:1832 (in load_module)

	if (find_module(mod->name)) {
		err = -EEXIST;
		goto free_mod;
	}
Quoted 4 lines

That's pretty early, and before this backtrace.

Even for simultaneous loads, there's a mutex which protects from here to the list insertion.

My problem isn't trying to load the same module twice.

My problem is that the *driver* already exists (because it's compiled in), and has already initialized itself, and has already registered.

Then, initrd tries to load an old module for that driver.

So no simultaneous loading, no two modules, simple two *drivers* with the same module names - but one was compiled in, and the other will fail because it doesn't have the required linkages (ie it will failt the modversions checks).

But even before it fails the modversion checks, it apparently does various ugly things that clash with the built-in driver.

At least that seems to be the case.

Linus

#270 lore raw
Quoted 4 lines · On Sunday 27 January 2008 17:42:28 Linus Torvalds wrote:

My problem is that the *driver* already exists (because it's compiled in), and has already initialized itself, and has already registered.

Then, initrd tries to load an old module for that driver.

I hate to say it, but this is user error. And it used to be that for some drivers you'd actually end up with two in-kernel if you did that.

But if even *you* don't get this right, it should finally prompt us to fix this...

Thanks,
Rusty.

#271 lore raw
In reply to Linus Torvalds
Quoted 4 lines · Linus Torvalds

and the problem seems to be that it does all these checks even for modules that will never be loaded, because I use my own kernel, but with the default Fedora initrd (which is trying to load modules for stuff that I already have built in).

Thanks Linus. I'll pass this on to the mkinitrd maintainer. We'll try to get this sorted out for you :)

Jon.