Skip to contentSkip to conversation

Driver Core update for 2.6.4

PATCH New Greg KH 3 participants 19 messages Mar 16, 2004

Subsystems (15)
Networking Network drivers VFS SCSI +11 more subsystems
lore
Share & tools
lore

Greg KH

author
#0 lore raw

PATCH 1/1 Driver Core update for 2.6.4

Hi,

Here are a few driver core changes for 2.6.3. They have all been in the -mm tree with the exception of the kref patch, which has been reviewed on lkml. These patches add a few more sysfs class entries, clean up the cdev interface and add the kref structure.

Please pull from:

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

thanks,

greg k-h

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

 drivers/base/Makefile                  |    5 ++
 drivers/base/bus.c                     |    4 -
 drivers/base/class.c                   |   16 ++++--
 drivers/base/class_simple.c            |    4 -
 drivers/base/core.c                    |    4 -
 drivers/base/driver.c                  |    4 -
 drivers/base/power/Makefile            |    4 +
 drivers/base/power/main.c              |    4 -
 drivers/base/power/shutdown.c          |    4 -
 drivers/base/sys.c                     |    4 -
 drivers/char/drm/drm_stub.h            |   35 +++++++++++++-
 drivers/char/lp.c                      |   16 +++++-
 drivers/char/misc.c                    |    1 
 drivers/char/tty_io.c                  |   80 ++++++++++++++++++---------------
 drivers/ieee1394/amdtp.c               |    3 -
 drivers/ieee1394/dv1394.c              |    4 -
 drivers/ieee1394/raw1394.c             |    4 -
 drivers/ieee1394/video1394.c           |    3 -
 drivers/input/input.c                  |    4 +
 drivers/net/ppp_generic.c              |   21 ++++++++
 drivers/pci/hotplug/pci_hotplug_core.c |   14 -----
 drivers/s390/char/tape_class.c         |    7 --
 drivers/scsi/sg.c                      |    7 +-
 drivers/scsi/st.c                      |   39 ++++++++++------
 fs/char_dev.c                          |   26 +++-------
 include/linux/cdev.h                   |    4 -
 include/linux/kobject.h                |    8 +++
 include/linux/kref.h                   |   32 +++++++++++++
 lib/Makefile                           |    3 +
 lib/kref.c                             |   60 ++++++++++++++++++++++++
 net/netlink/netlink_dev.c              |   20 +++++++-
 31 files changed, 301 insertions(+), 143 deletions(-)

-----

Andrew Morton:
o cdev: warning fix

Chris Wright:
o class_simple cleanup in sg
o class_simple cleanup in misc
o class_simple cleanup in input
o class_simple clean up in lp
o Patch to hook up PPP to simple class sysfs support

Greg Kroah-Hartman:
o kref: add kref structure to kernel tree
o remove cdev_set_name completely as it is not needed
o PCI Hotplug: use the new decl_subsys_name() macro instead of rolling our own
o Kobject: add decl_subsys_name() macro for users who want to set the subsystem name
o Driver core: make CONFIG_DEBUG_DRIVER implementation a whole lot cleaner

Jonathan Corbet:
o cdev 2/2: hide cdev->kobj
o cdev 1/2: Eliminate /sys/cdev

Leann Ogasawara:
o add sysfs simple class support for DRI char device
o Fix class_register() always returns 0
o Add sysfs simple class support for netlink

author
#1 lore raw

PATCH 1/1 Driver Core update for 2.6.4

ChangeSet 1.1608.84.1, 2004/03/09 14:25:46-08:00, [email protected]

Driver core: make CONFIG_DEBUG_DRIVER implementation a whole lot cleaner

 drivers/base/Makefile         |    5 +++++
 drivers/base/bus.c            |    4 ----
 drivers/base/class.c          |    4 ----
 drivers/base/class_simple.c   |    4 ----
 drivers/base/core.c           |    4 ----
 drivers/base/driver.c         |    4 ----
 drivers/base/power/Makefile   |    4 ++++
 drivers/base/power/main.c     |    4 ----
 drivers/base/power/shutdown.c |    4 ----
 drivers/base/sys.c            |    4 ----
 10 files changed, 9 insertions(+), 32 deletions(-)
drivers/base/Makefile +5 -0
diff -Nru a/drivers/base/Makefile b/drivers/base/Makefile
@@ -6,3 +6,8 @@
 obj-y			+= power/
 obj-$(CONFIG_FW_LOADER)	+= firmware_class.o
 obj-$(CONFIG_NUMA)	+= node.o
+
+ifeq ($(CONFIG_DEBUG_DRIVER),y)
+EXTRA_CFLAGS += -DDEBUG
+endif
+
drivers/base/bus.c +0 -4
diff -Nru a/drivers/base/bus.c b/drivers/base/bus.c
@@ -9,10 +9,6 @@
  */
 
 #include <linux/config.h>
-#ifdef CONFIG_DEBUG_DRIVER
-#define DEBUG	1
-#endif
-
 #include <linux/device.h>
 #include <linux/module.h>
 #include <linux/errno.h>
drivers/base/class.c +0 -4
diff -Nru a/drivers/base/class.c b/drivers/base/class.c
@@ -11,10 +11,6 @@
  */
 
 #include <linux/config.h>
-#ifdef CONFIG_DEBUG_DRIVER
-#define DEBUG	1
-#endif
-
 #include <linux/device.h>
 #include <linux/module.h>
 #include <linux/init.h>
drivers/base/class_simple.c +0 -4
diff -Nru a/drivers/base/class_simple.c b/drivers/base/class_simple.c
@@ -9,10 +9,6 @@
  */
 
 #include <linux/config.h>
-#ifdef CONFIG_DEBUG_DRIVER
-#define DEBUG	1
-#endif
-
 #include <linux/device.h>
 #include <linux/kdev_t.h>
 #include <linux/err.h>
drivers/base/core.c +0 -4
diff -Nru a/drivers/base/core.c b/drivers/base/core.c
@@ -9,10 +9,6 @@
  */
 
 #include <linux/config.h>
-#ifdef CONFIG_DEBUG_DRIVER
-#define DEBUG	1
-#endif
-
 #include <linux/device.h>
 #include <linux/err.h>
 #include <linux/init.h>
drivers/base/driver.c +0 -4
diff -Nru a/drivers/base/driver.c b/drivers/base/driver.c
@@ -9,10 +9,6 @@
  */
 
 #include <linux/config.h>
-#ifdef CONFIG_DEBUG_DRIVER
-#define DEBUG	1
-#endif
-
 #include <linux/device.h>
 #include <linux/module.h>
 #include <linux/errno.h>
drivers/base/power/Makefile +4 -0
diff -Nru a/drivers/base/power/Makefile b/drivers/base/power/Makefile
@@ -1,2 +1,6 @@
 obj-y			:= shutdown.o
 obj-$(CONFIG_PM)	+= main.o suspend.o resume.o runtime.o sysfs.o
+
+ifeq ($(CONFIG_DEBUG_DRIVER),y)
+EXTRA_CFLAGS += -DDEBUG
+endif
drivers/base/power/main.c +0 -4
diff -Nru a/drivers/base/power/main.c b/drivers/base/power/main.c
@@ -20,10 +20,6 @@
  */
 
 #include <linux/config.h>
-#ifdef CONFIG_DEBUG_DRIVER
-#define DEBUG	1
-#endif
-
 #include <linux/device.h>
 #include "power.h"
 
drivers/base/power/shutdown.c +0 -4
diff -Nru a/drivers/base/power/shutdown.c b/drivers/base/power/shutdown.c
@@ -9,10 +9,6 @@
  */
 
 #include <linux/config.h>
-#ifdef CONFIG_DEBUG_DRIVER
-#define DEBUG	1
-#endif
-
 #include <linux/device.h>
 #include <asm/semaphore.h>
 
drivers/base/sys.c +0 -4
diff -Nru a/drivers/base/sys.c b/drivers/base/sys.c
@@ -13,10 +13,6 @@
  */
 
 #include <linux/config.h>
-#ifdef CONFIG_DEBUG_DRIVER
-#define DEBUG	1
-#endif
-
 #include <linux/sysdev.h>
 #include <linux/err.h>
 #include <linux/module.h>
author
#2 lore raw

ChangeSet 1.1608.84.2, 2004/03/10 16:04:33-08:00, [email protected]

[PATCH] Patch to hook up PPP to simple class sysfs support

Review

Quoted 2 lines · * Hanna Linder ([email protected]) wrote:
(quoted diff) +2 -0
+		ppp_class = class_simple_create(THIS_MODULE, "ppp");
+		class_simple_device_add(ppp_class, MKDEV(PPP_MAJOR, 0), NULL, "ppp");

What happens if that class_simple_create() fails? Actually, class_simple_device_add could fail too, but doesn't seem anybody is checking for that.

Review

Quoted 7 lines
(quoted diff) +3 -1
 		err = devfs_mk_cdev(MKDEV(PPP_MAJOR, 0),
 				S_IFCHR|S_IRUSR|S_IWUSR, "ppp");
-		if (err)
+		if (err) {
 			unregister_chrdev(PPP_MAJOR, "ppp");
+			class_simple_device_remove(MKDEV(PPP_MAJOR,0));
+		}

need to destroy the class on error path to avoid leak.

Review static void __exit ppp_cleanup(void) · line 2550

Quoted 5 lines
(quoted diff) +1 -0
@@ -2540,6 +2547,7 @@ static void __exit ppp_cleanup(void)
 	if (unregister_chrdev(PPP_MAJOR, "ppp") != 0)
 		printk(KERN_ERR "PPP: failed to unregister PPP device\n");
 	devfs_remove("ppp");
+	class_simple_device_remove(MKDEV(PPP_MAJOR, 0));

ditto. this will leak and would cause oops on reload of module.

something like below.

 drivers/net/ppp_generic.c |   21 ++++++++++++++++++++-
 1 files changed, 20 insertions(+), 1 deletion(-)
drivers/net/ppp_generic.c +20 -1
diff -Nru a/drivers/net/ppp_generic.c b/drivers/net/ppp_generic.c
@@ -45,6 +45,7 @@
 #include <linux/smp_lock.h>
 #include <linux/rwsem.h>
 #include <linux/stddef.h>
+#include <linux/device.h>
 #include <net/slhc_vj.h>
 #include <asm/atomic.h>
 
@@ -271,6 +272,8 @@
 static int ppp_disconnect_channel(struct channel *pch);
 static void ppp_destroy_channel(struct channel *pch);
 
+static struct class_simple *ppp_class;
+
 /* Translates a PPP protocol number to a NP index (NP == network protocol) */
 static inline int proto_to_npindex(int proto)
 {
@@ -804,15 +807,29 @@
 	printk(KERN_INFO "PPP generic driver version " PPP_VERSION "\n");
 	err = register_chrdev(PPP_MAJOR, "ppp", &ppp_device_fops);
 	if (!err) {
+		ppp_class = class_simple_create(THIS_MODULE, "ppp");
+		if (IS_ERR(ppp_class)) {
+			err = PTR_ERR(ppp_class);
+			goto out_chrdev;
+		}
+		class_simple_device_add(ppp_class, MKDEV(PPP_MAJOR, 0), NULL, "ppp");
 		err = devfs_mk_cdev(MKDEV(PPP_MAJOR, 0),
 				S_IFCHR|S_IRUSR|S_IWUSR, "ppp");
 		if (err)
-			unregister_chrdev(PPP_MAJOR, "ppp");
+			goto out_class;
 	}
 
+out:
 	if (err)
 		printk(KERN_ERR "failed to register PPP device (%d)\n", err);
 	return err;
+
+out_class:
+	class_simple_device_remove(MKDEV(PPP_MAJOR,0));
+	class_simple_destroy(ppp_class);
+out_chrdev:
+	unregister_chrdev(PPP_MAJOR, "ppp");
+	goto out;
 }
 
 /*
@@ -2545,6 +2562,8 @@
 	if (unregister_chrdev(PPP_MAJOR, "ppp") != 0)
 		printk(KERN_ERR "PPP: failed to unregister PPP device\n");
 	devfs_remove("ppp");
+	class_simple_device_remove(MKDEV(PPP_MAJOR, 0));
+	class_simple_destroy(ppp_class);
 }
 
 /*
author
#3 lore raw

ChangeSet 1.1608.84.3, 2004/03/10 16:05:00-08:00, [email protected]

[PATCH] class_simple clean up in lp

Error condition isn't caught on class_simple_create, and parport_register_driver failure doesn't do proper cleanup.

 drivers/char/lp.c |   16 ++++++++++++++--
 1 files changed, 14 insertions(+), 2 deletions(-)
drivers/char/lp.c +14 -2
diff -Nru a/drivers/char/lp.c b/drivers/char/lp.c
@@ -869,7 +869,7 @@
 
 int __init lp_init (void)
 {
-	int i;
+	int i, err = 0;
 
 	if (parport_nr[0] == LP_PARPORT_OFF)
 		return 0;
@@ -900,10 +900,15 @@
 
 	devfs_mk_dir("printers");
 	lp_class = class_simple_create(THIS_MODULE, "printer");
+	if (IS_ERR(lp_class)) {
+		err = PTR_ERR(lp_class);
+		goto out_devfs;
+	}
 
 	if (parport_register_driver (&lp_driver)) {
 		printk (KERN_ERR "lp: unable to register with parport\n");
-		return -EIO;
+		err = -EIO;
+		goto out_class;
 	}
 
 	if (!lp_count) {
@@ -915,6 +920,13 @@
 	}
 
 	return 0;
+
+out_class:
+	class_simple_destroy(lp_class);
+out_devfs:
+	devfs_remove("printers");
+	unregister_chrdev(LP_MAJOR, "lp");
+	return err;
 }
 
 static int __init lp_init_module (void)
author
#4 lore raw

ChangeSet 1.1608.84.4, 2004/03/10 16:05:28-08:00, [email protected]

[PATCH] class_simple cleanup in input

Doesn't catch error on class_simple_add, and existing error return paths forget to class_simple_destroy.

 drivers/input/input.c |    4 ++++
 1 files changed, 4 insertions(+)
drivers/input/input.c +4 -0
diff -Nru a/drivers/input/input.c b/drivers/input/input.c
@@ -727,6 +727,8 @@
 	int retval = -ENOMEM;
 
 	input_class = class_simple_create(THIS_MODULE, "input");
+	if (IS_ERR(input_class))
+		return PTR_ERR(input_class);
 	input_proc_init();
 	retval = register_chrdev(INPUT_MAJOR, "input", &input_fops);
 	if (retval) {
@@ -734,6 +736,7 @@
 		remove_proc_entry("devices", proc_bus_input_dir);
 		remove_proc_entry("handlers", proc_bus_input_dir);
 		remove_proc_entry("input", proc_bus);
+		class_simple_destroy(input_class);
 		return retval;
 	}
 
@@ -743,6 +746,7 @@
 		remove_proc_entry("handlers", proc_bus_input_dir);
 		remove_proc_entry("input", proc_bus);
 		unregister_chrdev(INPUT_MAJOR, "input");
+		class_simple_destroy(input_class);
 	}
 	return retval;
 }
author
#5 lore raw

ChangeSet 1.1608.84.5, 2004/03/10 16:05:50-08:00, [email protected]

[PATCH] class_simple cleanup in misc

Error path doesn't class_simple_destroy.

 drivers/char/misc.c |    1 +
 1 files changed, 1 insertion(+)
drivers/char/misc.c +1 -0
diff -Nru a/drivers/char/misc.c b/drivers/char/misc.c
@@ -342,6 +342,7 @@
 	if (register_chrdev(MISC_MAJOR,"misc",&misc_fops)) {
 		printk("unable to get major %d for misc devices\n",
 		       MISC_MAJOR);
+		class_simple_destroy(misc_class);
 		return -EIO;
 	}
 	return 0;
author
#6 lore raw

ChangeSet 1.1608.84.6, 2004/03/10 16:06:14-08:00, [email protected]

[PATCH] class_simple cleanup in sg

The only spot that seems to care about class_simple_device_add possibly failing, but it gets the wrong error test.

 drivers/scsi/sg.c |    2 +-
 1 files changed, 1 insertion(+), 1 deletion(-)
drivers/scsi/sg.c +1 -1
diff -Nru a/drivers/scsi/sg.c b/drivers/scsi/sg.c
@@ -1439,7 +1439,7 @@
 				MKDEV(SCSI_GENERIC_MAJOR, k), 
 				cl_dev->dev, "%s", 
 				disk->disk_name);
-		if (NULL == sg_class_member)
+		if (IS_ERR(sg_class_member))
 			printk(KERN_WARNING "sg_add: "
 				"class_simple_device_add failed\n");
 		class_set_devdata(sg_class_member, sdp);
author
#7 lore raw

ChangeSet 1.1608.84.7, 2004/03/10 17:34:33-08:00, [email protected]

[PATCH] Add sysfs simple class support for netlink

Patch adds sysfs simple class support for netlink character device (Major 36). Feedback appreciated. Thanks,

 net/netlink/netlink_dev.c |   20 ++++++++++++++++++--
 1 files changed, 18 insertions(+), 2 deletions(-)
net/netlink/netlink_dev.c +18 -2
diff -Nru a/net/netlink/netlink_dev.c b/net/netlink/netlink_dev.c
@@ -27,6 +27,7 @@
 #include <linux/init.h>
 #include <linux/devfs_fs_kernel.h>
 #include <linux/smp_lock.h>
+#include <linux/device.h>
 
 #include <asm/bitops.h>
 #include <asm/system.h>
@@ -34,6 +35,7 @@
 
 static long open_map;
 static struct socket *netlink_user[MAX_LINKS];
+static struct class_simple *netlink_class;
 
 /*
  *	Device operations
@@ -229,17 +231,26 @@
 		return -EIO;
 	}
 
+	netlink_class = class_simple_create(THIS_MODULE, "netlink");
+	if (IS_ERR(netlink_class)) {
+		printk (KERN_ERR "Error creating netlink class.\n");
+		unregister_chrdev(NETLINK_MAJOR, "netlink");
+		return PTR_ERR(netlink_class);
+	}
+
 	devfs_mk_dir("netlink");
 
 	/*  Someone tell me the official names for the uppercase ones  */
 	for (i = 0; i < ARRAY_SIZE(entries); i++) {
 		devfs_mk_cdev(MKDEV(NETLINK_MAJOR, entries[i].minor),
 			S_IFCHR|S_IRUSR|S_IWUSR, "netlink/%s", entries[i].name);
+		class_simple_device_add(netlink_class, MKDEV(NETLINK_MAJOR, entries[i].minor), NULL, "%s", entries[i].name);
 	}
 
 	for (i = 0; i < 16; i++) {
 		devfs_mk_cdev(MKDEV(NETLINK_MAJOR, i + 16),
 			S_IFCHR|S_IRUSR|S_IWUSR, "netlink/tap%d", i);
+		class_simple_device_add(netlink_class, MKDEV(NETLINK_MAJOR, i + 16), NULL, "tap%d", i);
 	}
 
 	return 0;
@@ -249,11 +260,16 @@
 {
 	int i;
 
-	for (i = 0; i < ARRAY_SIZE(entries); i++)
+	for (i = 0; i < ARRAY_SIZE(entries); i++) {
 		devfs_remove("netlink/%s", entries[i].name);
-	for (i = 0; i < 16; i++)
+		class_simple_device_remove(MKDEV(NETLINK_MAJOR, entries[i].minor));
+	}
+	for (i = 0; i < 16; i++) {
 		devfs_remove("netlink/tap%d", i);
+		class_simple_device_remove(MKDEV(NETLINK_MAJOR, i + 16));
+	}
 	devfs_remove("netlink");
+	class_simple_destroy(netlink_class);
 	unregister_chrdev(NETLINK_MAJOR, "netlink");
 }
 
author
#8 lore raw

ChangeSet 1.1608.84.8, 2004/03/11 10:57:27-08:00, [email protected]

[PATCH] Fix class_register() always returns 0

I noticed that the class_register() function in drivers/base/class.c always returns 0 and thus will never fail. Patch below inserts simple error checking to return any errors if they occur. Feedback welcome. Thanks,

 drivers/base/class.c |   12 ++++++++++--
 1 files changed, 10 insertions(+), 2 deletions(-)
drivers/base/class.c +10 -2
diff -Nru a/drivers/base/class.c b/drivers/base/class.c
@@ -102,13 +102,21 @@
 
 int class_register(struct class * cls)
 {
+	int error;
+
 	pr_debug("device class '%s': registering\n",cls->name);
 
 	INIT_LIST_HEAD(&cls->children);
 	INIT_LIST_HEAD(&cls->interfaces);
-	kobject_set_name(&cls->subsys.kset.kobj,cls->name);
+	error = kobject_set_name(&cls->subsys.kset.kobj,cls->name);
+	if (error)
+		return error;
+
 	subsys_set_kset(cls,class_subsys);
-	subsystem_register(&cls->subsys);
+
+	error = subsystem_register(&cls->subsys);
+	if (error)
+		return error;
 
 	return 0;
 }
author
#9 lore raw

ChangeSet 1.1608.84.9, 2004/03/11 13:21:13-08:00, [email protected]

Kobject: add decl_subsys_name() macro for users who want to set the subsystem name

 include/linux/kobject.h |    8 ++++++++
 1 files changed, 8 insertions(+)
include/linux/kobject.h +8 -0
diff -Nru a/include/linux/kobject.h b/include/linux/kobject.h
@@ -151,6 +151,14 @@
 		.hotplug_ops =_hotplug_ops, \
 	} \
 }
+#define decl_subsys_name(_varname,_name,_type,_hotplug_ops) \
+struct subsystem _varname##_subsys = { \
+	.kset = { \
+		.kobj = { .name = __stringify(_name) }, \
+		.ktype = _type, \
+		.hotplug_ops =_hotplug_ops, \
+	} \
+}
 
 
 /**
author
#10 lore raw

ChangeSet 1.1608.84.10, 2004/03/11 13:22:16-08:00, [email protected]

PCI Hotplug: use the new decl_subsys_name() macro instead of rolling our own.

 drivers/pci/hotplug/pci_hotplug_core.c |   14 +-------------
 1 files changed, 1 insertion(+), 13 deletions(-)
drivers/pci/hotplug/pci_hotplug_core.c +1 -13
diff -Nru a/drivers/pci/hotplug/pci_hotplug_core.c b/drivers/pci/hotplug/pci_hotplug_core.c
@@ -104,19 +104,7 @@
 	.release = &hotplug_slot_release,
 };
 
-/* 
- * We create a struct subsystem on our own and not use decl_subsys so
- * we can have a sane name "slots" in sysfs, yet still keep a good
- * global variable name "pci_hotplug_slots_subsys.
- * If the decl_subsys() #define ever changes, this declaration will
- * need to be update to make sure everything is initialized properly.
- */
-struct subsystem pci_hotplug_slots_subsys = {
-	.kset = {
-		.kobj = { .name = "slots" },
-		.ktype = &hotplug_slot_ktype,
-	}
-};
+decl_subsys_name(pci_hotplug_slots, slots, &hotplug_slot_ktype, NULL);
 
 /* these strings match up with the values in pci_bus_speed */
 static char *pci_bus_speed_strings[] = {
author
#11 lore raw

ChangeSet 1.1608.84.11, 2004/03/11 16:35:34-08:00, [email protected]

[PATCH] add sysfs simple class support for DRI char device

Patch adds sysfs simple class support for DRI character device (Major 226). Also, adds some error checking.

 drivers/char/drm/drm_stub.h |   35 ++++++++++++++++++++++++++++++++---
 1 files changed, 32 insertions(+), 3 deletions(-)
drivers/char/drm/drm_stub.h +32 -3
diff -Nru a/drivers/char/drm/drm_stub.h b/drivers/char/drm/drm_stub.h
@@ -35,6 +35,8 @@
 
 #define DRM_STUB_MAXCARDS 16	/* Enough for one machine */
 
+static struct class_simple *drm_class;
+
 /** Stub list. One for each minor. */
 static struct drm_stub_list {
 	const char             *name;
@@ -117,6 +119,7 @@
 			DRM(stub_root) = DRM(proc_init)(dev, i, DRM(stub_root),
 							&DRM(stub_list)[i]
 							.dev_root);
+			class_simple_device_add(drm_class, MKDEV(DRM_MAJOR, i), NULL, name);
 			return i;
 		}
 	}
@@ -141,6 +144,7 @@
 	DRM(proc_cleanup)(minor, DRM(stub_root),
 			  DRM(stub_list)[minor].dev_root);
 	if (minor) {
+		class_simple_device_remove(MKDEV(DRM_MAJOR, minor));
 		inter_module_put("drm");
 	} else {
 		inter_module_unregister("drm");
@@ -148,6 +152,8 @@
 			  sizeof(*DRM(stub_list)) * DRM_STUB_MAXCARDS,
 			  DRM_MEM_STUB);
 		unregister_chrdev(DRM_MAJOR, "drm");
+		class_simple_device_remove(MKDEV(DRM_MAJOR, minor));
+		class_simple_destroy(drm_class);
 	}
 	return 0;
 }
@@ -170,10 +176,23 @@
 		       drm_device_t *dev)
 {
 	struct drm_stub_info *i = NULL;
+	int ret1;
+	int ret2;
 
 	DRM_DEBUG("\n");
-	if (register_chrdev(DRM_MAJOR, "drm", &DRM(stub_fops)))
+	ret1 = register_chrdev(DRM_MAJOR, "drm", &DRM(stub_fops));
+	if (!ret1) {
+		drm_class = class_simple_create(THIS_MODULE, "drm");
+		if (IS_ERR(drm_class)) {
+			printk (KERN_ERR "Error creating drm class.\n");
+			unregister_chrdev(DRM_MAJOR, "drm");
+			return PTR_ERR(drm_class);
+		}
+	}
+	else if (ret1 == -EBUSY)
 		i = (struct drm_stub_info *)inter_module_get("drm");
+	else
+		return -1;
 
 	if (i) {
 				/* Already registered */
@@ -186,8 +205,18 @@
 		DRM_DEBUG("calling inter_module_register\n");
 		inter_module_register("drm", THIS_MODULE, &DRM(stub_info));
 	}
-	if (DRM(stub_info).info_register)
-		return DRM(stub_info).info_register(name, fops, dev);
+	if (DRM(stub_info).info_register) {
+		ret2 = DRM(stub_info).info_register(name, fops, dev);
+		if (ret2) {
+			if (!ret1) {
+			unregister_chrdev(DRM_MAJOR, "drm");
+			class_simple_destroy(drm_class);
+			}
+			if (!i)
+				inter_module_unregister("drm");
+		}
+		return ret2;
+	}
 	return -1;
 }
 
author
#12 lore raw

ChangeSet 1.1608.84.12, 2004/03/12 15:20:28-08:00, [email protected]

[PATCH] cdev 1/2: Eliminate /sys/cdev

This is the first of two patches designed to make life easier for authors of device driver books - and, with luck, driver authors too.

/sys/cdev is, according to Al, a mistake which was never really meant to exist. I believe nothing uses it currently - there isn't a whole lot there to use. Its existence takes up system resources, and also requires drivers to deal with the cdev's embedded kobject in their failure paths. The following patch (against 2.6.4) makes it all go away.

OK, almost all. We have to keep (but not register) cdev_subsys because it's rwsem is needed to control access to cdev_map.

 drivers/char/tty_io.c |   10 +++-------
 fs/char_dev.c         |   26 ++++++++------------------
 2 files changed, 11 insertions(+), 25 deletions(-)
drivers/char/tty_io.c +3 -7
diff -Nru a/drivers/char/tty_io.c b/drivers/char/tty_io.c
@@ -2175,8 +2175,6 @@
 EXPORT_SYMBOL(tty_register_device);
 EXPORT_SYMBOL(tty_unregister_device);
 
-static struct kobject tty_kobj = {.name = "tty"};
-
 struct tty_driver *alloc_tty_driver(int lines)
 {
 	struct tty_driver *driver;
@@ -2276,7 +2274,6 @@
 		driver->termios_locked = NULL;
 	}
 
-	driver->cdev.kobj.parent = &tty_kobj;
 	strcpy(driver->cdev.kobj.name, driver->name);
 	for (s = strchr(driver->cdev.kobj.name, '/'); s; s = strchr(s, '/'))
 		*s = '!';
@@ -2400,7 +2397,9 @@
 }
 
 postcore_initcall(tty_class_init);
- 
+
+/* 3/2004 jmc: why do these devices exist? */
+
 static struct cdev tty_cdev, console_cdev;
 #ifdef CONFIG_UNIX98_PTYS
 static struct cdev ptmx_cdev;
@@ -2430,9 +2429,6 @@
 		panic("Couldn't register /dev/console driver\n");
 	devfs_mk_cdev(MKDEV(TTYAUX_MAJOR, 1), S_IFCHR|S_IRUSR|S_IWUSR, "console");
 	class_simple_device_add(tty_class, MKDEV(TTYAUX_MAJOR, 1), NULL, "console");
-
-	tty_kobj.kset = tty_cdev.kobj.kset;
-	kobject_register(&tty_kobj);
 
 #ifdef CONFIG_UNIX98_PTYS
 	strcpy(ptmx_cdev.kobj.name, "dev.ptmx");
fs/char_dev.c +8 -18
diff -Nru a/fs/char_dev.c b/fs/char_dev.c
@@ -340,15 +340,9 @@
 
 int cdev_add(struct cdev *p, dev_t dev, unsigned count)
 {
-	int err = kobject_add(&p->kobj);
-	if (err)
-		return err;
-	err = kobj_map(cdev_map, dev, count, NULL, exact_match, exact_lock, p);
-	if (err)
-		kobject_del(&p->kobj);
 	p->dev = dev;
 	p->count = count;
-	return err;
+	return kobj_map(cdev_map, dev, count, NULL, exact_match, exact_lock, p);
 }
 
 static void cdev_unmap(dev_t dev, unsigned count)
@@ -359,7 +353,6 @@
 void cdev_del(struct cdev *p)
 {
 	cdev_unmap(p->dev, p->count);
-	kobject_del(&p->kobj);
 	kobject_put(&p->kobj);
 }
 
@@ -407,18 +400,12 @@
 	.release	= cdev_dynamic_release,
 };
 
-static struct kset kset_dynamic = {
-	.subsys = &cdev_subsys,
-	.kobj = {.name = "major",},
-	.ktype = &ktype_cdev_dynamic,
-};
-
 struct cdev *cdev_alloc(void)
 {
 	struct cdev *p = kmalloc(sizeof(struct cdev), GFP_KERNEL);
 	if (p) {
 		memset(p, 0, sizeof(struct cdev));
-		p->kobj.kset = &kset_dynamic;
+		p->kobj.ktype = &ktype_cdev_dynamic;
 		INIT_LIST_HEAD(&p->list);
 		kobject_init(&p->kobj);
 	}
@@ -428,7 +415,6 @@
 void cdev_init(struct cdev *cdev, struct file_operations *fops)
 {
 	INIT_LIST_HEAD(&cdev->list);
-	kobj_set_kset_s(cdev, cdev_subsys);
 	cdev->kobj.ktype = &ktype_cdev_default;
 	kobject_init(&cdev->kobj);
 	cdev->ops = fops;
@@ -444,8 +430,12 @@
 
 void __init chrdev_init(void)
 {
-	subsystem_register(&cdev_subsys);
-	kset_register(&kset_dynamic);
+/*
+ * Keep cdev_subsys around because (and only because) the kobj_map code
+ * depends on the rwsem it contains.  We don't make it public in sysfs,
+ * however.
+ */
+	subsystem_init(&cdev_subsys);
 	cdev_map = kobj_map_init(base_probe, &cdev_subsys);
 }
 
author
#13 lore raw

ChangeSet 1.1608.84.13, 2004/03/12 15:20:49-08:00, [email protected]

[PATCH] cdev 2/2: hide cdev->kobj

The existing cdev interface requires users to deal with the embedded kobject in two places:

- The kobject name field must be set before adding the cdev, and
- Should cdev_add() fail, a call to kobject_put() is required.

IMO, this exposure of the embedded kobject makes the interface more brittle and harder to understand. It's also unnecessary. With the removal of /sys/cdev, a call to cdev_del() will nicely replace kobject_put(), and the name setting is easily wrapped.

This is against 2.6.4, but depends on the /sys/cdev removal patch.

 drivers/char/tty_io.c          |   12 ++++++------
 drivers/ieee1394/amdtp.c       |    2 +-
 drivers/ieee1394/dv1394.c      |    2 +-
 drivers/ieee1394/raw1394.c     |    3 ++-
 drivers/ieee1394/video1394.c   |    2 +-
 drivers/s390/char/tape_class.c |    4 ++--
 drivers/scsi/sg.c              |    4 ++--
 drivers/scsi/st.c              |    5 ++---
 include/linux/cdev.h           |    2 ++
 9 files changed, 19 insertions(+), 17 deletions(-)
drivers/char/tty_io.c +6 -6
diff -Nru a/drivers/char/tty_io.c b/drivers/char/tty_io.c
@@ -2274,14 +2274,14 @@
 		driver->termios_locked = NULL;
 	}
 
-	strcpy(driver->cdev.kobj.name, driver->name);
+	cdev_set_name(&driver->cdev, driver->name);
 	for (s = strchr(driver->cdev.kobj.name, '/'); s; s = strchr(s, '/'))
 		*s = '!';
 	cdev_init(&driver->cdev, &tty_fops);
 	driver->cdev.owner = driver->owner;
 	error = cdev_add(&driver->cdev, dev, driver->num);
 	if (error) {
-		kobject_del(&driver->cdev.kobj);
+		cdev_del(&driver->cdev);
 		unregister_chrdev_region(dev, driver->num);
 		driver->ttys = NULL;
 		driver->termios = driver->termios_locked = NULL;
@@ -2414,7 +2414,7 @@
  */
 static int __init tty_init(void)
 {
-	strcpy(tty_cdev.kobj.name, "dev.tty");
+	cdev_set_name(&tty_cdev, "dev.tty");
 	cdev_init(&tty_cdev, &tty_fops);
 	if (cdev_add(&tty_cdev, MKDEV(TTYAUX_MAJOR, 0), 1) ||
 	    register_chrdev_region(MKDEV(TTYAUX_MAJOR, 0), 1, "/dev/tty") < 0)
@@ -2422,7 +2422,7 @@
 	devfs_mk_cdev(MKDEV(TTYAUX_MAJOR, 0), S_IFCHR|S_IRUGO|S_IWUGO, "tty");
 	class_simple_device_add(tty_class, MKDEV(TTYAUX_MAJOR, 0), NULL, "tty");
 
-	strcpy(console_cdev.kobj.name, "dev.console");
+	cdev_set_name(&console_cdev, "dev.console");
 	cdev_init(&console_cdev, &console_fops);
 	if (cdev_add(&console_cdev, MKDEV(TTYAUX_MAJOR, 1), 1) ||
 	    register_chrdev_region(MKDEV(TTYAUX_MAJOR, 1), 1, "/dev/console") < 0)
@@ -2431,7 +2431,7 @@
 	class_simple_device_add(tty_class, MKDEV(TTYAUX_MAJOR, 1), NULL, "console");
 
 #ifdef CONFIG_UNIX98_PTYS
-	strcpy(ptmx_cdev.kobj.name, "dev.ptmx");
+	cdev_set_name(&ptmx_cdev, "dev.ptmx");
 	cdev_init(&ptmx_cdev, &tty_fops);
 	if (cdev_add(&ptmx_cdev, MKDEV(TTYAUX_MAJOR, 2), 1) ||
 	    register_chrdev_region(MKDEV(TTYAUX_MAJOR, 2), 1, "/dev/ptmx") < 0)
@@ -2441,7 +2441,7 @@
 #endif
 
 #ifdef CONFIG_VT
-	strcpy(vc0_cdev.kobj.name, "dev.vc0");
+	cdev_set_name(&vc0_cdev, "dev.vc0");
 	cdev_init(&vc0_cdev, &console_fops);
 	if (cdev_add(&vc0_cdev, MKDEV(TTY_MAJOR, 0), 1) ||
 	    register_chrdev_region(MKDEV(TTY_MAJOR, 0), 1, "/dev/vc/0") < 0)
drivers/ieee1394/amdtp.c +1 -1
diff -Nru a/drivers/ieee1394/amdtp.c b/drivers/ieee1394/amdtp.c
@@ -1266,7 +1266,7 @@
 {
 	cdev_init(&amdtp_cdev, &amdtp_fops);
 	amdtp_cdev.owner = THIS_MODULE;
-	kobject_set_name(&amdtp_cdev.kobj, "amdtp");
+	cdev_set_name(&amdtp_cdev, "amdtp");
 	if (cdev_add(&amdtp_cdev, IEEE1394_AMDTP_DEV, 16)) {
 		HPSB_ERR("amdtp: unable to add char device");
  		return -EIO;
drivers/ieee1394/dv1394.c +1 -1
diff -Nru a/drivers/ieee1394/dv1394.c b/drivers/ieee1394/dv1394.c
@@ -2616,7 +2616,7 @@
 
 	cdev_init(&dv1394_cdev, &dv1394_fops);
 	dv1394_cdev.owner = THIS_MODULE;
-	kobject_set_name(&dv1394_cdev.kobj, "dv1394");
+	cdev_set_name(&dv1394_cdev, "dv1394");
 	ret = cdev_add(&dv1394_cdev, IEEE1394_DV1394_DEV, 16);
 	if (ret) {
 		printk(KERN_ERR "dv1394: unable to register character device\n");
drivers/ieee1394/raw1394.c +2 -1
diff -Nru a/drivers/ieee1394/raw1394.c b/drivers/ieee1394/raw1394.c
@@ -2746,9 +2746,10 @@
 
 	cdev_init(&raw1394_cdev, &raw1394_fops);
 	raw1394_cdev.owner = THIS_MODULE;
-	kobject_set_name(&raw1394_cdev.kobj, RAW1394_DEVICE_NAME);
+	cdev_set_name(&raw1394_cdev, RAW1394_DEVICE_NAME);
 	ret = cdev_add(&raw1394_cdev, IEEE1394_RAW1394_DEV, 1);
 	if (ret) {
+		/* jmc: leaves reference to (static) raw1394_cdev */
                 HPSB_ERR("raw1394 failed to register minor device block");
                 devfs_remove(RAW1394_DEVICE_NAME);
                 hpsb_unregister_highlevel(&raw1394_highlevel);
drivers/ieee1394/video1394.c +1 -1
diff -Nru a/drivers/ieee1394/video1394.c b/drivers/ieee1394/video1394.c
@@ -1457,7 +1457,7 @@
 
 	cdev_init(&video1394_cdev, &video1394_fops);
 	video1394_cdev.owner = THIS_MODULE;
-	kobject_set_name(&video1394_cdev.kobj, VIDEO1394_DRIVER_NAME);
+	cdev_set_name(&video1394_cdev, VIDEO1394_DRIVER_NAME);
 	ret = cdev_add(&video1394_cdev, IEEE1394_VIDEO1394_DEV, 16);
 	if (ret) {
 		PRINT_G(KERN_ERR, "video1394: unable to get minor device block");
drivers/s390/char/tape_class.c +2 -2
diff -Nru a/drivers/s390/char/tape_class.c b/drivers/s390/char/tape_class.c
@@ -46,13 +46,13 @@
 	cdev->owner = fops->owner;
 	cdev->ops   = fops;
 	cdev->dev   = dev;
-	strcpy(cdev->kobj.name, devname);
+	cdev_set_name(cdev, devname);
 	for (s = strchr(cdev->kobj.name, '/'); s; s = strchr(s, '/'))
 		*s = '!';
 
 	rc = cdev_add(cdev, cdev->dev, 1);
 	if (rc) {
-		kobject_put(&cdev->kobj);
+		cdev_del(cdev);
 		return ERR_PTR(rc);
 	}
 	class_simple_device_add(tape_class, cdev->dev, device, "%s", devname);
drivers/scsi/sg.c +2 -2
diff -Nru a/drivers/scsi/sg.c b/drivers/scsi/sg.c
@@ -1409,7 +1409,7 @@
 	SCSI_LOG_TIMEOUT(3, printk("sg_add: dev=%d \n", k));
 	memset(sdp, 0, sizeof(*sdp));
 	sprintf(disk->disk_name, "sg%d", k);
-	strncpy(cdev->kobj.name, disk->disk_name, KOBJ_NAME_LEN);
+	cdev_set_name(cdev, disk->disk_name);
 	cdev->owner = THIS_MODULE;
 	cdev->ops = &sg_fops;
 	disk->major = SCSI_GENERIC_MAJOR;
@@ -1462,7 +1462,7 @@
 out:
 	put_disk(disk);
 	if (cdev)
-		kobject_put(&cdev->kobj);
+		cdev_del(cdev);
 	return error;
 }
 
drivers/scsi/st.c +2 -3
diff -Nru a/drivers/scsi/st.c b/drivers/scsi/st.c
@@ -3888,8 +3888,7 @@
 				       dev_num);
 				goto out_free_tape;
 			}
-			snprintf(cdev->kobj.name, KOBJ_NAME_LEN, "%sm%d%s", disk->disk_name,
-				 mode, j ? "n" : "");
+			cdev_set_name(cdev, "%sm%d%s", disk->disk_name, mode, j ? "n" : "");
 			cdev->owner = THIS_MODULE;
 			cdev->ops = &st_fops;
 
@@ -3944,7 +3943,7 @@
 		}
 	}
 	if (cdev)
-		kobject_put(&cdev->kobj);
+		cdev_del(cdev);
 	write_lock(&st_dev_arr_lock);
 	scsi_tapes[dev_num] = NULL;
 	st_nr_dev--;
include/linux/cdev.h +2 -0
diff -Nru a/include/linux/cdev.h b/include/linux/cdev.h
@@ -25,5 +25,7 @@
 
 void cd_forget(struct inode *);
 
+#define cdev_set_name(cdev, args...) kobject_set_name(&((cdev)->kobj), ##args)
+
 #endif
 #endif
author
#14 lore raw

ChangeSet 1.1608.84.14, 2004/03/12 16:22:36-08:00, [email protected]

remove cdev_set_name completely as it is not needed.

 drivers/char/tty_io.c          |    7 -------
 drivers/ieee1394/amdtp.c       |    1 -
 drivers/ieee1394/dv1394.c      |    1 -
 drivers/ieee1394/raw1394.c     |    1 -
 drivers/ieee1394/video1394.c   |    1 -
 drivers/s390/char/tape_class.c |    3 ---
 drivers/scsi/sg.c              |    1 -
 drivers/scsi/st.c              |    1 -
 include/linux/cdev.h           |    2 --
 9 files changed, 18 deletions(-)
drivers/char/tty_io.c +0 -7
diff -Nru a/drivers/char/tty_io.c b/drivers/char/tty_io.c
@@ -2274,9 +2274,6 @@
 		driver->termios_locked = NULL;
 	}
 
-	cdev_set_name(&driver->cdev, driver->name);
-	for (s = strchr(driver->cdev.kobj.name, '/'); s; s = strchr(s, '/'))
-		*s = '!';
 	cdev_init(&driver->cdev, &tty_fops);
 	driver->cdev.owner = driver->owner;
 	error = cdev_add(&driver->cdev, dev, driver->num);
@@ -2414,7 +2411,6 @@
  */
 static int __init tty_init(void)
 {
-	cdev_set_name(&tty_cdev, "dev.tty");
 	cdev_init(&tty_cdev, &tty_fops);
 	if (cdev_add(&tty_cdev, MKDEV(TTYAUX_MAJOR, 0), 1) ||
 	    register_chrdev_region(MKDEV(TTYAUX_MAJOR, 0), 1, "/dev/tty") < 0)
@@ -2422,7 +2418,6 @@
 	devfs_mk_cdev(MKDEV(TTYAUX_MAJOR, 0), S_IFCHR|S_IRUGO|S_IWUGO, "tty");
 	class_simple_device_add(tty_class, MKDEV(TTYAUX_MAJOR, 0), NULL, "tty");
 
-	cdev_set_name(&console_cdev, "dev.console");
 	cdev_init(&console_cdev, &console_fops);
 	if (cdev_add(&console_cdev, MKDEV(TTYAUX_MAJOR, 1), 1) ||
 	    register_chrdev_region(MKDEV(TTYAUX_MAJOR, 1), 1, "/dev/console") < 0)
@@ -2431,7 +2426,6 @@
 	class_simple_device_add(tty_class, MKDEV(TTYAUX_MAJOR, 1), NULL, "console");
 
 #ifdef CONFIG_UNIX98_PTYS
-	cdev_set_name(&ptmx_cdev, "dev.ptmx");
 	cdev_init(&ptmx_cdev, &tty_fops);
 	if (cdev_add(&ptmx_cdev, MKDEV(TTYAUX_MAJOR, 2), 1) ||
 	    register_chrdev_region(MKDEV(TTYAUX_MAJOR, 2), 1, "/dev/ptmx") < 0)
@@ -2441,7 +2435,6 @@
 #endif
 
 #ifdef CONFIG_VT
-	cdev_set_name(&vc0_cdev, "dev.vc0");
 	cdev_init(&vc0_cdev, &console_fops);
 	if (cdev_add(&vc0_cdev, MKDEV(TTY_MAJOR, 0), 1) ||
 	    register_chrdev_region(MKDEV(TTY_MAJOR, 0), 1, "/dev/vc/0") < 0)
drivers/ieee1394/amdtp.c +0 -1
diff -Nru a/drivers/ieee1394/amdtp.c b/drivers/ieee1394/amdtp.c
@@ -1266,7 +1266,6 @@
 {
 	cdev_init(&amdtp_cdev, &amdtp_fops);
 	amdtp_cdev.owner = THIS_MODULE;
-	cdev_set_name(&amdtp_cdev, "amdtp");
 	if (cdev_add(&amdtp_cdev, IEEE1394_AMDTP_DEV, 16)) {
 		HPSB_ERR("amdtp: unable to add char device");
  		return -EIO;
drivers/ieee1394/dv1394.c +0 -1
diff -Nru a/drivers/ieee1394/dv1394.c b/drivers/ieee1394/dv1394.c
@@ -2616,7 +2616,6 @@
 
 	cdev_init(&dv1394_cdev, &dv1394_fops);
 	dv1394_cdev.owner = THIS_MODULE;
-	cdev_set_name(&dv1394_cdev, "dv1394");
 	ret = cdev_add(&dv1394_cdev, IEEE1394_DV1394_DEV, 16);
 	if (ret) {
 		printk(KERN_ERR "dv1394: unable to register character device\n");
drivers/ieee1394/raw1394.c +0 -1
diff -Nru a/drivers/ieee1394/raw1394.c b/drivers/ieee1394/raw1394.c
@@ -2746,7 +2746,6 @@
 
 	cdev_init(&raw1394_cdev, &raw1394_fops);
 	raw1394_cdev.owner = THIS_MODULE;
-	cdev_set_name(&raw1394_cdev, RAW1394_DEVICE_NAME);
 	ret = cdev_add(&raw1394_cdev, IEEE1394_RAW1394_DEV, 1);
 	if (ret) {
 		/* jmc: leaves reference to (static) raw1394_cdev */
drivers/ieee1394/video1394.c +0 -1
diff -Nru a/drivers/ieee1394/video1394.c b/drivers/ieee1394/video1394.c
@@ -1457,7 +1457,6 @@
 
 	cdev_init(&video1394_cdev, &video1394_fops);
 	video1394_cdev.owner = THIS_MODULE;
-	cdev_set_name(&video1394_cdev, VIDEO1394_DRIVER_NAME);
 	ret = cdev_add(&video1394_cdev, IEEE1394_VIDEO1394_DEV, 16);
 	if (ret) {
 		PRINT_G(KERN_ERR, "video1394: unable to get minor device block");
drivers/s390/char/tape_class.c +0 -3
diff -Nru a/drivers/s390/char/tape_class.c b/drivers/s390/char/tape_class.c
@@ -46,9 +46,6 @@
 	cdev->owner = fops->owner;
 	cdev->ops   = fops;
 	cdev->dev   = dev;
-	cdev_set_name(cdev, devname);
-	for (s = strchr(cdev->kobj.name, '/'); s; s = strchr(s, '/'))
-		*s = '!';
 
 	rc = cdev_add(cdev, cdev->dev, 1);
 	if (rc) {
drivers/scsi/sg.c +0 -1
diff -Nru a/drivers/scsi/sg.c b/drivers/scsi/sg.c
@@ -1409,7 +1409,6 @@
 	SCSI_LOG_TIMEOUT(3, printk("sg_add: dev=%d \n", k));
 	memset(sdp, 0, sizeof(*sdp));
 	sprintf(disk->disk_name, "sg%d", k);
-	cdev_set_name(cdev, disk->disk_name);
 	cdev->owner = THIS_MODULE;
 	cdev->ops = &sg_fops;
 	disk->major = SCSI_GENERIC_MAJOR;
drivers/scsi/st.c +0 -1
diff -Nru a/drivers/scsi/st.c b/drivers/scsi/st.c
@@ -3888,7 +3888,6 @@
 				       dev_num);
 				goto out_free_tape;
 			}
-			cdev_set_name(cdev, "%sm%d%s", disk->disk_name, mode, j ? "n" : "");
 			cdev->owner = THIS_MODULE;
 			cdev->ops = &st_fops;
 
include/linux/cdev.h +0 -2
diff -Nru a/include/linux/cdev.h b/include/linux/cdev.h
@@ -25,7 +25,5 @@
 
 void cd_forget(struct inode *);
 
-#define cdev_set_name(cdev, args...) kobject_set_name(&((cdev)->kobj), ##args)
-
 #endif
 #endif
author
#15 lore raw

ChangeSet 1.1608.84.15, 2004/03/15 14:36:49-08:00, [email protected]

[PATCH] cdev: warning fix

Against Jon's cdev stuff

 drivers/char/tty_io.c |    1 -
 1 files changed, 1 deletion(-)
drivers/char/tty_io.c +0 -1
diff -Nru a/drivers/char/tty_io.c b/drivers/char/tty_io.c
@@ -2234,7 +2234,6 @@
 	int error;
         int i;
 	dev_t dev;
-	char *s;
 	void **p = NULL;
 
 	if (driver->flags & TTY_DRIVER_INSTALLED)
author
#16 lore raw

ChangeSet 1.1608.84.16, 2004/03/15 14:39:18-08:00, [email protected]

kref: add kref structure to kernel tree.

Based on the kobject structure, but much smaller and simpler to use.

 include/linux/kref.h |   32 +++++++++++++++++++++++++++
 lib/Makefile         |    3 ++
 lib/kref.c           |   60 +++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 95 insertions(+)
include/linux/kref.h new file +32 -0
diff -Nru a/include/linux/kref.h b/include/linux/kref.h
@@ -0,0 +1,32 @@
+/*
+ * kref.c - library routines for handling generic reference counted objects
+ *
+ * Copyright (C) 2004 Greg Kroah-Hartman <[email protected]>
+ * Copyright (C) 2004 IBM Corp.
+ *
+ * based on kobject.h which was:
+ * Copyright (C) 2002-2003 Patrick Mochel <[email protected]>
+ * Copyright (C) 2002-2003 Open Source Development Labs
+ *
+ * This file is released under the GPLv2.
+ *
+ */
+
+#if defined(__KERNEL__) && !defined(_KREF_H_)
+#define _KREF_H_
+
+#include <linux/types.h>
+#include <asm/atomic.h>
+
+
+struct kref {
+	atomic_t refcount;
+	void (*release)(struct kref *kref);
+};
+
+void kref_init(struct kref *kref, void (*release)(struct kref *));
+struct kref *kref_get(struct kref *kref);
+void kref_put(struct kref *kref);
+
+
+#endif /* _KREF_H_ */
lib/Makefile +3 -0
diff -Nru a/lib/Makefile b/lib/Makefile
@@ -8,6 +8,9 @@
 	 kobject.o idr.o div64.o parser.o int_sqrt.o \
 	 bitmap.o extable.o
 
+# hack for now till some static code uses krefs, then it can move up above...
+obj-y += kref.o
+
 lib-$(CONFIG_RWSEM_GENERIC_SPINLOCK) += rwsem-spinlock.o
 lib-$(CONFIG_RWSEM_XCHGADD_ALGORITHM) += rwsem.o
 
lib/kref.c new file +60 -0

60 lines not on this page · raw message

#17 lore raw
Quoted 5 lines · Greg KH

ChangeSet 1.1608.84.16, 2004/03/15 14:39:18-08:00, [email protected]

kref: add kref structure to kernel tree.

Based on the kobject structure, but much smaller and simpler to use.

Didn't everyone who reviewed this say it's useless bloat. Andi even got so far as calling it obsfucation, given that hides simple things behind an overly complex and wastefull abstraction.

#18 lore raw
Quoted 9 lines · Christoph Hellwig
Quoted 5 lines · Greg KH

ChangeSet 1.1608.84.16, 2004/03/15 14:39:18-08:00, [email protected]

kref: add kref structure to kernel tree.

Based on the kobject structure, but much smaller and simpler to use.

Didn't everyone who reviewed this say it's useless bloat.

No.

bix:/usr/src/25> wc -l include/linux/kref.h lib/kref.c

     32 include/linux/kref.h
     60 lib/kref.c
     92 total

bix:/usr/src/25> size lib/kref.o

   text    data     bss     dec     hex filename
    368       0       0     368     170 lib/kref.o
Quoted 3 lines

Andi even got
so far as calling it obsfucation, given that hides simple things behind an overly complex and wastefull abstraction.

eh? If there is any argument against this code it is that it is so simple that the thing which it abstracts is not worth abstracting. But given that it is so unwasteful, this seems unimportant.