diff options
-rw-r--r-- | drivers/usb/mon/mon_bin.c | 34 | ||||
-rw-r--r-- | drivers/usb/mon/mon_main.c | 14 | ||||
-rw-r--r-- | drivers/usb/mon/mon_text.c | 29 | ||||
-rw-r--r-- | drivers/usb/mon/usb_mon.h | 7 |
4 files changed, 66 insertions, 18 deletions
diff --git a/drivers/usb/mon/mon_bin.c b/drivers/usb/mon/mon_bin.c index 0af11a66207c..c03dfd7a9d36 100644 --- a/drivers/usb/mon/mon_bin.c +++ b/drivers/usb/mon/mon_bin.c | |||
@@ -4,7 +4,7 @@ | |||
4 | * This is a binary format reader. | 4 | * This is a binary format reader. |
5 | * | 5 | * |
6 | * Copyright (C) 2006 Paolo Abeni (paolo.abeni@email.it) | 6 | * Copyright (C) 2006 Paolo Abeni (paolo.abeni@email.it) |
7 | * Copyright (C) 2006 Pete Zaitcev (zaitcev@redhat.com) | 7 | * Copyright (C) 2006,2007 Pete Zaitcev (zaitcev@redhat.com) |
8 | */ | 8 | */ |
9 | 9 | ||
10 | #include <linux/kernel.h> | 10 | #include <linux/kernel.h> |
@@ -172,6 +172,7 @@ static inline struct mon_bin_hdr *MON_OFF2HDR(const struct mon_reader_bin *rp, | |||
172 | 172 | ||
173 | #define MON_RING_EMPTY(rp) ((rp)->b_cnt == 0) | 173 | #define MON_RING_EMPTY(rp) ((rp)->b_cnt == 0) |
174 | 174 | ||
175 | static struct class *mon_bin_class; | ||
175 | static dev_t mon_bin_dev0; | 176 | static dev_t mon_bin_dev0; |
176 | static struct cdev mon_bin_cdev; | 177 | static struct cdev mon_bin_cdev; |
177 | 178 | ||
@@ -1144,10 +1145,38 @@ static void mon_free_buff(struct mon_pgmap *map, int npages) | |||
1144 | free_page((unsigned long) map[n].ptr); | 1145 | free_page((unsigned long) map[n].ptr); |
1145 | } | 1146 | } |
1146 | 1147 | ||
1148 | int mon_bin_add(struct mon_bus *mbus, const struct usb_bus *ubus) | ||
1149 | { | ||
1150 | struct device *dev; | ||
1151 | unsigned minor = ubus? ubus->busnum: 0; | ||
1152 | |||
1153 | if (minor >= MON_BIN_MAX_MINOR) | ||
1154 | return 0; | ||
1155 | |||
1156 | dev = device_create(mon_bin_class, ubus? ubus->controller: NULL, | ||
1157 | MKDEV(MAJOR(mon_bin_dev0), minor), "usbmon%d", minor); | ||
1158 | if (IS_ERR(dev)) | ||
1159 | return 0; | ||
1160 | |||
1161 | mbus->classdev = dev; | ||
1162 | return 1; | ||
1163 | } | ||
1164 | |||
1165 | void mon_bin_del(struct mon_bus *mbus) | ||
1166 | { | ||
1167 | device_destroy(mon_bin_class, mbus->classdev->devt); | ||
1168 | } | ||
1169 | |||
1147 | int __init mon_bin_init(void) | 1170 | int __init mon_bin_init(void) |
1148 | { | 1171 | { |
1149 | int rc; | 1172 | int rc; |
1150 | 1173 | ||
1174 | mon_bin_class = class_create(THIS_MODULE, "usbmon"); | ||
1175 | if (IS_ERR(mon_bin_class)) { | ||
1176 | rc = PTR_ERR(mon_bin_class); | ||
1177 | goto err_class; | ||
1178 | } | ||
1179 | |||
1151 | rc = alloc_chrdev_region(&mon_bin_dev0, 0, MON_BIN_MAX_MINOR, "usbmon"); | 1180 | rc = alloc_chrdev_region(&mon_bin_dev0, 0, MON_BIN_MAX_MINOR, "usbmon"); |
1152 | if (rc < 0) | 1181 | if (rc < 0) |
1153 | goto err_dev; | 1182 | goto err_dev; |
@@ -1164,6 +1193,8 @@ int __init mon_bin_init(void) | |||
1164 | err_add: | 1193 | err_add: |
1165 | unregister_chrdev_region(mon_bin_dev0, MON_BIN_MAX_MINOR); | 1194 | unregister_chrdev_region(mon_bin_dev0, MON_BIN_MAX_MINOR); |
1166 | err_dev: | 1195 | err_dev: |
1196 | class_destroy(mon_bin_class); | ||
1197 | err_class: | ||
1167 | return rc; | 1198 | return rc; |
1168 | } | 1199 | } |
1169 | 1200 | ||
@@ -1171,4 +1202,5 @@ void mon_bin_exit(void) | |||
1171 | { | 1202 | { |
1172 | cdev_del(&mon_bin_cdev); | 1203 | cdev_del(&mon_bin_cdev); |
1173 | unregister_chrdev_region(mon_bin_dev0, MON_BIN_MAX_MINOR); | 1204 | unregister_chrdev_region(mon_bin_dev0, MON_BIN_MAX_MINOR); |
1205 | class_destroy(mon_bin_class); | ||
1174 | } | 1206 | } |
diff --git a/drivers/usb/mon/mon_main.c b/drivers/usb/mon/mon_main.c index 8977ec0d0f99..ce61d8b0fd86 100644 --- a/drivers/usb/mon/mon_main.c +++ b/drivers/usb/mon/mon_main.c | |||
@@ -220,6 +220,8 @@ static void mon_bus_remove(struct usb_bus *ubus) | |||
220 | list_del(&mbus->bus_link); | 220 | list_del(&mbus->bus_link); |
221 | if (mbus->text_inited) | 221 | if (mbus->text_inited) |
222 | mon_text_del(mbus); | 222 | mon_text_del(mbus); |
223 | if (mbus->bin_inited) | ||
224 | mon_bin_del(mbus); | ||
223 | 225 | ||
224 | mon_dissolve(mbus, ubus); | 226 | mon_dissolve(mbus, ubus); |
225 | kref_put(&mbus->ref, mon_bus_drop); | 227 | kref_put(&mbus->ref, mon_bus_drop); |
@@ -301,8 +303,8 @@ static void mon_bus_init(struct usb_bus *ubus) | |||
301 | mbus->u_bus = ubus; | 303 | mbus->u_bus = ubus; |
302 | ubus->mon_bus = mbus; | 304 | ubus->mon_bus = mbus; |
303 | 305 | ||
304 | mbus->text_inited = mon_text_add(mbus, ubus->busnum); | 306 | mbus->text_inited = mon_text_add(mbus, ubus); |
305 | // mon_bin_add(...) | 307 | mbus->bin_inited = mon_bin_add(mbus, ubus); |
306 | 308 | ||
307 | mutex_lock(&mon_lock); | 309 | mutex_lock(&mon_lock); |
308 | list_add_tail(&mbus->bus_link, &mon_buses); | 310 | list_add_tail(&mbus->bus_link, &mon_buses); |
@@ -321,8 +323,8 @@ static void mon_bus0_init(void) | |||
321 | spin_lock_init(&mbus->lock); | 323 | spin_lock_init(&mbus->lock); |
322 | INIT_LIST_HEAD(&mbus->r_list); | 324 | INIT_LIST_HEAD(&mbus->r_list); |
323 | 325 | ||
324 | mbus->text_inited = mon_text_add(mbus, 0); | 326 | mbus->text_inited = mon_text_add(mbus, NULL); |
325 | // mbus->bin_inited = mon_bin_add(mbus, 0); | 327 | mbus->bin_inited = mon_bin_add(mbus, NULL); |
326 | } | 328 | } |
327 | 329 | ||
328 | /* | 330 | /* |
@@ -403,6 +405,8 @@ static void __exit mon_exit(void) | |||
403 | 405 | ||
404 | if (mbus->text_inited) | 406 | if (mbus->text_inited) |
405 | mon_text_del(mbus); | 407 | mon_text_del(mbus); |
408 | if (mbus->bin_inited) | ||
409 | mon_bin_del(mbus); | ||
406 | 410 | ||
407 | /* | 411 | /* |
408 | * This never happens, because the open/close paths in | 412 | * This never happens, because the open/close paths in |
@@ -423,6 +427,8 @@ static void __exit mon_exit(void) | |||
423 | mbus = &mon_bus0; | 427 | mbus = &mon_bus0; |
424 | if (mbus->text_inited) | 428 | if (mbus->text_inited) |
425 | mon_text_del(mbus); | 429 | mon_text_del(mbus); |
430 | if (mbus->bin_inited) | ||
431 | mon_bin_del(mbus); | ||
426 | 432 | ||
427 | mutex_unlock(&mon_lock); | 433 | mutex_unlock(&mon_lock); |
428 | 434 | ||
diff --git a/drivers/usb/mon/mon_text.c b/drivers/usb/mon/mon_text.c index ec0cc51e39ac..982b773d71e6 100644 --- a/drivers/usb/mon/mon_text.c +++ b/drivers/usb/mon/mon_text.c | |||
@@ -655,20 +655,24 @@ static const struct file_operations mon_fops_text_u = { | |||
655 | .release = mon_text_release, | 655 | .release = mon_text_release, |
656 | }; | 656 | }; |
657 | 657 | ||
658 | int mon_text_add(struct mon_bus *mbus, int busnum) | 658 | int mon_text_add(struct mon_bus *mbus, const struct usb_bus *ubus) |
659 | { | 659 | { |
660 | struct dentry *d; | 660 | struct dentry *d; |
661 | enum { NAMESZ = 10 }; | 661 | enum { NAMESZ = 10 }; |
662 | char name[NAMESZ]; | 662 | char name[NAMESZ]; |
663 | int busnum = ubus? ubus->busnum: 0; | ||
663 | int rc; | 664 | int rc; |
664 | 665 | ||
665 | rc = snprintf(name, NAMESZ, "%dt", busnum); | 666 | if (ubus != NULL) { |
666 | if (rc <= 0 || rc >= NAMESZ) | 667 | rc = snprintf(name, NAMESZ, "%dt", busnum); |
667 | goto err_print_t; | 668 | if (rc <= 0 || rc >= NAMESZ) |
668 | d = debugfs_create_file(name, 0600, mon_dir, mbus, &mon_fops_text_t); | 669 | goto err_print_t; |
669 | if (d == NULL) | 670 | d = debugfs_create_file(name, 0600, mon_dir, mbus, |
670 | goto err_create_t; | 671 | &mon_fops_text_t); |
671 | mbus->dent_t = d; | 672 | if (d == NULL) |
673 | goto err_create_t; | ||
674 | mbus->dent_t = d; | ||
675 | } | ||
672 | 676 | ||
673 | rc = snprintf(name, NAMESZ, "%du", busnum); | 677 | rc = snprintf(name, NAMESZ, "%du", busnum); |
674 | if (rc <= 0 || rc >= NAMESZ) | 678 | if (rc <= 0 || rc >= NAMESZ) |
@@ -694,8 +698,10 @@ err_print_s: | |||
694 | mbus->dent_u = NULL; | 698 | mbus->dent_u = NULL; |
695 | err_create_u: | 699 | err_create_u: |
696 | err_print_u: | 700 | err_print_u: |
697 | debugfs_remove(mbus->dent_t); | 701 | if (ubus != NULL) { |
698 | mbus->dent_t = NULL; | 702 | debugfs_remove(mbus->dent_t); |
703 | mbus->dent_t = NULL; | ||
704 | } | ||
699 | err_create_t: | 705 | err_create_t: |
700 | err_print_t: | 706 | err_print_t: |
701 | return 0; | 707 | return 0; |
@@ -704,7 +710,8 @@ err_print_t: | |||
704 | void mon_text_del(struct mon_bus *mbus) | 710 | void mon_text_del(struct mon_bus *mbus) |
705 | { | 711 | { |
706 | debugfs_remove(mbus->dent_u); | 712 | debugfs_remove(mbus->dent_u); |
707 | debugfs_remove(mbus->dent_t); | 713 | if (mbus->dent_t != NULL) |
714 | debugfs_remove(mbus->dent_t); | ||
708 | debugfs_remove(mbus->dent_s); | 715 | debugfs_remove(mbus->dent_s); |
709 | } | 716 | } |
710 | 717 | ||
diff --git a/drivers/usb/mon/usb_mon.h b/drivers/usb/mon/usb_mon.h index 13d63255283e..f68ad6d99ad7 100644 --- a/drivers/usb/mon/usb_mon.h +++ b/drivers/usb/mon/usb_mon.h | |||
@@ -20,9 +20,11 @@ struct mon_bus { | |||
20 | struct usb_bus *u_bus; | 20 | struct usb_bus *u_bus; |
21 | 21 | ||
22 | int text_inited; | 22 | int text_inited; |
23 | int bin_inited; | ||
23 | struct dentry *dent_s; /* Debugging file */ | 24 | struct dentry *dent_s; /* Debugging file */ |
24 | struct dentry *dent_t; /* Text interface file */ | 25 | struct dentry *dent_t; /* Text interface file */ |
25 | struct dentry *dent_u; /* Second text interface file */ | 26 | struct dentry *dent_u; /* Second text interface file */ |
27 | struct device *classdev; /* Device in usbmon class */ | ||
26 | 28 | ||
27 | /* Ref */ | 29 | /* Ref */ |
28 | int nreaders; /* Under mon_lock AND mbus->lock */ | 30 | int nreaders; /* Under mon_lock AND mbus->lock */ |
@@ -52,9 +54,10 @@ void mon_reader_del(struct mon_bus *mbus, struct mon_reader *r); | |||
52 | 54 | ||
53 | struct mon_bus *mon_bus_lookup(unsigned int num); | 55 | struct mon_bus *mon_bus_lookup(unsigned int num); |
54 | 56 | ||
55 | int /*bool*/ mon_text_add(struct mon_bus *mbus, int busnum); | 57 | int /*bool*/ mon_text_add(struct mon_bus *mbus, const struct usb_bus *ubus); |
56 | void mon_text_del(struct mon_bus *mbus); | 58 | void mon_text_del(struct mon_bus *mbus); |
57 | // void mon_bin_add(struct mon_bus *); | 59 | int /*bool*/ mon_bin_add(struct mon_bus *mbus, const struct usb_bus *ubus); |
60 | void mon_bin_del(struct mon_bus *mbus); | ||
58 | 61 | ||
59 | int __init mon_text_init(void); | 62 | int __init mon_text_init(void); |
60 | void mon_text_exit(void); | 63 | void mon_text_exit(void); |