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]>
---
I just changed the struct device creation, using the ubus->controller for
the parent device, as suggested by Greg. Otherwise, is the latest
version posted by Pete.
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-23
09:46:19.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,38 @@ 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, 0,
+ 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 (!mon_bin_class)
+ {
+ rc = -ENOMEM;
+ goto err_class;
+ }
+
rc = alloc_chrdev_region(&mon_bin_dev0, 0, MON_BIN_MAX_MINOR, "usbmon");
if (rc < 0)
goto err_dev;
@@ -1162,11 +1191,14 @@ 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;
}
void __exit mon_bin_exit(void)
{
+ class_destroy(mon_bin_class);
cdev_del(&mon_bin_cdev);
unregister_chrdev_region(mon_bin_dev0, MON_BIN_MAX_MINOR);
}
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-23
09:38:36.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-23
09:39:17.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);
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:
Crea il tuo sito web dinamico con PHP e MySQL - VideoCorso professionale
direttamente nel tuo computer. Trucchi e segreti
Clicca qui: http://adv.email.it/cgi-bin/foclick.cgi?mid=5142&d=27-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
_______________________________________________
[email protected]
To unsubscribe, use the last form field at:
https://lists.sourceforge.net/lists/listinfo/linux-usb-devel