Skip to contentSkip to conversation

Driver core changes for 2.6.12

PATCH New Greg KH 4 participants 92 messages Jun 20, 2005 – Jul 12, 2005 Page 2 of 2

Subsystems (57)
lore
Share & tools
lore
author
#21 lore raw

PATCH 1/1 class: convert drivers/* to use the new class api instead of class_simple

In reply to Greg KH

[PATCH] class: convert drivers/* to use the new class api instead of class_simple

---
commit 56b2293595b2eb52cc2aa2baf92c6cfa8265f9d5
tree 5cbada5b35b1b87dfd75852c9397a2b14dfbb9d9
parent 8874b414ffe037c39e73bb262ddf69653a13c0a4
author [email protected] <[email protected]> Wed, 23 Mar 2005 10:01:41 -0800 committer Greg Kroah-Hartman <[email protected]> Mon, 20 Jun 2005 15:15:09 -0700

 drivers/isdn/capi/capi.c            |   14 +++++++-------
 drivers/macintosh/adb.c             |    9 ++++-----
 drivers/media/dvb/dvb-core/dvbdev.c |   13 ++++++-------
 drivers/net/ppp_generic.c           |   14 +++++++-------
 drivers/net/wan/cosa.c              |   12 ++++++------
 drivers/s390/char/tape_class.c      |   10 +++++-----
 drivers/s390/char/vmlogrdr.c        |   10 +++++-----
 drivers/usb/core/file.c             |   12 ++++++------
 drivers/video/fbmem.c               |   10 +++++-----
 9 files changed, 51 insertions(+), 53 deletions(-)
drivers/isdn/capi/capi.c +7 -7
@@ -58,7 +58,7 @@ MODULE_LICENSE("GPL");
 
 /* -------- driver information -------------------------------------- */
 
-static struct class_simple *capi_class;
+static struct class *capi_class;
 
 static int capi_major = 68;		/* allocated */
 #ifdef CONFIG_ISDN_CAPI_MIDDLEWARE
@@ -1499,20 +1499,20 @@ static int __init capi_init(void)
 		return -EIO;
 	}
 
-	capi_class = class_simple_create(THIS_MODULE, "capi");
+	capi_class = class_create(THIS_MODULE, "capi");
 	if (IS_ERR(capi_class)) {
 		unregister_chrdev(capi_major, "capi20");
 		return PTR_ERR(capi_class);
 	}
 
-	class_simple_device_add(capi_class, MKDEV(capi_major, 0), NULL, "capi");
+	class_device_create(capi_class, MKDEV(capi_major, 0), NULL, "capi");
 	devfs_mk_cdev(MKDEV(capi_major, 0), S_IFCHR | S_IRUSR | S_IWUSR,
 			"isdn/capi20");
 
 #ifdef CONFIG_ISDN_CAPI_MIDDLEWARE
 	if (capinc_tty_init() < 0) {
-		class_simple_device_remove(MKDEV(capi_major, 0));
-		class_simple_destroy(capi_class);
+		class_device_destroy(capi_class, MKDEV(capi_major, 0));
+		class_destroy(capi_class);
 		unregister_chrdev(capi_major, "capi20");
 		return -ENOMEM;
 	}
@@ -1539,8 +1539,8 @@ static void __exit capi_exit(void)
 {
 	proc_exit();
 
-	class_simple_device_remove(MKDEV(capi_major, 0));
-	class_simple_destroy(capi_class);
+	class_device_destroy(capi_class, MKDEV(capi_major, 0));
+	class_destroy(capi_class);
 	unregister_chrdev(capi_major, "capi20");
 	devfs_remove("isdn/capi20");
 
drivers/macintosh/adb.c +4 -5
@@ -77,7 +77,7 @@ static struct adb_driver *adb_driver_lis
 	NULL
 };
 
-static struct class_simple *adb_dev_class;
+static struct class *adb_dev_class;
 
 struct adb_driver *adb_controller;
 struct notifier_block *adb_client_list = NULL;
@@ -902,9 +902,8 @@ adbdev_init(void)
 
 	devfs_mk_cdev(MKDEV(ADB_MAJOR, 0), S_IFCHR | S_IRUSR | S_IWUSR, "adb");
 
-	adb_dev_class = class_simple_create(THIS_MODULE, "adb");
-	if (IS_ERR(adb_dev_class)) {
+	adb_dev_class = class_create(THIS_MODULE, "adb");
+	if (IS_ERR(adb_dev_class))
 		return;
-	}
-	class_simple_device_add(adb_dev_class, MKDEV(ADB_MAJOR, 0), NULL, "adb");
+	class_device_create(adb_dev_class, MKDEV(ADB_MAJOR, 0), NULL, "adb");
 }
drivers/media/dvb/dvb-core/dvbdev.c +6 -7
@@ -56,8 +56,7 @@ static const char * const dnames[] = {
 #define nums2minor(num,type,id)	((num << 6) | (id << 4) | type)
 #define MAX_DVB_MINORS		(DVB_MAX_ADAPTERS*64)
 
-struct class_simple *dvb_class;
-EXPORT_SYMBOL(dvb_class);
+static struct class *dvb_class;
 
 static struct dvb_device* dvbdev_find_device (int minor)
 {
@@ -236,8 +235,8 @@ int dvb_register_device(struct dvb_adapt
 			S_IFCHR | S_IRUSR | S_IWUSR,
 			"dvb/adapter%d/%s%d", adap->num, dnames[type], id);
 
-	class_simple_device_add(dvb_class, MKDEV(DVB_MAJOR, nums2minor(adap->num, type, id)),
-				NULL, "dvb%d.%s%d", adap->num, dnames[type], id);
+	class_device_create(dvb_class, MKDEV(DVB_MAJOR, nums2minor(adap->num, type, id)),
+			    NULL, "dvb%d.%s%d", adap->num, dnames[type], id);
 
 	dprintk("DVB: register adapter%d/%s%d @ minor: %i (0x%02x)\n",
 		adap->num, dnames[type], id, nums2minor(adap->num, type, id),
@@ -256,7 +255,7 @@ void dvb_unregister_device(struct dvb_de
 	devfs_remove("dvb/adapter%d/%s%d", dvbdev->adapter->num,
 			dnames[dvbdev->type], dvbdev->id);
 
-	class_simple_device_remove(MKDEV(DVB_MAJOR, nums2minor(dvbdev->adapter->num,
+	class_device_destroy(dvb_class, MKDEV(DVB_MAJOR, nums2minor(dvbdev->adapter->num,
 					dvbdev->type, dvbdev->id)));
 
 	list_del (&dvbdev->list_head);
@@ -412,7 +411,7 @@ static int __init init_dvbdev(void)
 
 	devfs_mk_dir("dvb");
 
-	dvb_class = class_simple_create(THIS_MODULE, "dvb");
+	dvb_class = class_create(THIS_MODULE, "dvb");
 	if (IS_ERR(dvb_class)) {
 		retval = PTR_ERR(dvb_class);
 		goto error;
@@ -429,7 +428,7 @@ error:
 static void __exit exit_dvbdev(void)
 {
         devfs_remove("dvb");
-	class_simple_destroy(dvb_class);
+	class_destroy(dvb_class);
 	cdev_del(&dvb_device_cdev);
         unregister_chrdev_region(MKDEV(DVB_MAJOR, 0), MAX_DVB_MINORS);
 }
drivers/net/ppp_generic.c +7 -7
@@ -273,7 +273,7 @@ static int ppp_connect_channel(struct ch
 static int ppp_disconnect_channel(struct channel *pch);
 static void ppp_destroy_channel(struct channel *pch);
 
-static struct class_simple *ppp_class;
+static struct class *ppp_class;
 
 /* Translates a PPP protocol number to a NP index (NP == network protocol) */
 static inline int proto_to_npindex(int proto)
@@ -858,12 +858,12 @@ static int __init ppp_init(void)
 	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");
+		ppp_class = class_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");
+		class_device_create(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)
@@ -876,8 +876,8 @@ out:
 	return err;
 
 out_class:
-	class_simple_device_remove(MKDEV(PPP_MAJOR,0));
-	class_simple_destroy(ppp_class);
+	class_device_destroy(ppp_class, MKDEV(PPP_MAJOR,0));
+	class_destroy(ppp_class);
 out_chrdev:
 	unregister_chrdev(PPP_MAJOR, "ppp");
 	goto out;
@@ -2654,8 +2654,8 @@ 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));
-	class_simple_destroy(ppp_class);
+	class_device_destroy(ppp_class, MKDEV(PPP_MAJOR, 0));
+	class_destroy(ppp_class);
 }
 
 /*
drivers/net/wan/cosa.c +6 -6
@@ -235,7 +235,7 @@ static int dma[MAX_CARDS+1];
 static int irq[MAX_CARDS+1] = { -1, -1, -1, -1, -1, -1, 0, };
 
 /* for class stuff*/
-static struct class_simple *cosa_class;
+static struct class *cosa_class;
 
 #ifdef MODULE
 module_param_array(io, int, NULL, 0);
@@ -394,19 +394,19 @@ static int __init cosa_init(void)
 		goto out;
 	}
 	devfs_mk_dir("cosa");
-	cosa_class = class_simple_create(THIS_MODULE, "cosa");
+	cosa_class = class_create(THIS_MODULE, "cosa");
 	if (IS_ERR(cosa_class)) {
 		err = PTR_ERR(cosa_class);
 		goto out_chrdev;
 	}
 	for (i=0; i<nr_cards; i++) {
-		class_simple_device_add(cosa_class, MKDEV(cosa_major, i),
+		class_device_create(cosa_class, MKDEV(cosa_major, i),
 				NULL, "cosa%d", i);
 		err = devfs_mk_cdev(MKDEV(cosa_major, i),
 				S_IFCHR|S_IRUSR|S_IWUSR,
 				"cosa/%d", i);
 		if (err) {
-			class_simple_device_remove(MKDEV(cosa_major, i));
+			class_device_destroy(cosa_class, MKDEV(cosa_major, i));
 			goto out_chrdev;		
 		}
 	}
@@ -427,10 +427,10 @@ static void __exit cosa_exit(void)
 	printk(KERN_INFO "Unloading the cosa module\n");
 
 	for (i=0; i<nr_cards; i++) {
-		class_simple_device_remove(MKDEV(cosa_major, i));
+		class_device_destroy(cosa_class, MKDEV(cosa_major, i));
 		devfs_remove("cosa/%d", i);
 	}
-	class_simple_destroy(cosa_class);
+	class_destroy(cosa_class);
 	devfs_remove("cosa");
 	for (cosa=cosa_cards; nr_cards--; cosa++) {
 		/* Clean up the per-channel data */
drivers/s390/char/tape_class.c +5 -5
@@ -16,7 +16,7 @@ MODULE_DESCRIPTION(
 );
 MODULE_LICENSE("GPL");
 
-struct class_simple *tape_class;
+static struct class *tape_class;
 
 /*
  * Register a tape device and return a pointer to the cdev structure.
@@ -70,7 +70,7 @@ struct tape_class_device *register_tape_
 	if (rc)
 		goto fail_with_cdev;
 
-	tcd->class_device = class_simple_device_add(
+	tcd->class_device = class_device_create(
 				tape_class,
 				tcd->char_device->dev,
 				device,
@@ -101,7 +101,7 @@ void unregister_tape_dev(struct tape_cla
 			&tcd->class_device->dev->kobj,
 			tcd->mode_name
 		);
-		class_simple_device_remove(tcd->char_device->dev);
+		class_device_destroy(tape_class, tcd->char_device->dev);
 		cdev_del(tcd->char_device);
 		kfree(tcd);
 	}
@@ -111,14 +111,14 @@ EXPORT_SYMBOL(unregister_tape_dev);
 
 static int __init tape_init(void)
 {
-	tape_class = class_simple_create(THIS_MODULE, "tape390");
+	tape_class = class_create(THIS_MODULE, "tape390");
 
 	return 0;
 }
 
 static void __exit tape_exit(void)
 {
-	class_simple_destroy(tape_class);
+	class_destroy(tape_class);
 	tape_class = NULL;
 }
 
drivers/s390/char/vmlogrdr.c +5 -5
@@ -703,7 +703,7 @@ static struct attribute_group vmlogrdr_a
 	.attrs = vmlogrdr_attrs,
 };
 
-static struct class_simple *vmlogrdr_class;
+static struct class *vmlogrdr_class;
 static struct device_driver vmlogrdr_driver = {
 	.name = "vmlogrdr",
 	.bus  = &iucv_bus,
@@ -727,7 +727,7 @@ vmlogrdr_register_driver(void) {
 		goto unregdriver;
 	}
 
-	vmlogrdr_class = class_simple_create(THIS_MODULE, "vmlogrdr");
+	vmlogrdr_class = class_create(THIS_MODULE, "vmlogrdr");
 	if (IS_ERR(vmlogrdr_class)) {
 		printk(KERN_ERR "vmlogrdr: failed to create class.\n");
 		ret=PTR_ERR(vmlogrdr_class);
@@ -746,7 +746,7 @@ unregdriver:
 
 static void
 vmlogrdr_unregister_driver(void) {
-	class_simple_destroy(vmlogrdr_class);
+	class_destroy(vmlogrdr_class);
 	vmlogrdr_class = NULL;
 	driver_remove_file(&vmlogrdr_driver, &driver_attr_recording_status);
 	driver_unregister(&vmlogrdr_driver);
@@ -786,7 +786,7 @@ vmlogrdr_register_device(struct vmlogrdr
 		device_unregister(dev);
 		return ret;
 	}
-	priv->class_device = class_simple_device_add(
+	priv->class_device = class_device_create(
 				vmlogrdr_class,
 				MKDEV(vmlogrdr_major, priv->minor_num),
 				dev,
@@ -806,7 +806,7 @@ vmlogrdr_register_device(struct vmlogrdr
 
 static int
 vmlogrdr_unregister_device(struct vmlogrdr_priv_t *priv ) {
-	class_simple_device_remove(MKDEV(vmlogrdr_major, priv->minor_num));
+	class_device_destroy(vmlogrdr_class, MKDEV(vmlogrdr_major, priv->minor_num));
 	if (priv->device != NULL) {
 		sysfs_remove_group(&priv->device->kobj, &vmlogrdr_attr_group);
 		device_unregister(priv->device);
drivers/usb/core/file.c +6 -6
@@ -68,7 +68,7 @@ static struct file_operations usb_fops =
 	.open =		usb_open,
 };
 
-static struct class_simple *usb_class;
+static struct class *usb_class;
 
 int usb_major_init(void)
 {
@@ -80,9 +80,9 @@ int usb_major_init(void)
 		goto out;
 	}
 
-	usb_class = class_simple_create(THIS_MODULE, "usb");
+	usb_class = class_create(THIS_MODULE, "usb");
 	if (IS_ERR(usb_class)) {
-		err("class_simple_create failed for usb devices");
+		err("class_create failed for usb devices");
 		unregister_chrdev(USB_MAJOR, "usb");
 		goto out;
 	}
@@ -95,7 +95,7 @@ out:
 
 void usb_major_cleanup(void)
 {
-	class_simple_destroy(usb_class);
+	class_destroy(usb_class);
 	devfs_remove("usb");
 	unregister_chrdev(USB_MAJOR, "usb");
 }
@@ -171,7 +171,7 @@ int usb_register_dev(struct usb_interfac
 		++temp;
 	else
 		temp = name;
-	intf->class_dev = class_simple_device_add(usb_class, MKDEV(USB_MAJOR, minor), &intf->dev, "%s", temp);
+	intf->class_dev = class_device_create(usb_class, MKDEV(USB_MAJOR, minor), &intf->dev, "%s", temp);
 	if (IS_ERR(intf->class_dev)) {
 		spin_lock (&minor_lock);
 		usb_minors[intf->minor] = NULL;
@@ -220,7 +220,7 @@ void usb_deregister_dev(struct usb_inter
 
 	snprintf(name, BUS_ID_SIZE, class_driver->name, intf->minor - minor_base);
 	devfs_remove (name);
-	class_simple_device_remove(MKDEV(USB_MAJOR, intf->minor));
+	class_device_destroy(usb_class, MKDEV(USB_MAJOR, intf->minor));
 	intf->class_dev = NULL;
 	intf->minor = -1;
 }
drivers/video/fbmem.c +5 -5
@@ -1040,7 +1040,7 @@ static struct file_operations fb_fops = 
 #endif
 };
 
-static struct class_simple *fb_class;
+static struct class *fb_class;
 
 /**
  *	register_framebuffer - registers a frame buffer device
@@ -1066,7 +1066,7 @@ register_framebuffer(struct fb_info *fb_
 			break;
 	fb_info->node = i;
 
-	fb_info->class_device = class_simple_device_add(fb_class, MKDEV(FB_MAJOR, i),
+	fb_info->class_device = class_device_create(fb_class, MKDEV(FB_MAJOR, i),
 				    fb_info->device, "fb%d", i);
 	if (IS_ERR(fb_info->class_device)) {
 		/* Not fatal */
@@ -1134,7 +1134,7 @@ unregister_framebuffer(struct fb_info *f
 	registered_fb[i]=NULL;
 	num_registered_fb--;
 	fb_cleanup_class_device(fb_info);
-	class_simple_device_remove(MKDEV(FB_MAJOR, i));
+	class_device_destroy(fb_class, MKDEV(FB_MAJOR, i));
 	return 0;
 }
 
@@ -1197,7 +1197,7 @@ fbmem_init(void)
 	if (register_chrdev(FB_MAJOR,"fb",&fb_fops))
 		printk("unable to get major %d for fb devs\n", FB_MAJOR);
 
-	fb_class = class_simple_create(THIS_MODULE, "graphics");
+	fb_class = class_create(THIS_MODULE, "graphics");
 	if (IS_ERR(fb_class)) {
 		printk(KERN_WARNING "Unable to create fb class; errno = %ld\n", PTR_ERR(fb_class));
 		fb_class = NULL;
@@ -1210,7 +1210,7 @@ module_init(fbmem_init);
 static void __exit
 fbmem_exit(void)
 {
-	class_simple_destroy(fb_class);
+	class_destroy(fb_class);
 }
 
 module_exit(fbmem_exit);
author
#12 lore raw

PATCH 1/1 INPUT: move to use the new class code, instead of class_simple

In reply to Greg KH

[PATCH] INPUT: move to use the new class code, instead of class_simple

---
commit 1235686f6e67cf30c460eb77d90a6cb4be57b92f
tree c7ef368a38c8e0c64e09d9e0e8a2a93392a1732c
parent 7fe845d11ad1b4aac098d40c55275569e143c483
author [email protected] <[email protected]> Tue, 15 Mar 2005 14:26:30 -0800 committer Greg Kroah-Hartman <[email protected]> Mon, 20 Jun 2005 15:15:04 -0700

 drivers/input/evdev.c    |    9 +++++----
 drivers/input/input.c    |   10 +++++-----
 drivers/input/joydev.c   |    8 ++++----
 drivers/input/mousedev.c |   16 +++++++++-------
 drivers/input/tsdev.c    |    9 +++++----
 include/linux/input.h    |    2 +-
 6 files changed, 29 insertions(+), 25 deletions(-)
drivers/input/evdev.c +5 -4
@@ -431,9 +431,9 @@ static struct input_handle *evdev_connec
 
 	devfs_mk_cdev(MKDEV(INPUT_MAJOR, EVDEV_MINOR_BASE + minor),
 			S_IFCHR|S_IRUGO|S_IWUSR, "input/event%d", minor);
-	class_simple_device_add(input_class,
-				MKDEV(INPUT_MAJOR, EVDEV_MINOR_BASE + minor),
-				dev->dev, "event%d", minor);
+	class_device_create(input_class,
+			MKDEV(INPUT_MAJOR, EVDEV_MINOR_BASE + minor),
+			dev->dev, "event%d", minor);
 
 	return &evdev->handle;
 }
@@ -443,7 +443,8 @@ static void evdev_disconnect(struct inpu
 	struct evdev *evdev = handle->private;
 	struct evdev_list *list;
 
-	class_simple_device_remove(MKDEV(INPUT_MAJOR, EVDEV_MINOR_BASE + evdev->minor));
+	class_device_destroy(input_class,
+			MKDEV(INPUT_MAJOR, EVDEV_MINOR_BASE + evdev->minor));
 	devfs_remove("input/event%d", evdev->minor);
 	evdev->exist = 0;
 
drivers/input/input.c +5 -5
@@ -702,13 +702,13 @@ static int __init input_proc_init(void)
 static inline int input_proc_init(void) { return 0; }
 #endif
 
-struct class_simple *input_class;
+struct class *input_class;
 
 static int __init input_init(void)
 {
 	int retval = -ENOMEM;
 
-	input_class = class_simple_create(THIS_MODULE, "input");
+	input_class = class_create(THIS_MODULE, "input");
 	if (IS_ERR(input_class))
 		return PTR_ERR(input_class);
 	input_proc_init();
@@ -718,7 +718,7 @@ static int __init input_init(void)
 		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);
+		class_destroy(input_class);
 		return retval;
 	}
 
@@ -728,7 +728,7 @@ static int __init input_init(void)
 		remove_proc_entry("handlers", proc_bus_input_dir);
 		remove_proc_entry("input", proc_bus);
 		unregister_chrdev(INPUT_MAJOR, "input");
-		class_simple_destroy(input_class);
+		class_destroy(input_class);
 	}
 	return retval;
 }
@@ -741,7 +741,7 @@ static void __exit input_exit(void)
 
 	devfs_remove("input");
 	unregister_chrdev(INPUT_MAJOR, "input");
-	class_simple_destroy(input_class);
+	class_destroy(input_class);
 }
 
 subsys_initcall(input_init);
drivers/input/joydev.c +4 -4
@@ -452,9 +452,9 @@ static struct input_handle *joydev_conne
 
 	devfs_mk_cdev(MKDEV(INPUT_MAJOR, JOYDEV_MINOR_BASE + minor),
 			S_IFCHR|S_IRUGO|S_IWUSR, "input/js%d", minor);
-	class_simple_device_add(input_class,
-				MKDEV(INPUT_MAJOR, JOYDEV_MINOR_BASE + minor),
-				dev->dev, "js%d", minor);
+	class_device_create(input_class,
+			MKDEV(INPUT_MAJOR, JOYDEV_MINOR_BASE + minor),
+			dev->dev, "js%d", minor);
 
 	return &joydev->handle;
 }
@@ -464,7 +464,7 @@ static void joydev_disconnect(struct inp
 	struct joydev *joydev = handle->private;
 	struct joydev_list *list;
 
-	class_simple_device_remove(MKDEV(INPUT_MAJOR, JOYDEV_MINOR_BASE + joydev->minor));
+	class_device_destroy(input_class, MKDEV(INPUT_MAJOR, JOYDEV_MINOR_BASE + joydev->minor));
 	devfs_remove("input/js%d", joydev->minor);
 	joydev->exist = 0;
 
drivers/input/mousedev.c +9 -7
@@ -647,9 +647,9 @@ static struct input_handle *mousedev_con
 
 	devfs_mk_cdev(MKDEV(INPUT_MAJOR, MOUSEDEV_MINOR_BASE + minor),
 			S_IFCHR|S_IRUGO|S_IWUSR, "input/mouse%d", minor);
-	class_simple_device_add(input_class,
-				MKDEV(INPUT_MAJOR, MOUSEDEV_MINOR_BASE + minor),
-				dev->dev, "mouse%d", minor);
+	class_device_create(input_class,
+			MKDEV(INPUT_MAJOR, MOUSEDEV_MINOR_BASE + minor),
+			dev->dev, "mouse%d", minor);
 
 	return &mousedev->handle;
 }
@@ -659,7 +659,8 @@ static void mousedev_disconnect(struct i
 	struct mousedev *mousedev = handle->private;
 	struct mousedev_list *list;
 
-	class_simple_device_remove(MKDEV(INPUT_MAJOR, MOUSEDEV_MINOR_BASE + mousedev->minor));
+	class_device_destroy(input_class,
+			MKDEV(INPUT_MAJOR, MOUSEDEV_MINOR_BASE + mousedev->minor));
 	devfs_remove("input/mouse%d", mousedev->minor);
 	mousedev->exist = 0;
 
@@ -735,8 +736,8 @@ static int __init mousedev_init(void)
 
 	devfs_mk_cdev(MKDEV(INPUT_MAJOR, MOUSEDEV_MINOR_BASE + MOUSEDEV_MIX),
 			S_IFCHR|S_IRUGO|S_IWUSR, "input/mice");
-	class_simple_device_add(input_class, MKDEV(INPUT_MAJOR, MOUSEDEV_MINOR_BASE + MOUSEDEV_MIX),
-				NULL, "mice");
+	class_device_create(input_class,
+			MKDEV(INPUT_MAJOR, MOUSEDEV_MINOR_BASE + MOUSEDEV_MIX), NULL, "mice");
 
 #ifdef CONFIG_INPUT_MOUSEDEV_PSAUX
 	if (!(psaux_registered = !misc_register(&psaux_mouse)))
@@ -755,7 +756,8 @@ static void __exit mousedev_exit(void)
 		misc_deregister(&psaux_mouse);
 #endif
 	devfs_remove("input/mice");
-	class_simple_device_remove(MKDEV(INPUT_MAJOR, MOUSEDEV_MINOR_BASE + MOUSEDEV_MIX));
+	class_device_destroy(input_class,
+			MKDEV(INPUT_MAJOR, MOUSEDEV_MINOR_BASE + MOUSEDEV_MIX));
 	input_unregister_handler(&mousedev_handler);
 }
 
drivers/input/tsdev.c +5 -4
@@ -414,9 +414,9 @@ static struct input_handle *tsdev_connec
 			S_IFCHR|S_IRUGO|S_IWUSR, "input/ts%d", minor);
 	devfs_mk_cdev(MKDEV(INPUT_MAJOR, TSDEV_MINOR_BASE + minor + TSDEV_MINORS/2),
 			S_IFCHR|S_IRUGO|S_IWUSR, "input/tsraw%d", minor);
-	class_simple_device_add(input_class,
-				MKDEV(INPUT_MAJOR, TSDEV_MINOR_BASE + minor),
-				dev->dev, "ts%d", minor);
+	class_device_create(input_class,
+			MKDEV(INPUT_MAJOR, TSDEV_MINOR_BASE + minor),
+			dev->dev, "ts%d", minor);
 
 	return &tsdev->handle;
 }
@@ -426,7 +426,8 @@ static void tsdev_disconnect(struct inpu
 	struct tsdev *tsdev = handle->private;
 	struct tsdev_list *list;
 
-	class_simple_device_remove(MKDEV(INPUT_MAJOR, TSDEV_MINOR_BASE + tsdev->minor));
+	class_device_destroy(input_class,
+			MKDEV(INPUT_MAJOR, TSDEV_MINOR_BASE + tsdev->minor));
 	devfs_remove("input/ts%d", tsdev->minor);
 	devfs_remove("input/tsraw%d", tsdev->minor);
 	tsdev->exist = 0;
include/linux/input.h +1 -1
@@ -1015,7 +1015,7 @@ static inline void input_set_abs_params(
 	dev->absbit[LONG(axis)] |= BIT(axis);
 }
 
-extern struct class_simple *input_class;
+extern struct class *input_class;
 
 #endif
 #endif
author
#26 lore raw

PATCH 1/1 class: remove class_simple code, as no one in the tree is using it anymore.

In reply to Greg KH

[PATCH] class: remove class_simple code, as no one in the tree is using it anymore.

---
commit cd987d38cc59053e0bab8150ffaca33b109067f3
tree 68cf99616bd548bff80ca12f37912d9cc4b31edd
parent 2fc68447df5c76cf254037047b4b02551bd5d760
author [email protected] <[email protected]> Wed, 23 Mar 2005 11:12:38 -0800 committer Greg Kroah-Hartman <[email protected]> Mon, 20 Jun 2005 15:15:11 -0700

 drivers/base/Makefile       |    2 
 drivers/base/class_simple.c |  199 -------------------------------------------
 include/linux/device.h      |   10 --
 3 files changed, 1 insertions(+), 210 deletions(-)
drivers/base/Makefile +1 -1
@@ -1,7 +1,7 @@
 # Makefile for the Linux device tree
 
 obj-y			:= core.o sys.o bus.o \
-			   driver.o class.o class_simple.o platform.o \
+			   driver.o class.o platform.o \
 			   cpu.o firmware.o init.o map.o dmapool.o \
 			   attribute_container.o transport_class.o
 obj-y			+= power/
drivers/base/class_simple.c deleted +0 -199

199 lines not on this page · raw message

include/linux/device.h +0 -10
@@ -44,7 +44,6 @@ struct device;
 struct device_driver;
 struct class;
 struct class_device;
-struct class_simple;
 
 struct bus_type {
 	const char		* name;
@@ -254,15 +253,6 @@ extern struct class_device *class_device
 					__attribute__((format(printf,4,5)));
 extern void class_device_destroy(struct class *cls, dev_t devt);
 
-/* interface for class simple stuff */
-extern struct class_simple *class_simple_create(struct module *owner, char *name);
-extern void class_simple_destroy(struct class_simple *cs);
-extern struct class_device *class_simple_device_add(struct class_simple *cs, dev_t dev, struct device *device, const char *fmt, ...)
-	__attribute__((format(printf,4,5)));
-extern int class_simple_set_hotplug(struct class_simple *, 
-	int (*hotplug)(struct class_device *dev, char **envp, int num_envp, char *buffer, int buffer_size));
-extern void class_simple_device_remove(dev_t dev);
-
 
 struct device {
 	struct list_head node;		/* node in sibling list */
author
#64 lore raw

PATCH 1/1 libfs: add simple attribute files

In reply to Greg KH

[PATCH] libfs: add simple attribute files

Based on the discussion about spufs attributes, this is my suggestion for a more generic attribute file support that can be used by both debugfs and spufs.

Simple attribute files behave similarly to sequential files from a kernel programmers perspective in that a standard set of file operations is provided and only an open operation needs to be written that registers file specific get() and set() functions.

These operations are defined as

void foo_set(void *data, u64 val); and
u64 foo_get(void *data);

where data is the inode->u.generic_ip pointer of the file and the operations just need to make send of that pointer. The infrastructure makes sure this works correctly with concurrent access and partial read calls.

A macro named DEFINE_SIMPLE_ATTRIBUTE is provided to further simplify using the attributes.

This patch already contains the changes for debugfs to use attributes for its internal file operations.

---
commit acaefc25d21f850e47ecc5098d1e0bc442c526be
tree fbc7aa605c71667507b54d3b3320f9a999458dd4
parent 4109aca06cb7b042ea791d0f9d3c9615bc3bf5cd
author Arnd Bergmann <[email protected]> Wed, 18 May 2005 14:40:59 +0200 committer Greg Kroah-Hartman <[email protected]> Mon, 20 Jun 2005 15:15:30 -0700

 fs/debugfs/file.c  |   67 +++++++++++++++--------------------
 fs/libfs.c         |  100 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 include/linux/fs.h |   46 ++++++++++++++++++++++++
 3 files changed, 175 insertions(+), 38 deletions(-)
fs/debugfs/file.c +29 -38
@@ -45,44 +45,15 @@ struct file_operations debugfs_file_oper
 	.open =		default_open,
 };
 
-#define simple_type(type, format, temptype, strtolfn)				\
-static ssize_t read_file_##type(struct file *file, char __user *user_buf,	\
-				size_t count, loff_t *ppos)			\
-{										\
-	char buf[32];								\
-	type *val = file->private_data;						\
-										\
-	snprintf(buf, sizeof(buf), format "\n", *val);				\
-	return simple_read_from_buffer(user_buf, count, ppos, buf, strlen(buf));\
-}										\
-static ssize_t write_file_##type(struct file *file, const char __user *user_buf,\
-				 size_t count, loff_t *ppos)			\
-{										\
-	char *endp;								\
-	char buf[32];								\
-	int buf_size;								\
-	type *val = file->private_data;						\
-	temptype tmp;								\
-										\
-	memset(buf, 0x00, sizeof(buf));						\
-	buf_size = min(count, (sizeof(buf)-1));					\
-	if (copy_from_user(buf, user_buf, buf_size))				\
-		return -EFAULT;							\
-										\
-	tmp = strtolfn(buf, &endp, 0);						\
-	if ((endp == buf) || ((type)tmp != tmp))				\
-		return -EINVAL;							\
-	*val = tmp;								\
-	return count;								\
-}										\
-static struct file_operations fops_##type = {					\
-	.read =		read_file_##type,					\
-	.write =	write_file_##type,					\
-	.open =		default_open,						\
-};
-simple_type(u8, "%c", unsigned long, simple_strtoul);
-simple_type(u16, "%hi", unsigned long, simple_strtoul);
-simple_type(u32, "%i", unsigned long, simple_strtoul);
+static void debugfs_u8_set(void *data, u64 val)
+{
+	*(u8 *)data = val;
+}
+static u64 debugfs_u8_get(void *data)
+{
+	return *(u8 *)data;
+}
+DEFINE_SIMPLE_ATTRIBUTE(fops_u8, debugfs_u8_get, debugfs_u8_set, "%llu\n");
 
 /**
  * debugfs_create_u8 - create a file in the debugfs filesystem that is used to read and write a unsigned 8 bit value.
@@ -116,6 +87,16 @@ struct dentry *debugfs_create_u8(const c
 }
 EXPORT_SYMBOL_GPL(debugfs_create_u8);
 
+static void debugfs_u16_set(void *data, u64 val)
+{
+	*(u16 *)data = val;
+}
+static u64 debugfs_u16_get(void *data)
+{
+	return *(u16 *)data;
+}
+DEFINE_SIMPLE_ATTRIBUTE(fops_u16, debugfs_u16_get, debugfs_u16_set, "%llu\n");
+
 /**
  * debugfs_create_u16 - create a file in the debugfs filesystem that is used to read and write a unsigned 8 bit value.
  *
@@ -148,6 +129,16 @@ struct dentry *debugfs_create_u16(const 
 }
 EXPORT_SYMBOL_GPL(debugfs_create_u16);
 
+static void debugfs_u32_set(void *data, u64 val)
+{
+	*(u32 *)data = val;
+}
+static u64 debugfs_u32_get(void *data)
+{
+	return *(u32 *)data;
+}
+DEFINE_SIMPLE_ATTRIBUTE(fops_u32, debugfs_u32_get, debugfs_u32_set, "%llu\n");
+
 /**
  * debugfs_create_u32 - create a file in the debugfs filesystem that is used to read and write a unsigned 8 bit value.
  *
fs/libfs.c +100 -0

109 lines not on this page · raw message

include/linux/fs.h +46 -0

52 lines not on this page · raw message

author
#10 lore raw

PATCH 1/1 sysfs: (driver/block) if show/store is missing return -EIO

In reply to Greg KH

[PATCH] sysfs: (driver/block) if show/store is missing return -EIO

sysfs: fix drivers/block so if an attribute doesn't implement
show or store method read/write will return -EIO instead of 0 or -EINVAL.

---
commit 6c1852a08e444a2e66367352a99c0e93c8bf3e97
tree ffa075f75b7eb0e5b1399aeb8e34e6cf9a631a10
parent fc7e4828995d8c9e4c9597f8a19179e4ab53f73e
author Dmitry Torokhov <[email protected]> Fri, 29 Apr 2005 01:26:06 -0500 committer Greg Kroah-Hartman <[email protected]> Mon, 20 Jun 2005 15:15:03 -0700

 drivers/block/as-iosched.c       |    4 ++--
 drivers/block/cfq-iosched.c      |    4 ++--
 drivers/block/deadline-iosched.c |    4 ++--
 drivers/block/genhd.c            |    2 +-
 drivers/block/ll_rw_blk.c        |    4 ++--
 5 files changed, 9 insertions(+), 9 deletions(-)
drivers/block/as-iosched.c +2 -2
@@ -2044,7 +2044,7 @@ as_attr_show(struct kobject *kobj, struc
 	struct as_fs_entry *entry = to_as(attr);
 
 	if (!entry->show)
-		return 0;
+		return -EIO;
 
 	return entry->show(e->elevator_data, page);
 }
@@ -2057,7 +2057,7 @@ as_attr_store(struct kobject *kobj, stru
 	struct as_fs_entry *entry = to_as(attr);
 
 	if (!entry->store)
-		return -EINVAL;
+		return -EIO;
 
 	return entry->store(e->elevator_data, page, length);
 }
drivers/block/cfq-iosched.c +2 -2
@@ -1775,7 +1775,7 @@ cfq_attr_show(struct kobject *kobj, stru
 	struct cfq_fs_entry *entry = to_cfq(attr);
 
 	if (!entry->show)
-		return 0;
+		return -EIO;
 
 	return entry->show(e->elevator_data, page);
 }
@@ -1788,7 +1788,7 @@ cfq_attr_store(struct kobject *kobj, str
 	struct cfq_fs_entry *entry = to_cfq(attr);
 
 	if (!entry->store)
-		return -EINVAL;
+		return -EIO;
 
 	return entry->store(e->elevator_data, page, length);
 }
drivers/block/deadline-iosched.c +2 -2
@@ -886,7 +886,7 @@ deadline_attr_show(struct kobject *kobj,
 	struct deadline_fs_entry *entry = to_deadline(attr);
 
 	if (!entry->show)
-		return 0;
+		return -EIO;
 
 	return entry->show(e->elevator_data, page);
 }
@@ -899,7 +899,7 @@ deadline_attr_store(struct kobject *kobj
 	struct deadline_fs_entry *entry = to_deadline(attr);
 
 	if (!entry->store)
-		return -EINVAL;
+		return -EIO;
 
 	return entry->store(e->elevator_data, page, length);
 }
drivers/block/genhd.c +1 -1
@@ -322,7 +322,7 @@ static ssize_t disk_attr_show(struct kob
 	struct gendisk *disk = to_disk(kobj);
 	struct disk_attribute *disk_attr =
 		container_of(attr,struct disk_attribute,attr);
-	ssize_t ret = 0;
+	ssize_t ret = -EIO;
 
 	if (disk_attr->show)
 		ret = disk_attr->show(disk,page);
drivers/block/ll_rw_blk.c +2 -2
@@ -3574,7 +3574,7 @@ queue_attr_show(struct kobject *kobj, st
 
 	q = container_of(kobj, struct request_queue, kobj);
 	if (!entry->show)
-		return 0;
+		return -EIO;
 
 	return entry->show(q, page);
 }
@@ -3588,7 +3588,7 @@ queue_attr_store(struct kobject *kobj, s
 
 	q = container_of(kobj, struct request_queue, kobj);
 	if (!entry->store)
-		return -EINVAL;
+		return -EIO;
 
 	return entry->store(q, page, length);
 }
author
#16 lore raw

PATCH 1/1 USB: move the usb hcd code to use the new class code.

In reply to Greg KH

[PATCH] USB: move the usb hcd code to use the new class code.

This moves a kref into the main hcd structure, which detaches it from the class device structure.

---
commit 8561b10f6e7ef0a085709ffc844f74130a067abe
tree b25d023ce2d7397081735d20fd0c11ebdfcd603c
parent 1235686f6e67cf30c460eb77d90a6cb4be57b92f
author [email protected] <[email protected]> Tue, 15 Mar 2005 15:10:13 -0800 committer Greg Kroah-Hartman <[email protected]> Mon, 20 Jun 2005 15:15:07 -0700

 drivers/usb/core/hcd.c      |   61 +++++++++++++++++++------------------------
 drivers/usb/host/ehci-dbg.c |   10 ++++---
 drivers/usb/host/ohci-dbg.c |   10 ++++---
 include/linux/usb.h         |    5 +---
 4 files changed, 39 insertions(+), 47 deletions(-)
drivers/usb/core/hcd.c +27 -34
@@ -651,50 +651,45 @@ static int usb_rh_urb_dequeue (struct us
 /*-------------------------------------------------------------------------*/
 
 /* exported only within usbcore */
-struct usb_bus *usb_bus_get (struct usb_bus *bus)
+struct usb_bus *usb_bus_get(struct usb_bus *bus)
 {
-	struct class_device *tmp;
+	if (bus)
+		kref_get(&bus->kref);
+	return bus;
+}
 
-	if (!bus)
-		return NULL;
+static void usb_host_release(struct kref *kref)
+{
+	struct usb_bus *bus = container_of(kref, struct usb_bus, kref);
 
-	tmp = class_device_get(&bus->class_dev);
-	if (tmp)        
-		return to_usb_bus(tmp);
-	else
-		return NULL;
+	if (bus->release)
+		bus->release(bus);
 }
 
 /* exported only within usbcore */
-void usb_bus_put (struct usb_bus *bus)
+void usb_bus_put(struct usb_bus *bus)
 {
 	if (bus)
-		class_device_put(&bus->class_dev);
+		kref_put(&bus->kref, usb_host_release);
 }
 
 /*-------------------------------------------------------------------------*/
 
-static void usb_host_release(struct class_device *class_dev)
-{
-	struct usb_bus *bus = to_usb_bus(class_dev);
-
-	if (bus->release)
-		bus->release(bus);
-}
-
-static struct class usb_host_class = {
-	.name		= "usb_host",
-	.release	= &usb_host_release,
-};
+static struct class *usb_host_class;
 
 int usb_host_init(void)
 {
-	return class_register(&usb_host_class);
+	int retval = 0;
+
+	usb_host_class = class_create(THIS_MODULE, "usb_host");
+	if (IS_ERR(usb_host_class))
+		retval = PTR_ERR(usb_host_class);
+	return retval;
 }
 
 void usb_host_cleanup(void)
 {
-	class_unregister(&usb_host_class);
+	class_destroy(usb_host_class);
 }
 
 /**
@@ -719,8 +714,7 @@ static void usb_bus_init (struct usb_bus
 
 	INIT_LIST_HEAD (&bus->bus_list);
 
-	class_device_initialize(&bus->class_dev);
-	bus->class_dev.class = &usb_host_class;
+	kref_init(&bus->kref);
 }
 
 /**
@@ -761,7 +755,6 @@ struct usb_bus *usb_alloc_bus (struct us
 static int usb_register_bus(struct usb_bus *bus)
 {
 	int busnum;
-	int retval;
 
 	down (&usb_bus_list_lock);
 	busnum = find_next_zero_bit (busmap.busmap, USB_MAXBUS, 1);
@@ -774,15 +767,15 @@ static int usb_register_bus(struct usb_b
 		return -E2BIG;
 	}
 
-	snprintf(bus->class_dev.class_id, BUS_ID_SIZE, "usb%d", busnum);
-	bus->class_dev.dev = bus->controller;
-	retval = class_device_add(&bus->class_dev);
-	if (retval) {
+	bus->class_dev = class_device_create(usb_host_class, MKDEV(0,0), bus->controller, "usb%d", busnum);
+	if (IS_ERR(bus->class_dev)) {
 		clear_bit(busnum, busmap.busmap);
 		up(&usb_bus_list_lock);
-		return retval;
+		return PTR_ERR(bus->class_dev);
 	}
 
+	class_set_devdata(bus->class_dev, bus);
+
 	/* Add it to the local list of buses */
 	list_add (&bus->bus_list, &usb_bus_list);
 	up (&usb_bus_list_lock);
@@ -820,7 +813,7 @@ static void usb_deregister_bus (struct u
 
 	clear_bit (bus->busnum, busmap.busmap);
 
-	class_device_del(&bus->class_dev);
+	class_device_unregister(bus->class_dev);
 }
 
 /**
drivers/usb/host/ehci-dbg.c +5 -5
@@ -450,7 +450,7 @@ show_async (struct class_device *class_d
 
 	*buf = 0;
 
-	bus = to_usb_bus(class_dev);
+	bus = class_get_devdata(class_dev);
 	hcd = bus->hcpriv;
 	ehci = hcd_to_ehci (hcd);
 	next = buf;
@@ -496,7 +496,7 @@ show_periodic (struct class_device *clas
 		return 0;
 	seen_count = 0;
 
-	bus = to_usb_bus(class_dev);
+	bus = class_get_devdata(class_dev);
 	hcd = bus->hcpriv;
 	ehci = hcd_to_ehci (hcd);
 	next = buf;
@@ -633,7 +633,7 @@ show_registers (struct class_device *cla
 	static char		fmt [] = "%*s\n";
 	static char		label [] = "";
 
-	bus = to_usb_bus(class_dev);
+	bus = class_get_devdata(class_dev);
 	hcd = bus->hcpriv;
 	ehci = hcd_to_ehci (hcd);
 	next = buf;
@@ -735,7 +735,7 @@ static CLASS_DEVICE_ATTR (registers, S_I
 
 static inline void create_debug_files (struct ehci_hcd *ehci)
 {
-	struct class_device *cldev = &ehci_to_hcd(ehci)->self.class_dev;
+	struct class_device *cldev = ehci_to_hcd(ehci)->self.class_dev;
 
 	class_device_create_file(cldev, &class_device_attr_async);
 	class_device_create_file(cldev, &class_device_attr_periodic);
@@ -744,7 +744,7 @@ static inline void create_debug_files (s
 
 static inline void remove_debug_files (struct ehci_hcd *ehci)
 {
-	struct class_device *cldev = &ehci_to_hcd(ehci)->self.class_dev;
+	struct class_device *cldev = ehci_to_hcd(ehci)->self.class_dev;
 
 	class_device_remove_file(cldev, &class_device_attr_async);
 	class_device_remove_file(cldev, &class_device_attr_periodic);
drivers/usb/host/ohci-dbg.c +5 -5
@@ -481,7 +481,7 @@ show_async (struct class_device *class_d
 	size_t			temp;
 	unsigned long		flags;
 
-	bus = to_usb_bus(class_dev);
+	bus = class_get_devdata(class_dev);
 	hcd = bus->hcpriv;
 	ohci = hcd_to_ohci(hcd);
 
@@ -514,7 +514,7 @@ show_periodic (struct class_device *clas
 		return 0;
 	seen_count = 0;
 
-	bus = to_usb_bus(class_dev);
+	bus = class_get_devdata(class_dev);
 	hcd = bus->hcpriv;
 	ohci = hcd_to_ohci(hcd);
 	next = buf;
@@ -611,7 +611,7 @@ show_registers (struct class_device *cla
 	char			*next;
 	u32			rdata;
 
-	bus = to_usb_bus(class_dev);
+	bus = class_get_devdata(class_dev);
 	hcd = bus->hcpriv;
 	ohci = hcd_to_ohci(hcd);
 	regs = ohci->regs;
@@ -684,7 +684,7 @@ static CLASS_DEVICE_ATTR (registers, S_I
 
 static inline void create_debug_files (struct ohci_hcd *ohci)
 {
-	struct class_device *cldev = &ohci_to_hcd(ohci)->self.class_dev;
+	struct class_device *cldev = ohci_to_hcd(ohci)->self.class_dev;
 
 	class_device_create_file(cldev, &class_device_attr_async);
 	class_device_create_file(cldev, &class_device_attr_periodic);
@@ -694,7 +694,7 @@ static inline void create_debug_files (s
 
 static inline void remove_debug_files (struct ohci_hcd *ohci)
 {
-	struct class_device *cldev = &ohci_to_hcd(ohci)->self.class_dev;
+	struct class_device *cldev = ohci_to_hcd(ohci)->self.class_dev;
 
 	class_device_remove_file(cldev, &class_device_attr_async);
 	class_device_remove_file(cldev, &class_device_attr_periodic);
include/linux/usb.h +2 -3
@@ -287,15 +287,14 @@ struct usb_bus {
 
 	struct dentry *usbfs_dentry;	/* usbfs dentry entry for the bus */
 
-	struct class_device class_dev;	/* class device for this bus */
+	struct class_device *class_dev;	/* class device for this bus */
+	struct kref kref;		/* handles reference counting this bus */
 	void (*release)(struct usb_bus *bus);	/* function to destroy this bus's memory */
 #if defined(CONFIG_USB_MON) || defined(CONFIG_USB_MON_MODULE)
 	struct mon_bus *mon_bus;	/* non-null when associated */
 	int monitored;			/* non-zero when monitored */
 #endif
 };
-#define	to_usb_bus(d) container_of(d, struct usb_bus, class_dev)
-
 
 /* -------------------------------------------------------------------------- */
 
author
#6 lore raw

PATCH 1/1 Make attributes names const char *

In reply to Greg KH

[PATCH] Make attributes names const char *

sysfs: make attributes and attribute_group's names const char *

---
commit d48593bf208e0d046c35fb0707ae5b23fef8c4ff
tree 8ee1375b7c7725c11238716646266d9a6d7fbc9f
parent 8d790d74085833ba2a3e84b5bcd683be4981c29a
author Dmitry Torokhov <[email protected]> Fri, 29 Apr 2005 00:58:46 -0500 committer Greg Kroah-Hartman <[email protected]> Mon, 20 Jun 2005 15:15:01 -0700

 drivers/infiniband/core/sysfs.c |  122 ++++++++++++++++-----------------------
 drivers/pci/pci-sysfs.c         |   13 ++--
 include/linux/sysfs.h           |    4 +
 3 files changed, 59 insertions(+), 80 deletions(-)
drivers/infiniband/core/sysfs.c +50 -72
@@ -40,9 +40,7 @@ struct ib_port {
 	struct kobject         kobj;
 	struct ib_device      *ibdev;
 	struct attribute_group gid_group;
-	struct attribute     **gid_attr;
 	struct attribute_group pkey_group;
-	struct attribute     **pkey_attr;
 	u8                     port_num;
 };
 
@@ -60,8 +58,9 @@ struct port_attribute port_attr_##_name 
 struct port_attribute port_attr_##_name = __ATTR_RO(_name)
 
 struct port_table_attribute {
-	struct port_attribute attr;
-	int                   index;
+	struct port_attribute	attr;
+	char			name[8];
+	int			index;
 };
 
 static ssize_t port_attr_show(struct kobject *kobj,
@@ -398,17 +397,16 @@ static void ib_port_release(struct kobje
 	struct attribute *a;
 	int i;
 
-	for (i = 0; (a = p->gid_attr[i]); ++i) {
-		kfree(a->name);
+	for (i = 0; (a = p->gid_group.attrs[i]); ++i)
 		kfree(a);
-	}
 
-	for (i = 0; (a = p->pkey_attr[i]); ++i) {
-		kfree(a->name);
+	kfree(p->gid_group.attrs);
+
+	for (i = 0; (a = p->pkey_group.attrs[i]); ++i)
 		kfree(a);
-	}
 
-	kfree(p->gid_attr);
+	kfree(p->pkey_group.attrs);
+
 	kfree(p);
 }
 
@@ -449,58 +447,45 @@ static int ib_device_hotplug(struct clas
 	return 0;
 }
 
-static int alloc_group(struct attribute ***attr,
-		       ssize_t (*show)(struct ib_port *,
-				       struct port_attribute *, char *buf),
-		       int len)
+static struct attribute **
+alloc_group_attrs(ssize_t (*show)(struct ib_port *,
+				  struct port_attribute *, char *buf),
+		  int len)
 {
-	struct port_table_attribute ***tab_attr =
-		(struct port_table_attribute ***) attr;
+	struct attribute **tab_attr;
+	struct port_table_attribute *element;
 	int i;
-	int ret;
-
-	*tab_attr = kmalloc((1 + len) * sizeof *tab_attr, GFP_KERNEL);
-	if (!*tab_attr)
-		return -ENOMEM;
 
-	memset(*tab_attr, 0, (1 + len) * sizeof *tab_attr);
-
-	for (i = 0; i < len; ++i) {
-		(*tab_attr)[i] = kmalloc(sizeof *(*tab_attr)[i], GFP_KERNEL);
-		if (!(*tab_attr)[i]) {
-			ret = -ENOMEM;
-			goto err;
-		}
-		memset((*tab_attr)[i], 0, sizeof *(*tab_attr)[i]);
-		(*tab_attr)[i]->attr.attr.name = kmalloc(8, GFP_KERNEL);
-		if (!(*tab_attr)[i]->attr.attr.name) {
-			ret = -ENOMEM;
+	tab_attr = kcalloc(1 + len, sizeof(struct attribute *), GFP_KERNEL);
+	if (!tab_attr)
+		return NULL;
+
+	for (i = 0; i < len; i++) {
+		element = kcalloc(1, sizeof(struct port_table_attribute),
+				  GFP_KERNEL);
+		if (!element)
 			goto err;
-		}
 
-		if (snprintf((*tab_attr)[i]->attr.attr.name, 8, "%d", i) >= 8) {
-			ret = -ENOMEM;
+		if (snprintf(element->name, sizeof(element->name),
+			     "%d", i) >= sizeof(element->name))
 			goto err;
-		}
-
-		(*tab_attr)[i]->attr.attr.mode  = S_IRUGO;
-		(*tab_attr)[i]->attr.attr.owner = THIS_MODULE;
-		(*tab_attr)[i]->attr.show       = show;
-		(*tab_attr)[i]->index           = i;
-	}
 
-	return 0;
+		element->attr.attr.name  = element->name;
+		element->attr.attr.mode  = S_IRUGO;
+		element->attr.attr.owner = THIS_MODULE;
+		element->attr.show       = show;
+		element->index		 = i;
 
-err:
-	for (i = 0; i < len; ++i) {
-		if ((*tab_attr)[i])
-			kfree((*tab_attr)[i]->attr.attr.name);
-		kfree((*tab_attr)[i]);
+		tab_attr[i] = &element->attr.attr;
 	}
 
-	kfree(*tab_attr);
+	return tab_attr;
 
-	return ret;
+err:
+	while (--i >= 0)
+		kfree(tab_attr[i]);
+	kfree(tab_attr);
+	return NULL;
 }
 
 static int add_port(struct ib_device *device, int port_num)
@@ -541,23 +526,20 @@ static int add_port(struct ib_device *de
 	if (ret)
 		goto err_put;
 
-	ret = alloc_group(&p->gid_attr, show_port_gid, attr.gid_tbl_len);
-	if (ret)
-		goto err_remove_pma;
-
 	p->gid_group.name  = "gids";
-	p->gid_group.attrs = p->gid_attr;
+	p->gid_group.attrs = alloc_group_attrs(show_port_gid, attr.gid_tbl_len);
+	if (!p->gid_group.attrs)
+		goto err_remove_pma;
 
 	ret = sysfs_create_group(&p->kobj, &p->gid_group);
 	if (ret)
 		goto err_free_gid;
 
-	ret = alloc_group(&p->pkey_attr, show_port_pkey, attr.pkey_tbl_len);
-	if (ret)
-		goto err_remove_gid;
-
 	p->pkey_group.name  = "pkeys";
-	p->pkey_group.attrs = p->pkey_attr;
+	p->pkey_group.attrs = alloc_group_attrs(show_port_pkey,
+						attr.pkey_tbl_len);
+	if (!p->pkey_group.attrs)
+		goto err_remove_gid;
 
 	ret = sysfs_create_group(&p->kobj, &p->pkey_group);
 	if (ret)
@@ -568,23 +550,19 @@ static int add_port(struct ib_device *de
 	return 0;
 
 err_free_pkey:
-	for (i = 0; i < attr.pkey_tbl_len; ++i) {
-		kfree(p->pkey_attr[i]->name);
-		kfree(p->pkey_attr[i]);
-	}
+	for (i = 0; i < attr.pkey_tbl_len; ++i)
+		kfree(p->pkey_group.attrs[i]);
 
-	kfree(p->pkey_attr);
+	kfree(p->pkey_group.attrs);
 
 err_remove_gid:
 	sysfs_remove_group(&p->kobj, &p->gid_group);
 
 err_free_gid:
-	for (i = 0; i < attr.gid_tbl_len; ++i) {
-		kfree(p->gid_attr[i]->name);
-		kfree(p->gid_attr[i]);
-	}
+	for (i = 0; i < attr.gid_tbl_len; ++i)
+		kfree(p->gid_group.attrs[i]);
 
-	kfree(p->gid_attr);
+	kfree(p->gid_group.attrs);
 
 err_remove_pma:
 	sysfs_remove_group(&p->kobj, &pma_group);
drivers/pci/pci-sysfs.c +7 -6
@@ -339,16 +339,17 @@ pci_create_resource_files(struct pci_dev
 		if (!pci_resource_len(pdev, i))
 			continue;
 
-		res_attr = kmalloc(sizeof(*res_attr) + 10, GFP_ATOMIC);
+		/* allocate attribute structure, piggyback attribute name */
+		res_attr = kcalloc(1, sizeof(*res_attr) + 10, GFP_ATOMIC);
 		if (res_attr) {
-			memset(res_attr, 0, sizeof(*res_attr) + 10);
+			char *res_attr_name = (char *)(res_attr + 1);
+
 			pdev->res_attr[i] = res_attr;
-			/* Allocated above after the res_attr struct */
-			res_attr->attr.name = (char *)(res_attr + 1);
-			sprintf(res_attr->attr.name, "resource%d", i);
-			res_attr->size = pci_resource_len(pdev, i);
+			sprintf(res_attr_name, "resource%d", i);
+			res_attr->attr.name = res_attr_name;
 			res_attr->attr.mode = S_IRUSR | S_IWUSR;
 			res_attr->attr.owner = THIS_MODULE;
+			res_attr->size = pci_resource_len(pdev, i);
 			res_attr->mmap = pci_mmap_resource;
 			res_attr->private = &pdev->resource[i];
 			sysfs_create_bin_file(&pdev->dev.kobj, res_attr);
include/linux/sysfs.h +2 -2
@@ -16,13 +16,13 @@ struct kobject;
 struct module;
 
 struct attribute {
-	char			* name;
+	const char		* name;
 	struct module 		* owner;
 	mode_t			mode;
 };
 
 struct attribute_group {
-	char			* name;
+	const char		* name;
 	struct attribute	** attrs;
 };
 
author
#27 lore raw

PATCH 1/1 fix "make mandocs" after class_simple.c removal

In reply to Greg KH

[PATCH] fix "make mandocs" after class_simple.c removal

Due to the removal of class_simple.c, "make mandocs" no longer works.

This patch fixes this issue.

---
commit 733a366c34aea88def75dee478f92233410ab3c4
tree a122298da923d63cad0837b56c51b69391ac6b8d
parent cd987d38cc59053e0bab8150ffaca33b109067f3
author Adrian Bunk <[email protected]> Thu, 05 May 2005 15:06:38 -0700 committer Greg Kroah-Hartman <[email protected]> Mon, 20 Jun 2005 15:15:12 -0700

 Documentation/DocBook/kernel-api.tmpl |    1 -
 1 files changed, 0 insertions(+), 1 deletions(-)
Documentation/DocBook/kernel-api.tmpl +0 -1
@@ -338,7 +338,6 @@ X!Earch/i386/kernel/mca.c
 X!Iinclude/linux/device.h
 -->
 !Edrivers/base/driver.c
-!Edrivers/base/class_simple.c
 !Edrivers/base/core.c
 !Edrivers/base/firmware_class.c
 !Edrivers/base/transport_class.c
author
#14 lore raw

PATCH 1/1 CLASS: move a "simple" class logic into the class core.

In reply to Greg KH

[PATCH] CLASS: move a "simple" class logic into the class core.

One step on improving the class api so that it can not be used incorrectly. This also fixes the module owner issue with the dev files that happened when the devt logic moved to the class core.

Based on a patch originally written by Kay Sievers <[email protected]>

---
commit e9ba6365fd4f0d9e7d022c883bd044fbaa48257f
tree 062476167b5c9cd5ed08a01f223e71c2ece795ee
parent 70f2817a43c89b784dc2ec3d06ba5bf3064f8235
author [email protected] <[email protected]> Tue, 15 Mar 2005 11:54:21 -0800 committer Greg Kroah-Hartman <[email protected]> Mon, 20 Jun 2005 15:15:04 -0700

 drivers/base/class.c   |  145 ++++++++++++++++++++++++++++++++++++++++++++----
 include/linux/device.h |    9 +++
 2 files changed, 143 insertions(+), 11 deletions(-)
drivers/base/class.c +134 -11
@@ -16,6 +16,7 @@
 #include <linux/init.h>
 #include <linux/string.h>
 #include <linux/kdev_t.h>
+#include <linux/err.h>
 #include "base.h"
 
 #define to_class_attr(_attr) container_of(_attr, struct class_attribute, attr)
@@ -162,6 +163,51 @@ void class_unregister(struct class * cls
 	subsystem_unregister(&cls->subsys);
 }
 
+static void class_create_release(struct class *cls)
+{
+	kfree(cls);
+}
+
+static void class_device_create_release(struct class_device *class_dev)
+{
+	kfree(class_dev);
+}
+
+struct class *class_create(struct module *owner, char *name)
+{
+	struct class *cls;
+	int retval;
+
+	cls = kmalloc(sizeof(struct class), GFP_KERNEL);
+	if (!cls) {
+		retval = -ENOMEM;
+		goto error;
+	}
+	memset(cls, 0x00, sizeof(struct class));
+
+	cls->name = name;
+	cls->owner = owner;
+	cls->class_release = class_create_release;
+	cls->release = class_device_create_release;
+
+	retval = class_register(cls);
+	if (retval)
+		goto error;
+
+	return cls;
+
+error:
+	kfree(cls);
+	return ERR_PTR(retval);
+}
+
+void class_destroy(struct class *cls)
+{
+	if ((cls == NULL) || (IS_ERR(cls)))
+		return;
+
+	class_unregister(cls);
+}
 
 /* Class Device Stuff */
 
@@ -375,7 +421,6 @@ static ssize_t show_dev(struct class_dev
 {
 	return print_dev_t(buf, class_dev->devt);
 }
-static CLASS_DEVICE_ATTR(dev, S_IRUGO, show_dev, NULL);
 
 void class_device_initialize(struct class_device *class_dev)
 {
@@ -412,7 +457,31 @@ int class_device_add(struct class_device
 	if ((error = kobject_add(&class_dev->kobj)))
 		goto register_done;
 
-	/* now take care of our own registration */
+	/* add the needed attributes to this device */
+	if (MAJOR(class_dev->devt)) {
+		struct class_device_attribute *attr;
+		attr = kmalloc(sizeof(*attr), GFP_KERNEL);
+		if (!attr) {
+			error = -ENOMEM;
+			kobject_del(&class_dev->kobj);
+			goto register_done;
+		}
+		memset(attr, sizeof(*attr), 0x00);
+		attr->attr.name = "dev";
+		attr->attr.mode = S_IRUGO;
+		attr->attr.owner = parent->owner;
+		attr->show = show_dev;
+		attr->store = NULL;
+		class_device_create_file(class_dev, attr);
+		class_dev->devt_attr = attr;
+	}
+
+	class_device_add_attrs(class_dev);
+	if (class_dev->dev)
+		sysfs_create_link(&class_dev->kobj,
+				  &class_dev->dev->kobj, "device");
+
+	/* notify any interfaces this device is now here */
 	if (parent) {
 		down(&parent->sem);
 		list_add_tail(&class_dev->node, &parent->children);
@@ -421,16 +490,8 @@ int class_device_add(struct class_device
 				class_intf->add(class_dev);
 		up(&parent->sem);
 	}
-
-	if (MAJOR(class_dev->devt))
-		class_device_create_file(class_dev, &class_device_attr_dev);
-
-	class_device_add_attrs(class_dev);
-	if (class_dev->dev)
-		sysfs_create_link(&class_dev->kobj,
-				  &class_dev->dev->kobj, "device");
-
 	kobject_hotplug(&class_dev->kobj, KOBJ_ADD);
+
  register_done:
 	if (error && parent)
 		class_put(parent);
@@ -444,6 +505,41 @@ int class_device_register(struct class_d
 	return class_device_add(class_dev);
 }
 
+struct class_device *class_device_create(struct class *cls, dev_t devt,
+					 struct device *device, char *fmt, ...)
+{
+	va_list args;
+	struct class_device *class_dev = NULL;
+	int retval = -ENODEV;
+
+	if (cls == NULL || IS_ERR(cls))
+		goto error;
+
+	class_dev = kmalloc(sizeof(struct class_device), GFP_KERNEL);
+	if (!class_dev) {
+		retval = -ENOMEM;
+		goto error;
+	}
+	memset(class_dev, 0x00, sizeof(struct class_device));
+
+	class_dev->devt = devt;
+	class_dev->dev = device;
+	class_dev->class = cls;
+
+	va_start(args, fmt);
+	vsnprintf(class_dev->class_id, BUS_ID_SIZE, fmt, args);
+	va_end(args);
+	retval = class_device_register(class_dev);
+	if (retval)
+		goto error;
+
+	return class_dev;
+
+error:
+	kfree(class_dev);
+	return ERR_PTR(retval);
+}
+
 void class_device_del(struct class_device *class_dev)
 {
 	struct class * parent = class_dev->class;
@@ -460,6 +556,11 @@ void class_device_del(struct class_devic
 
 	if (class_dev->dev)
 		sysfs_remove_link(&class_dev->kobj, "device");
+	if (class_dev->devt_attr) {
+		class_device_remove_file(class_dev, class_dev->devt_attr);
+		kfree(class_dev->devt_attr);
+		class_dev->devt_attr = NULL;
+	}
 	class_device_remove_attrs(class_dev);
 
 	kobject_hotplug(&class_dev->kobj, KOBJ_REMOVE);
@@ -477,6 +578,24 @@ void class_device_unregister(struct clas
 	class_device_put(class_dev);
 }
 
+void class_device_destroy(struct class *cls, dev_t devt)
+{
+	struct class_device *class_dev = NULL;
+	struct class_device *class_dev_tmp;
+
+	down(&cls->sem);
+	list_for_each_entry(class_dev_tmp, &cls->children, node) {
+		if (class_dev_tmp->devt == devt) {
+			class_dev = class_dev_tmp;
+			break;
+		}
+	}
+	up(&cls->sem);
+
+	if (class_dev)
+		class_device_unregister(class_dev);
+}
+
 int class_device_rename(struct class_device *class_dev, char *new_name)
 {
 	int error = 0;
@@ -576,6 +695,8 @@ EXPORT_SYMBOL_GPL(class_register);
 EXPORT_SYMBOL_GPL(class_unregister);
 EXPORT_SYMBOL_GPL(class_get);
 EXPORT_SYMBOL_GPL(class_put);
+EXPORT_SYMBOL_GPL(class_create);
+EXPORT_SYMBOL_GPL(class_destroy);
 
 EXPORT_SYMBOL_GPL(class_device_register);
 EXPORT_SYMBOL_GPL(class_device_unregister);
@@ -584,6 +705,8 @@ EXPORT_SYMBOL_GPL(class_device_add);
 EXPORT_SYMBOL_GPL(class_device_del);
 EXPORT_SYMBOL_GPL(class_device_get);
 EXPORT_SYMBOL_GPL(class_device_put);
+EXPORT_SYMBOL_GPL(class_device_create);
+EXPORT_SYMBOL_GPL(class_device_destroy);
 EXPORT_SYMBOL_GPL(class_device_create_file);
 EXPORT_SYMBOL_GPL(class_device_remove_file);
 EXPORT_SYMBOL_GPL(class_device_create_bin_file);
include/linux/device.h +9 -0
@@ -143,6 +143,7 @@ extern void driver_remove_file(struct de
  */
 struct class {
 	const char		* name;
+	struct module		* owner;
 
 	struct subsystem	subsys;
 	struct list_head	children;
@@ -185,6 +186,7 @@ struct class_device {
 	struct kobject		kobj;
 	struct class		* class;	/* required */
 	dev_t			devt;		/* dev_t, creates the sysfs "dev" */
+	struct class_device_attribute *devt_attr;
 	struct device		* dev;		/* not necessary, but nice to have */
 	void			* class_data;	/* class-specific data */
 
@@ -245,6 +247,13 @@ struct class_interface {
 extern int class_interface_register(struct class_interface *);
 extern void class_interface_unregister(struct class_interface *);
 
+extern struct class *class_create(struct module *owner, char *name);
+extern void class_destroy(struct class *cls);
+extern struct class_device *class_device_create(struct class *cls, dev_t devt,
+						struct device *device, char *fmt, ...)
+					__attribute__((format(printf,4,5)));
+extern void class_device_destroy(struct class *cls, dev_t devt);
+
 /* interface for class simple stuff */
 extern struct class_simple *class_simple_create(struct module *owner, char *name);
 extern void class_simple_destroy(struct class_simple *cs);
author
#24 lore raw

PATCH 1/1 class: convert the remaining class_simple users in the kernel to usee the new class api

In reply to Greg KH

[PATCH] class: convert the remaining class_simple users in the kernel to usee the new class api

---
commit 1db560afe629b682c45a7f4ba7edf98b4ee28518
tree d48ed2d5458b86bf65c78f8e738c6510fdec3917
parent 5cebfb759cc75208c04590ad7f4485cdd822cf46
author [email protected] <[email protected]> Wed, 23 Mar 2005 10:02:26 -0800 committer Greg Kroah-Hartman <[email protected]> Mon, 20 Jun 2005 15:15:11 -0700

 fs/coda/psdev.c |   18 +++++++++---------
 1 files changed, 9 insertions(+), 9 deletions(-)
fs/coda/psdev.c +9 -9
@@ -61,7 +61,7 @@ unsigned long coda_timeout = 30; /* .. s
 
 
 struct venus_comm coda_comms[MAX_CODADEVS];
-static struct class_simple *coda_psdev_class;
+static struct class *coda_psdev_class;
 
 /*
  * Device operations
@@ -363,14 +363,14 @@ static int init_coda_psdev(void)
 		     CODA_PSDEV_MAJOR);
               return -EIO;
 	}
-	coda_psdev_class = class_simple_create(THIS_MODULE, "coda");
+	coda_psdev_class = class_create(THIS_MODULE, "coda");
 	if (IS_ERR(coda_psdev_class)) {
 		err = PTR_ERR(coda_psdev_class);
 		goto out_chrdev;
 	}		
 	devfs_mk_dir ("coda");
 	for (i = 0; i < MAX_CODADEVS; i++) {
-		class_simple_device_add(coda_psdev_class, MKDEV(CODA_PSDEV_MAJOR,i), 
+		class_device_create(coda_psdev_class, MKDEV(CODA_PSDEV_MAJOR,i),
 				NULL, "cfs%d", i);
 		err = devfs_mk_cdev(MKDEV(CODA_PSDEV_MAJOR, i),
 				S_IFCHR|S_IRUSR|S_IWUSR, "coda/%d", i);
@@ -382,8 +382,8 @@ static int init_coda_psdev(void)
 
 out_class:
 	for (i = 0; i < MAX_CODADEVS; i++) 
-		class_simple_device_remove(MKDEV(CODA_PSDEV_MAJOR, i));
-	class_simple_destroy(coda_psdev_class);
+		class_device_destroy(coda_psdev_class, MKDEV(CODA_PSDEV_MAJOR, i));
+	class_destroy(coda_psdev_class);
 out_chrdev:
 	unregister_chrdev(CODA_PSDEV_MAJOR, "coda");
 out:
@@ -425,10 +425,10 @@ static int __init init_coda(void)
 	return 0;
 out:
 	for (i = 0; i < MAX_CODADEVS; i++) {
-		class_simple_device_remove(MKDEV(CODA_PSDEV_MAJOR, i));
+		class_device_destroy(coda_psdev_class, MKDEV(CODA_PSDEV_MAJOR, i));
 		devfs_remove("coda/%d", i);
 	}
-	class_simple_destroy(coda_psdev_class);
+	class_destroy(coda_psdev_class);
 	devfs_remove("coda");
 	unregister_chrdev(CODA_PSDEV_MAJOR, "coda");
 	coda_sysctl_clean();
@@ -447,10 +447,10 @@ static void __exit exit_coda(void)
                 printk("coda: failed to unregister filesystem\n");
         }
 	for (i = 0; i < MAX_CODADEVS; i++) {
-		class_simple_device_remove(MKDEV(CODA_PSDEV_MAJOR, i));
+		class_device_destroy(coda_psdev_class, MKDEV(CODA_PSDEV_MAJOR, i));
 		devfs_remove("coda/%d", i);
 	}
-	class_simple_destroy(coda_psdev_class);
+	class_destroy(coda_psdev_class);
 	devfs_remove("coda");
 	unregister_chrdev(CODA_PSDEV_MAJOR, "coda");
 	coda_sysctl_clean();

Greg KH

author
#0 lore raw

PATCH 1/1 Driver core changes for 2.6.12

Loads of fun stuff in this patch series (86 patches in all). They can all be broken down into the following categories:
- driver core locking rework (added klists)
- class_simple rework (removing it and moving that api to be the main class api)
- sysfs attribute change for driver attributes (gets another parameter on all attributes).
- const marking for some driver core structures
- persistent permissions and owners for sysfs files
- misc sysfs and driver core changes and fixes.

Due to some of the driver core apis changing, it has required all users of these functions to also change. That accounts for the large size in these patches, and why they touch so many different files. If you want me to break these down into the individual categories (one per pull), I would be glad to do so.

All of these have been in the -mm tree for a few months.

Please pull from:
rsync://rsync.kernel.org/pub/scm/linux/kernel/git/gregkh/driver-2.6.git/
or if master.kernel.org hasn't synced up yet (seems like the git trees are killing the mirror functions), use the following directory on master.kernel.org:

	/pub/scm/linux/kernel/git/gregkh/driver-2.6.git/

The full patch series will sent to the linux-kernel mailing list, if anyone wants to see them.

thanks,

greg k-h

 Documentation/DocBook/kernel-api.tmpl    |    1 
 Documentation/driver-model/device.txt    |    8 
 Documentation/driver-model/driver.txt    |   51 +-
 Documentation/filesystems/sysfs.txt      |    2 
 arch/arm/common/amba.c                   |    2 
 arch/arm/kernel/ecard.c                  |   12 
 arch/arm26/kernel/ecard.c                |   10 
 arch/i386/kernel/cpuid.c                 |   22 -
 arch/i386/kernel/msr.c                   |   22 -
 arch/ia64/sn/kernel/tiocx.c              |   25 -
 arch/parisc/kernel/drivers.c             |    2 
 arch/ppc/kernel/pci.c                    |    2 
 arch/ppc/syslib/ocp.c                    |    2 
 arch/ppc/syslib/of_device.c              |    2 
 arch/ppc64/kernel/of_device.c            |    2 
 arch/ppc64/kernel/pci.c                  |    2 
 arch/ppc64/kernel/vio.c                  |    4 
 drivers/acpi/scan.c                      |    4 
 drivers/base/Makefile                    |    4 
 drivers/base/base.h                      |    2 
 drivers/base/bus.c                       |  331 +++-------------
 drivers/base/class.c                     |  194 ++++++++-
 drivers/base/class_simple.c              |  199 ---------
 drivers/base/core.c                      |   64 +--
 drivers/base/dd.c                        |  534 +++++++++++++++++++-------
 drivers/base/dmapool.c                   |    2 
 drivers/base/driver.c                    |   67 ++-
 drivers/base/node.c                      |   20 
 drivers/base/power/resume.c              |    8 
 drivers/base/power/suspend.c             |   16 
 drivers/base/power/sysfs.c               |    4 
 drivers/base/sys.c                       |    4 
 drivers/block/aoe/aoechr.c               |   10 
 drivers/block/as-iosched.c               |    4 
 drivers/block/cfq-iosched.c              |    4 
 drivers/block/deadline-iosched.c         |    4 
 drivers/block/genhd.c                    |    2 
 drivers/block/ll_rw_blk.c                |    4 
 drivers/block/paride/pg.c                |   14 
 drivers/block/paride/pt.c                |   20 
 drivers/block/ub.c                       |    2 
 drivers/char/dsp56k.c                    |   14 
 drivers/char/ftape/zftape/zftape-init.c  |   30 -
 drivers/char/hvcs.c                      |   14 
 drivers/char/ip2main.c                   |   24 -
 drivers/char/ipmi/ipmi_devintf.c         |   14 
 drivers/char/istallion.c                 |   10 
 drivers/char/lp.c                        |   12 
 drivers/char/mbcs.c                      |    4 
 drivers/char/mem.c                       |    7 
 drivers/char/misc.c                      |   16 
 drivers/char/mwave/mwavedd.c             |    2 
 drivers/char/ppdev.c                     |   12 
 drivers/char/raw.c                       |   18 
 drivers/char/snsc.c                      |    9 
 drivers/char/stallion.c                  |   10 
 drivers/char/tipar.c                     |   14 
 drivers/char/tpm/tpm.c                   |    6 
 drivers/char/tty_io.c                    |   16 
 drivers/char/vc_screen.c                 |   16 
 drivers/char/viotape.c                   |   16 
 drivers/cpufreq/cpufreq.c                |    4 
 drivers/dio/dio-sysfs.c                  |   10 
 drivers/eisa/eisa-bus.c                  |    4 
 drivers/firmware/edd.c                   |    2 
 drivers/firmware/efivars.c               |    4 
 drivers/i2c/chips/adm1021.c              |    6 
 drivers/i2c/chips/adm1025.c              |   28 -
 drivers/i2c/chips/adm1026.c              |  622 ++++++++++++++-----------------
 drivers/i2c/chips/adm1031.c              |   44 +-
 drivers/i2c/chips/asb100.c               |   46 +-
 drivers/i2c/chips/ds1621.c               |    6 
 drivers/i2c/chips/fscher.c               |    8 
 drivers/i2c/chips/fscpos.c               |   16 
 drivers/i2c/chips/gl518sm.c              |   12 
 drivers/i2c/chips/gl520sm.c              |    8 
 drivers/i2c/chips/it87.c                 |   50 +-
 drivers/i2c/chips/lm63.c                 |   24 -
 drivers/i2c/chips/lm75.c                 |    4 
 drivers/i2c/chips/lm77.c                 |   14 
 drivers/i2c/chips/lm78.c                 |   36 -
 drivers/i2c/chips/lm80.c                 |   20 
 drivers/i2c/chips/lm83.c                 |    6 
 drivers/i2c/chips/lm85.c                 |   72 +--
 drivers/i2c/chips/lm87.c                 |   46 +-
 drivers/i2c/chips/lm90.c                 |   12 
 drivers/i2c/chips/lm92.c                 |   14 
 drivers/i2c/chips/max1619.c              |    6 
 drivers/i2c/chips/pc87360.c              |   68 +--
 drivers/i2c/chips/pcf8574.c              |    6 
 drivers/i2c/chips/pcf8591.c              |   10 
 drivers/i2c/chips/sis5595.c              |   34 -
 drivers/i2c/chips/smsc47b397.c           |    4 
 drivers/i2c/chips/smsc47m1.c             |   20 
 drivers/i2c/chips/via686a.c              |   32 -
 drivers/i2c/chips/w83627hf.c             |   56 +-
 drivers/i2c/chips/w83781d.c              |   52 +-
 drivers/i2c/chips/w83l785ts.c            |    4 
 drivers/i2c/i2c-core.c                   |    4 
 drivers/ieee1394/dv1394.c                |    6 
 drivers/ieee1394/ieee1394_core.c         |    8 
 drivers/ieee1394/ieee1394_core.h         |    3 
 drivers/ieee1394/nodemgr.c               |   27 -
 drivers/ieee1394/raw1394.c               |   10 
 drivers/ieee1394/sbp2.c                  |    2 
 drivers/ieee1394/video1394.c             |    4 
 drivers/infiniband/core/sysfs.c          |  124 ++----
 drivers/input/evdev.c                    |    9 
 drivers/input/gameport/gameport.c        |    4 
 drivers/input/input.c                    |   10 
 drivers/input/joydev.c                   |    8 
 drivers/input/keyboard/atkbd.c           |    4 
 drivers/input/mouse/psmouse.h            |    4 
 drivers/input/mousedev.c                 |   16 
 drivers/input/serio/serio.c              |   16 
 drivers/input/tsdev.c                    |    9 
 drivers/isdn/capi/capi.c                 |   14 
 drivers/macintosh/adb.c                  |    9 
 drivers/macintosh/therm_adt746x.c        |   11 
 drivers/macintosh/therm_pm72.c           |    4 
 drivers/macintosh/therm_windtunnel.c     |    4 
 drivers/mca/mca-bus.c                    |    4 
 drivers/media/dvb/dvb-core/dvbdev.c      |   13 
 drivers/message/fusion/mptscsih.c        |    2 
 drivers/message/fusion/mptscsih.h        |    2 
 drivers/mmc/mmc_sysfs.c                  |    2 
 drivers/net/ppp_generic.c                |   14 
 drivers/net/wan/cosa.c                   |   12 
 drivers/pci/hotplug/cpqphp_sysfs.c       |    4 
 drivers/pci/hotplug/pci_hotplug_core.c   |    4 
 drivers/pci/hotplug/rpadlpar_sysfs.c     |    2 
 drivers/pci/hotplug/shpchp_sysfs.c       |    4 
 drivers/pci/pci-driver.c                 |   26 -
 drivers/pci/pci-sysfs.c                  |   21 -
 drivers/pci/pcie/portdrv_core.c          |  139 +++---
 drivers/pcmcia/ds.c                      |    4 
 drivers/pnp/card.c                       |    4 
 drivers/pnp/driver.c                     |   12 
 drivers/pnp/interface.c                  |    8 
 drivers/s390/block/dasd_devmap.c         |   10 
 drivers/s390/block/dcssblk.c             |   24 -
 drivers/s390/char/raw3270.c              |    6 
 drivers/s390/char/tape_class.c           |   10 
 drivers/s390/char/tape_core.c            |   10 
 drivers/s390/char/vmlogrdr.c             |   22 -
 drivers/s390/cio/ccwgroup.c              |    6 
 drivers/s390/cio/chsc.c                  |    6 
 drivers/s390/cio/cmf.c                   |   12 
 drivers/s390/cio/device.c                |   14 
 drivers/s390/net/claw.c                  |   40 -
 drivers/s390/net/ctcmain.c               |   18 
 drivers/s390/net/lcs.c                   |   10 
 drivers/s390/net/netiucv.c               |   44 +-
 drivers/s390/net/qeth_sys.c              |  126 +++---
 drivers/s390/scsi/zfcp_scsi.c            |    2 
 drivers/s390/scsi/zfcp_sysfs_adapter.c   |   10 
 drivers/s390/scsi/zfcp_sysfs_port.c      |   10 
 drivers/s390/scsi/zfcp_sysfs_unit.c      |    6 
 drivers/scsi/53c700.c                    |    2 
 drivers/scsi/arm/eesox.c                 |    4 
 drivers/scsi/arm/powertec.c              |    4 
 drivers/scsi/ipr.c                       |    2 
 drivers/scsi/megaraid/megaraid_mbox.c    |    4 
 drivers/scsi/osst.c                      |   10 
 drivers/scsi/scsi_sysfs.c                |   42 +-
 drivers/scsi/scsi_transport_spi.c        |   16 
 drivers/scsi/sg.c                        |   14 
 drivers/scsi/st.c                        |   28 -
 drivers/sh/superhyway/superhyway-sysfs.c |    2 
 drivers/usb/core/devices.c               |    2 
 drivers/usb/core/file.c                  |   13 
 drivers/usb/core/hcd.c                   |   61 +--
 drivers/usb/core/sysfs.c                 |   26 -
 drivers/usb/core/usb.c                   |   59 +-
 drivers/usb/gadget/dummy_hcd.c           |    4 
 drivers/usb/gadget/file_storage.c        |    8 
 drivers/usb/gadget/net2280.c             |    6 
 drivers/usb/gadget/pxa2xx_udc.c          |    2 
 drivers/usb/host/ehci-dbg.c              |   10 
 drivers/usb/host/ohci-dbg.c              |   10 
 drivers/usb/input/aiptek.c               |   78 +--
 drivers/usb/misc/cytherm.c               |   20 
 drivers/usb/misc/phidgetkit.c            |   14 
 drivers/usb/misc/phidgetservo.c          |    4 
 drivers/usb/misc/usbled.c                |    4 
 drivers/usb/serial/ftdi_sio.c            |    6 
 drivers/usb/storage/scsiglue.c           |    4 
 drivers/video/fbmem.c                    |   10 
 drivers/video/gbefb.c                    |    4 
 drivers/video/w100fb.c                   |   12 
 drivers/w1/w1.c                          |   16 
 drivers/w1/w1_family.h                   |    4 
 drivers/w1/w1_smem.c                     |    8 
 drivers/w1/w1_therm.c                    |    8 
 drivers/zorro/zorro-sysfs.c              |    4 
 fs/coda/psdev.c                          |   18 
 fs/debugfs/file.c                        |   67 +--
 fs/libfs.c                               |  100 ++++
 fs/sysfs/bin.c                           |    4 
 fs/sysfs/dir.c                           |   26 -
 fs/sysfs/file.c                          |    6 
 fs/sysfs/inode.c                         |  102 ++++-
 fs/sysfs/mount.c                         |    4 
 fs/sysfs/symlink.c                       |    8 
 fs/sysfs/sysfs.h                         |    4 
 include/asm-ppc/ocp.h                    |    2 
 include/linux/device.h                   |   66 +--
 include/linux/fs.h                       |   46 ++
 include/linux/i2c-sysfs.h                |   36 +
 include/linux/input.h                    |    2 
 include/linux/klist.h                    |   55 ++
 include/linux/kobject.h                  |    8 
 include/linux/node.h                     |    1 
 include/linux/sysfs.h                    |   15 
 include/linux/usb.h                      |    5 
 kernel/params.c                          |    4 
 lib/Makefile                             |    7 
 lib/klist.c                              |  269 +++++++++++++
 lib/kobject.c                            |    2 
 lib/kobject_uevent.c                     |    6 
 security/seclvl.c                        |    4 
 sound/core/sound.c                       |    6 
 sound/oss/soundcard.c                    |   19 
 sound/sound_core.c                       |   10 
 224 files changed, 3194 insertions(+), 2568 deletions(-)

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

Adrian Bunk:
fix "make mandocs" after class_simple.c removal

Alan Stern:
usbcore: Don't call device_release_driver recursively driver core: Fix races in driver_detach()

Andrew Morton:
fix up ipmi code after class_simple.c removal

Arnd Bergmann:
libfs: add simple attribute files

Benjamin Herrenschmidt:
Driver core: Don't "lose" devices on suspend on failure

David Brownell:
Driver Core: driver model doc update

Dmitry Torokhov:
sysfs: (rest) if show/store is missing return -EIO
sysfs: (driver/block) if show/store is missing return -EIO
sysfs: (driver/pci) if show/store is missing return -EIO
sysfs: if show/store is missing return -EIO
sysfs: (driver/base) if show/store is missing return -EIO Make attributes names const char *
make driver's name be const char * kset_hotplug_ops->name shoudl return const char * Make kobject's name be const char * kobject_hotplug() should use kobject_name() sysfs_{create|remove}_link should take const char *

Greg Kroah-Hartman:
PCI: fix show_modalias() function due to attribute change
USB: fix show_modalias() function due to attribute change
Driver core: Fix up the driver and device iterators to be quieter
USB: fix build warning in usb core as pointed out by Andrew.
Use device_for_each_child() to unregister devices in nodemgr_remove_host_dev() driver core: change export symbol for driver_for_each_device()
use device_for_each_child() to properly access child devices.
class: remove class_simple code, as no one in the tree is using it anymore.
class: add kerneldoc for the new class functions.
class: convert the remaining class_simple users in the kernel to usee the new class api
class: convert arch/* to use the new class api instead of class_simple
class: convert drivers/* to use the new class api instead of class_simple
class: convert drivers/scsi/* to use the new class api instead of class_simple
class: convert drivers/char/* to use the new class api instead of class_simple
class: convert drivers/ieee1394/* to use the new class api instead of class_simple
class: convert drivers/block/* to use the new class api instead of class_simple
USB: move the usb hcd code to use the new class code.
class: convert sound/* to use the new class api instead of class_simple
CLASS: move a "simple" class logic into the class core.
tty: move to use the new class code, instead of class_simple
INPUT: move to use the new class code, instead of class_simple

Hannes Reinecke:
driver core: fix error handling in bus_add_device

Jason Uhlenkott:
Fix typo in scdrv_init()

Jon Smirl:
SYSFS: fix PAGE_SIZE check

Keiichiro Tokunaga:
Driver core: unregister_node() for hotplug use

long:
use device_for_each_child() to properly access child devices.

Maneesh Soni:
sysfs-iattr: add sysfs_setattr
sysfs-iattr: set inode attributes
sysfs-iattr: attach sysfs_dirent before new inode

Mark M. Hoffman:
USB: trivial error path fix

Patrick Mochel:
Fix up bogus comment.
Use a klist for device child lists.
Use device_for_each_child() to unregister devices in scsi_remove_target(). Call klist_del() instead of klist_remove().
Don't reference NULL klist pointer in klist_remove().
Remove struct device::bus_list.
Fix up bus code and remove use of rwsem.
Remove struct device::driver_list.
Fix up USB to use klist_node_attached() instead of list_empty() on lists that will go away. add klist_node_attached() to determine if a node is on a list or not.
Use bus_for_each_{dev,drv} for driver binding.
Remove the unused device_find().
Add a klist to struct device_driver for the devices bound to it.
Add initial implementation of klist helpers.
Add a klist to struct bus_type for its devices.
Add a klist to struct bus_type for its drivers.
Add driver_for_each_device().
Use driver_for_each_device() in drivers/pnp/driver.c instead of manually walking list. Use driver_for_each_device() instead of manually walking list.
Move device/driver code to drivers/base/dd.c
Add a semaphore to struct device to synchronize calls to its driver.
sn: fixes due to driver core changes
usb: klist_node_attached() fix
Driver Core: fix bk-driver-core kills ppc64

Yani Ioannou:
I2C: add i2c sensor_device_attribute and macros
I2C: drivers/i2c/chips/adm1026.c: use dynamic sysfs callbacks
Driver Core: include: update device attribute callbacks
Driver Core: drivers/s390/net/qeth_sys.c - drivers/usb/gadget/pxa2xx_udc.c: update device attribute callbacks Driver Core: drivers/usb/input/aiptek.c - drivers/zorro/zorro-sysfs.c: update device attribute callbacks Driver Core: drivers/i2c/chips/w83781d.c - drivers/s390/block/dcssblk.c: update device attribute callbacks Driver Core: drivers/char/raw3270.c - drivers/net/netiucv.c: update device attribute callbacks Driver Core: drivers/i2c/chips/pc87360.c - w83627hf.c: update device attribute callbacks Driver Core: drivers/i2c/chips/lm77.c - max1619.c: update device attribute callbacks
Driver Core: drivers/i2c/chips/adm1031.c - lm75.c: update device attribute callbacks
Driver Core: arch: update device attribute callbacks
Driver Core: drivers/base - drivers/i2c/chips/adm1026.c: update device attribute callbacks Driver core: Documentation: update device attribute callbacks
Driver core: change device_attribute callbacks

#90 lore raw

Re: [PATCH] Add initial implementation of klist helpers.

In reply to Greg KH
Quoted 3 lines · Greg KH

Internally, that routine takes the klist's lock, decrements the reference count of the previous klist_node and increments the count of the next klist_node. It then drops the lock and returns.

Sacrificing performance for scalability has never been the right thing in the past. Why would it be right now?

Signature · 3 lines
The Theory of Escalating Commitment: "The cost of continuing mistakes is
borne by others, while the cost of admitting mistakes is borne by yourself."
  -- Joseph Stiglitz, Nobel Laureate in Economics
#91 lore raw

Re: [PATCH] Add initial implementation of klist helpers.

Quoted 8 lines · Rik van Riel
Quoted 3 lines · Greg KH

Internally, that routine takes the klist's lock, decrements the reference count of the previous klist_node and increments the count of the next klist_node. It then drops the lock and returns.

Sacrificing performance for scalability has never been the right thing in the past. Why would it be right now?

This is not a performance critical piece of code at all. It's used to walk devices and drivers and busses at device insertion and removal time, and at module load and unload. All of which are not bottlenecks in benchmarks :)

Now if people want to use this for performance critical stuff, that would be a different story. But the odds that they would be doing this with kobjects would be very slim...

thanks,

greg k-h

#87 lore raw

Re: [PATCH] Use device_for_each_child() to unregister devices in scsi_remove_target().

In reply to Greg KH

Hi Greg / Patrick -

I'm getting an oops with current (pulled today) 2.6 git, the device_for_each_child() does not seem to be deletion safe.

We hold the klist in place via the n_ref, but the kobj (in the struct device for the struct scsi_target) containing it is freed when the kref->refcount goes to zero.

Any fixes or ?

I haven't found any relevant patches or similar oopses.

The only (current) caller of scsi_remove_target() is in scsi_transport_fc.c, for scsi you could only hit this running with the emulex or qlogic drivers, but it could affect other replacements of list_for_each_entry_safe with device_for_each_child.

The oops:

[linux root]# Oops: Kernel access of bad area, sig: 11 [#1] SMP NR_CPUS=128 NUMA PSERIES LPAR

Modules linked in: qla2300 qla2xxx scsi_transport_fc scsi_mod<7>kobject_get -> c00000001dfde390 kref c00000001dfde3ac mem: 33
 tg3 evdev joydev ipv6 ohci_hcd usbcore dm_mod
NIP: C00000000020C408 XER: 00000000 LR: C000000000394DB8 CTR: C0000000002106D0
REGS: c00000001414b240 TRAP: 0300   Not tainted  (2.6.13-rc1pm)
MSR: 8000000000009032 EE: 1 PR: 0 FP: 0 ME: 1 IR/DR: 11 CR: 24000422
DAR: 6b6b6b6b6b6b6b7b DSISR: 0000000040000000
TASK: c000000002754030[12001] 'rmmod' THREAD: c000000014148000 CPU: 0

GPR00: C000000000394DAC C00000001414B4C0 C0000000005F4618 6B6B6B6B6B6B6B7B
GPR04: 8000000000009032 FFFFFFFFFFFFFFFF 0000000000000037 C0000000005111A4
GPR08: C000000000511198 C000000000514A60 C0000000006024D0 C0000000006023F0
GPR12: 0000000000000010 C0000000004B2000 0000000000000000 0000000010000000
GPR16: 0000000000000000 0000000000000000 0000000010000000 0000000000000000
GPR20: 0000000000000800 0000000000000002 0000000000000880 00000000FFFA7AF0
GPR24: 00000000FFFAA320 0000000010013008 D0000000003D5460 D0000000003D53D8
GPR28: 6B6B6B6B6B6B6B63 C00000001414B5C0 C000000000582FB8 6B6B6B6B6B6B6B6B NIP [c00000000020c408] .kref_get+0x0/0x28
LR [c000000000394db8] .klist_next+0x90/0x104

Call Trace:
[c00000001414b4c0] [c000000000394dac] .klist_next+0x84/0x104 (unreliable)
[c00000001414b550] [c00000000026c8e0] .device_for_each_child+0x7c/0xd0
[c00000001414b600] [d00000000030ac78] .scsi_remove_target+0xa8/0xe8 [scsi_mod]
[c00000001414b690] [d0000000002c6898] .fc_rport_tgt_remove+0xb8/0xdc [scsi_transport_fc]
[c00000001414b720] [d0000000002c6918] .fc_rport_terminate+0x5c/0xf0 [scsi_transport_fc]
[c00000001414b7b0] [d0000000002c6b7c] .fc_remove_host+0x40/0xb8 [scsi_transport_fc]
[c00000001414b830] [d0000000003e6a58] .qla2x00_remove_one+0x34/0x7c [qla2xxx]
[c00000001414b8c0] [d0000000003b7010] .qla2300_remove_one+0x10/0x24 [qla2300]
[c00000001414b940] [c00000000021bc88] .pci_device_remove+0x80/0x88
[c00000001414b9c0] [c00000000026efb0] .__device_release_driver+0xd4/0xdc
[c00000001414ba50] [c00000000026f100] .driver_detach+0x148/0x14c
[c00000001414baf0] [c00000000026e0d8] .bus_remove_driver+0xa0/0x128
[c00000001414bb90] [c00000000026f628] .driver_unregister+0x1c/0x40
[c00000001414bc20] [c00000000021bf58] .pci_unregister_driver+0x24/0xbc
[c00000001414bcb0] [d0000000003b7068] .qla2300_exit+0x1c/0x34 [qla2300]
[c00000001414bd30] [c000000000080014] .sys_delete_module+0x220/0x368
[c00000001414be30] [c00000000000d580] syscall_exit+0x0/0x18

Instruction dump:
4bfffd94 e89e8080 e87e80f0 4be4baad 60000000 4bffff60 e89e8080 e87e80c8 4bffffec 38000001 90030000 4e800020 <81230000> 2fa90000 7c000026 5400fffe

-- Patrick Mansfield

Quoted 56 lines · Greg KH

[PATCH] Use device_for_each_child() to unregister devices in scsi_remove_target().

Index: gregkh-2.6/drivers/scsi/scsi_sysfs.c
===================================================================

---
commit 20b1e674230b642be662c5975923a0160ab9cbdc
tree 749e1384c57576bfbe3ffd1414df321cc783296f
parent 0293a509405dccecc30783a5d729d615b68d6a77
author [email protected] <[email protected]> Thu, 24 Mar 2005 19:03:59 -0800 committer Greg Kroah-Hartman <[email protected]> Mon, 20 Jun 2005 15:15:19 -0700

 drivers/scsi/scsi_sysfs.c |   14 +++++++++-----
 1 files changed, 9 insertions(+), 5 deletions(-)
drivers/scsi/scsi_sysfs.c +9 -5
@@ -669,6 +669,13 @@ void __scsi_remove_target(struct scsi_ta
 	scsi_target_reap(starget);
 }
 
+static int __remove_child (struct device * dev, void * data)
+{
+	if (scsi_is_target_device(dev))
+		__scsi_remove_target(to_scsi_target(dev));
+	return 0;
+}
+
 /**
  * scsi_remove_target - try to remove a target and all its devices
  * @dev: generic starget or parent of generic stargets to be removed
@@ -679,7 +686,7 @@ void __scsi_remove_target(struct scsi_ta
  */
 void scsi_remove_target(struct device *dev)
 {
-	struct device *rdev, *idev, *next;
+	struct device *rdev;
 
 	if (scsi_is_target_device(dev)) {
 		__scsi_remove_target(to_scsi_target(dev));
@@ -687,10 +694,7 @@ void scsi_remove_target(struct device *d
 	}
 
 	rdev = get_device(dev);
-	list_for_each_entry_safe(idev, next, &dev->children, node) {
-		if (scsi_is_target_device(idev))
-			__scsi_remove_target(to_scsi_target(idev));
-	}
+	device_for_each_child(dev, NULL, __remove_child);
 	put_device(rdev);
 }
 EXPORT_SYMBOL(scsi_remove_target);
#88 lore raw

Re: [PATCH] Use device_for_each_child() to unregister devices in scsi_remove_target().

Quoted 8 lines · Patrick Mansfield

Hi Greg / Patrick -

I'm getting an oops with current (pulled today) 2.6 git, the device_for_each_child() does not seem to be deletion safe.

We hold the klist in place via the n_ref, but the kobj (in the struct device for the struct scsi_target) containing it is freed when the kref->refcount goes to zero.

But we grab a reference to that object right before we call device_for_each_child(), right? Or am I missing something here?

thanks,

greg k-h

#89 lore raw

Re: [PATCH] Use device_for_each_child() to unregister devices in scsi_remove_target().

Quoted 6 lines · Greg KH
Quoted 5 lines · Patrick Mansfield

Hi Greg / Patrick -

I'm getting an oops with current (pulled today) 2.6 git, the device_for_each_child() does not seem to be deletion safe.

Quoted 6 lines
Quoted 3 lines

We hold the klist in place via the n_ref, but the kobj (in the struct device for the struct scsi_target) containing it is freed when the kref->refcount goes to zero.

But we grab a reference to that object right before we call device_for_each_child(), right? Or am I missing something here?

No, we get another reference on the passed in dev argument (in this failing case, it is for an FC's rport), not its children (scsi_target) that we want to iterate over.

If all children (scsi_targets) are removed, then the put in scsi_remove_target() would (or could) set the rport refcount to zero and it would be deleted. But the scsi_target would already be gone.

Cases that are not affected are passed a scsi_target:
scsi_is_target_device(dev) is true and we won't even call device_for_each_child().

Adding another get/put in __remove_child() does *not* help either, as it is the code within device_for_each_child() that needs another get/put of the kref instead of a get/put on the klist (well its n_ref); and if you do that, I don't see how the locking can be done correctly.

I thought we had some semaphores in scsi to protect calls to scsi_remove_target(), but I only see those for scsi_device scan/removal (the shost->scan_mutex).

It looks like scsi should not allow removal and additions to happen at the same time on any scsi_target (and adding up/down on shost->scan_mutex won't fix this problem).

-- Patrick Mansfield