This patch adds a class which allows for an easier integration with
udev.
 
Signed-off-by: Paolo Abeni <[EMAIL PROTECTED]>
Signed-off-by: Pete Zaitcev <[EMAIL PROTECTED]>

---

The patch is against linux 2.6.21-rc1.

I just changed the struct device creation, using the ubus->controller as
the parent device, as suggested by Greg. Otherwise, is the latest
version posted by Pete.

In the previous post I included two version of this patch. My mistake,
sorry.

diff -uprN linux-2.6.21-rc1/drivers/usb/mon/mon_bin.c 
linux-2.6.21-rc1-mon/drivers/usb/mon/mon_bin.c
--- linux-2.6.21-rc1/drivers/usb/mon/mon_bin.c  2007-02-23 09:57:44.000000000 
+0100
+++ linux-2.6.21-rc1-mon/drivers/usb/mon/mon_bin.c      2007-02-27 
09:58:04.000000000 +0100
@@ -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;
 
@@ -1142,10 +1143,35 @@ static void mon_free_buff(struct mon_pgm
                free_page((unsigned long) map[n].ptr);
 }
 
+int mon_bin_add(struct mon_bus *mbus, const struct usb_bus *ubus)
+{
+       struct device *dev;
+       unsigned minor = ubus->busnum;
+
+       if (minor >= MON_BIN_MAX_MINOR)
+               return 0;
+
+       dev = device_create(mon_bin_class, ubus->controller,
+                       MKDEV(MAJOR(mon_bin_dev0), minor), "usbmon%d", minor);
+       return !IS_ERR(dev);
+}
+
+void mon_bin_del(struct mon_bus *mbus)
+{
+       unsigned minor = mbus->u_bus->busnum;
+       device_destroy(mon_bin_class, MKDEV(MAJOR(mon_bin_dev0), minor));
+}
+
 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;
@@ -1162,6 +1188,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;
 }
 
@@ -1169,4 +1197,5 @@ void __exit 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 -uprN linux-2.6.21-rc1/drivers/usb/mon/mon_main.c 
linux-2.6.21-rc1-mon/drivers/usb/mon/mon_main.c
--- linux-2.6.21-rc1/drivers/usb/mon/mon_main.c 2007-02-23 09:57:44.000000000 
+0100
+++ linux-2.6.21-rc1-mon/drivers/usb/mon/mon_main.c     2007-02-27 
09:34:05.000000000 +0100
@@ -212,6 +212,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);
@@ -298,7 +300,7 @@ static void mon_bus_init(struct usb_bus 
        mbus->uses_dma = ubus->uses_dma;
 
        mbus->text_inited = mon_text_add(mbus, ubus);
-       // mon_bin_add(...)
+       mbus->bin_inited = mon_bin_add(mbus, ubus);
 
        mutex_lock(&mon_lock);
        list_add_tail(&mbus->bus_link, &mon_buses);
@@ -381,6 +383,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
diff -uprN linux-2.6.21-rc1/drivers/usb/mon/usb_mon.h 
linux-2.6.21-rc1-mon/drivers/usb/mon/usb_mon.h
--- linux-2.6.21-rc1/drivers/usb/mon/usb_mon.h  2007-02-23 09:57:44.000000000 
+0100
+++ linux-2.6.21-rc1-mon/drivers/usb/mon/usb_mon.h      2007-02-27 
09:34:05.000000000 +0100
@@ -20,6 +20,7 @@ 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 */
        int uses_dma;
@@ -54,7 +55,8 @@ struct mon_bus *mon_bus_lookup(unsigned 
 
 int /*bool*/ mon_text_add(struct mon_bus *mbus, const struct usb_bus *ubus);
 void mon_text_del(struct mon_bus *mbus);
-// void mon_bin_add(struct mon_bus *);
+int /*bool*/ mon_bin_add(struct mon_bus *mbus, const struct usb_bus *ubus);
+void mon_bin_del(struct mon_bus *mbus);
 
 int __init mon_text_init(void);
 void __exit mon_text_exit(void);


 
 
 --
 Email.it, the professional e-mail, gratis per te: http://www.email.it/f
 
 Sponsor:
 Ti piace la chitarra? Impara a suonarla senza fatica ed evitando tutti gli 
errori, con l'aiuto di un maestro professionista
 Clicca qui: http://adv.email.it/cgi-bin/foclick.cgi?mid=5144&d=28-2

-------------------------------------------------------------------------
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
_______________________________________________
linux-usb-devel@lists.sourceforge.net
To unsubscribe, use the last form field at:
https://lists.sourceforge.net/lists/listinfo/linux-usb-devel

Reply via email to