Add a class which allows for an easier integration with udev. Signed-off-by: Pete Zaitcev <[EMAIL PROTECTED]>
--- Greg: This patch falls back onto device_create with NULL parent, because of bus0. Obviously, no real USB bus corresponds to it. I thought it not as pretty to have all the real class devices attached, but not the pseudo one. So I'm resubmitting the patch the way it was before you asked us to correct it. I can change it into something like: dev = device_create(mon_bin_class, ubus? ubus->controller: NULL, MKDEV(MAJOR(mon_bin_dev0), minor), "usbmon%d", minor); Seems a bit wrong to me, but please let me know if you think otherwise, I'll resend. As far as I can tell, Paolo doesn't care either way. -- Pete diff -urp -X dontdiff linux-2.6.21-rc6-git5-gregkh/drivers/usb/mon/mon_bin.c linux-2.6.21-rc6-git5-gregkh-mon/drivers/usb/mon/mon_bin.c --- linux-2.6.21-rc6-git5-gregkh/drivers/usb/mon/mon_bin.c 2007-04-12 20:47:18.000000000 -0700 +++ linux-2.6.21-rc6-git5-gregkh-mon/drivers/usb/mon/mon_bin.c 2007-04-12 21:38:20.000000000 -0700 @@ -4,7 +4,7 @@ * This is a binary format reader. * * Copyright (C) 2006 Paolo Abeni ([EMAIL PROTECTED]) - * Copyright (C) 2006 Pete Zaitcev ([EMAIL PROTECTED]) + * Copyright (C) 2006,2007 Pete Zaitcev ([EMAIL PROTECTED]) */ #include <linux/kernel.h> @@ -172,6 +172,7 @@ static inline struct mon_bin_hdr *MON_OF #define MON_RING_EMPTY(rp) ((rp)->b_cnt == 0) +static struct class *mon_bin_class; static dev_t mon_bin_dev0; static struct cdev mon_bin_cdev; @@ -1144,10 +1145,38 @@ static void mon_free_buff(struct mon_pgm free_page((unsigned long) map[n].ptr); } +int mon_bin_add(struct mon_bus *mbus, int busnum) +{ + struct device *dev; + unsigned minor = busnum; + + if (minor >= MON_BIN_MAX_MINOR) + return 0; + + dev = device_create(mon_bin_class, NULL, + MKDEV(MAJOR(mon_bin_dev0), minor), "usbmon%d", minor); + if (IS_ERR(dev)) + return 0; + + mbus->classdev = dev; + return 1; +} + +void mon_bin_del(struct mon_bus *mbus) +{ + device_destroy(mon_bin_class, mbus->classdev->devt); +} + int __init mon_bin_init(void) { int rc; + mon_bin_class = class_create(THIS_MODULE, "usbmon"); + if (IS_ERR(mon_bin_class)) { + rc = PTR_ERR(mon_bin_class); + goto err_class; + } + rc = alloc_chrdev_region(&mon_bin_dev0, 0, MON_BIN_MAX_MINOR, "usbmon"); if (rc < 0) goto err_dev; @@ -1164,6 +1193,8 @@ int __init mon_bin_init(void) err_add: unregister_chrdev_region(mon_bin_dev0, MON_BIN_MAX_MINOR); err_dev: + class_destroy(mon_bin_class); +err_class: return rc; } @@ -1171,4 +1202,5 @@ void mon_bin_exit(void) { cdev_del(&mon_bin_cdev); unregister_chrdev_region(mon_bin_dev0, MON_BIN_MAX_MINOR); + class_destroy(mon_bin_class); } diff -urp -X dontdiff linux-2.6.21-rc6-git5-gregkh/drivers/usb/mon/mon_main.c linux-2.6.21-rc6-git5-gregkh-mon/drivers/usb/mon/mon_main.c --- linux-2.6.21-rc6-git5-gregkh/drivers/usb/mon/mon_main.c 2007-04-12 20:47:18.000000000 -0700 +++ linux-2.6.21-rc6-git5-gregkh-mon/drivers/usb/mon/mon_main.c 2007-04-12 21:38:20.000000000 -0700 @@ -221,6 +221,8 @@ static void mon_bus_remove(struct usb_bu list_del(&mbus->bus_link); if (mbus->text_inited) mon_text_del(mbus); + if (mbus->bin_inited) + mon_bin_del(mbus); mon_dissolve(mbus, ubus); kref_put(&mbus->ref, mon_bus_drop); @@ -303,7 +305,7 @@ static void mon_bus_init(struct usb_bus ubus->mon_bus = mbus; mbus->text_inited = mon_text_add(mbus, ubus->busnum); - // mon_bin_add(...) + mbus->bin_inited = mon_bin_add(mbus, ubus->busnum); mutex_lock(&mon_lock); list_add_tail(&mbus->bus_link, &mon_buses); @@ -323,7 +325,7 @@ static void mon_bus0_init(void) INIT_LIST_HEAD(&mbus->r_list); mbus->text_inited = mon_text_add(mbus, 0); - // mbus->bin_inited = mon_bin_add(mbus, 0); + mbus->bin_inited = mon_bin_add(mbus, 0); } /* @@ -404,6 +406,8 @@ static void __exit mon_exit(void) if (mbus->text_inited) mon_text_del(mbus); + if (mbus->bin_inited) + mon_bin_del(mbus); /* * This never happens, because the open/close paths in @@ -424,6 +428,8 @@ static void __exit mon_exit(void) mbus = &mon_bus0; if (mbus->text_inited) mon_text_del(mbus); + if (mbus->bin_inited) + mon_bin_del(mbus); mutex_unlock(&mon_lock); diff -urp -X dontdiff linux-2.6.21-rc6-git5-gregkh/drivers/usb/mon/usb_mon.h linux-2.6.21-rc6-git5-gregkh-mon/drivers/usb/mon/usb_mon.h --- linux-2.6.21-rc6-git5-gregkh/drivers/usb/mon/usb_mon.h 2007-04-12 20:47:18.000000000 -0700 +++ linux-2.6.21-rc6-git5-gregkh-mon/drivers/usb/mon/usb_mon.h 2007-04-12 21:38:20.000000000 -0700 @@ -20,9 +20,11 @@ struct mon_bus { struct usb_bus *u_bus; int text_inited; + int bin_inited; struct dentry *dent_s; /* Debugging file */ struct dentry *dent_t; /* Text interface file */ struct dentry *dent_u; /* Second text interface file */ + struct device *classdev; /* Device in usbmon class */ /* Ref */ int nreaders; /* Under mon_lock AND mbus->lock */ @@ -54,7 +56,8 @@ struct mon_bus *mon_bus_lookup(unsigned int /*bool*/ mon_text_add(struct mon_bus *mbus, int busnum); void mon_text_del(struct mon_bus *mbus); -// void mon_bin_add(struct mon_bus *); +int /*bool*/ mon_bin_add(struct mon_bus *mbus, int busnum); +void mon_bin_del(struct mon_bus *mbus); int __init mon_text_init(void); void mon_text_exit(void); ------------------------------------------------------------------------- Take Surveys. Earn Cash. Influence the Future of IT Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys-and earn cash http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV _______________________________________________ [EMAIL PROTECTED] To unsubscribe, use the last form field at: https://lists.sourceforge.net/lists/listinfo/linux-usb-devel