Commit 54a5c4cd2e4ec0b27c2c3731727f52591456086c
1 parent
a7b986b3e1
Exists in
master
and in
4 other branches
[PATCH] USB: convert usbfs/inode.c to use usb notifiers
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Showing 4 changed files with 31 additions and 28 deletions Side-by-side Diff
drivers/usb/core/hcd.c
| ... | ... | @@ -793,7 +793,6 @@ |
| 793 | 793 | up (&usb_bus_list_lock); |
| 794 | 794 | |
| 795 | 795 | usb_notify_add_bus(bus); |
| 796 | - usbfs_add_bus (bus); | |
| 797 | 796 | usbmon_notify_bus_add (bus); |
| 798 | 797 | |
| 799 | 798 | dev_info (bus->controller, "new USB bus registered, assigned bus number %d\n", bus->busnum); |
| ... | ... | @@ -823,7 +822,6 @@ |
| 823 | 822 | |
| 824 | 823 | usb_notify_remove_bus(bus); |
| 825 | 824 | usbmon_notify_bus_remove (bus); |
| 826 | - usbfs_remove_bus (bus); | |
| 827 | 825 | |
| 828 | 826 | clear_bit (bus->busnum, busmap.busmap); |
| 829 | 827 |
drivers/usb/core/hcd.h
| ... | ... | @@ -400,23 +400,13 @@ |
| 400 | 400 | * these are expected to be called from the USB core/hub thread |
| 401 | 401 | * with the kernel lock held |
| 402 | 402 | */ |
| 403 | -extern void usbfs_add_bus(struct usb_bus *bus); | |
| 404 | -extern void usbfs_remove_bus(struct usb_bus *bus); | |
| 405 | -extern void usbfs_add_device(struct usb_device *dev); | |
| 406 | -extern void usbfs_remove_device(struct usb_device *dev); | |
| 407 | 403 | extern void usbfs_update_special (void); |
| 408 | - | |
| 409 | 404 | extern int usbfs_init(void); |
| 410 | 405 | extern void usbfs_cleanup(void); |
| 411 | 406 | |
| 412 | 407 | #else /* CONFIG_USB_DEVICEFS */ |
| 413 | 408 | |
| 414 | -static inline void usbfs_add_bus(struct usb_bus *bus) {} | |
| 415 | -static inline void usbfs_remove_bus(struct usb_bus *bus) {} | |
| 416 | -static inline void usbfs_add_device(struct usb_device *dev) {} | |
| 417 | -static inline void usbfs_remove_device(struct usb_device *dev) {} | |
| 418 | 409 | static inline void usbfs_update_special (void) {} |
| 419 | - | |
| 420 | 410 | static inline int usbfs_init(void) { return 0; } |
| 421 | 411 | static inline void usbfs_cleanup(void) { } |
| 422 | 412 |
drivers/usb/core/hub.c
| ... | ... | @@ -1136,7 +1136,6 @@ |
| 1136 | 1136 | */ |
| 1137 | 1137 | dev_dbg (&udev->dev, "unregistering device\n"); |
| 1138 | 1138 | release_address(udev); |
| 1139 | - usbfs_remove_device(udev); | |
| 1140 | 1139 | usb_remove_sysfs_dev_files(udev); |
| 1141 | 1140 | |
| 1142 | 1141 | /* Avoid races with recursively_mark_NOTATTACHED() */ |
| ... | ... | @@ -1374,8 +1373,6 @@ |
| 1374 | 1373 | /* USB device state == configured ... usable */ |
| 1375 | 1374 | usb_notify_add_device(udev); |
| 1376 | 1375 | |
| 1377 | - /* add a /proc/bus/usb entry */ | |
| 1378 | - usbfs_add_device(udev); | |
| 1379 | 1376 | return 0; |
| 1380 | 1377 | |
| 1381 | 1378 | fail: |
drivers/usb/core/inode.c
| ... | ... | @@ -39,6 +39,7 @@ |
| 39 | 39 | #include <linux/usbdevice_fs.h> |
| 40 | 40 | #include <linux/smp_lock.h> |
| 41 | 41 | #include <linux/parser.h> |
| 42 | +#include <linux/notifier.h> | |
| 42 | 43 | #include <asm/byteorder.h> |
| 43 | 44 | #include "usb.h" |
| 44 | 45 | #include "hcd.h" |
| ... | ... | @@ -619,7 +620,7 @@ |
| 619 | 620 | } |
| 620 | 621 | } |
| 621 | 622 | |
| 622 | -void usbfs_add_bus(struct usb_bus *bus) | |
| 623 | +static void usbfs_add_bus(struct usb_bus *bus) | |
| 623 | 624 | { |
| 624 | 625 | struct dentry *parent; |
| 625 | 626 | char name[8]; |
| 626 | 627 | |
| ... | ... | @@ -642,12 +643,9 @@ |
| 642 | 643 | err ("error creating usbfs bus entry"); |
| 643 | 644 | return; |
| 644 | 645 | } |
| 645 | - | |
| 646 | - usbfs_update_special(); | |
| 647 | - usbfs_conn_disc_event(); | |
| 648 | 646 | } |
| 649 | 647 | |
| 650 | -void usbfs_remove_bus(struct usb_bus *bus) | |
| 648 | +static void usbfs_remove_bus(struct usb_bus *bus) | |
| 651 | 649 | { |
| 652 | 650 | if (bus->usbfs_dentry) { |
| 653 | 651 | fs_remove_file (bus->usbfs_dentry); |
| 654 | 652 | |
| ... | ... | @@ -659,12 +657,9 @@ |
| 659 | 657 | remove_special_files(); |
| 660 | 658 | num_buses = 0; |
| 661 | 659 | } |
| 662 | - | |
| 663 | - usbfs_update_special(); | |
| 664 | - usbfs_conn_disc_event(); | |
| 665 | 660 | } |
| 666 | 661 | |
| 667 | -void usbfs_add_device(struct usb_device *dev) | |
| 662 | +static void usbfs_add_device(struct usb_device *dev) | |
| 668 | 663 | { |
| 669 | 664 | char name[8]; |
| 670 | 665 | int i; |
| 671 | 666 | |
| ... | ... | @@ -690,12 +685,9 @@ |
| 690 | 685 | } |
| 691 | 686 | if (dev->usbfs_dentry->d_inode) |
| 692 | 687 | dev->usbfs_dentry->d_inode->i_size = i_size; |
| 693 | - | |
| 694 | - usbfs_update_special(); | |
| 695 | - usbfs_conn_disc_event(); | |
| 696 | 688 | } |
| 697 | 689 | |
| 698 | -void usbfs_remove_device(struct usb_device *dev) | |
| 690 | +static void usbfs_remove_device(struct usb_device *dev) | |
| 699 | 691 | { |
| 700 | 692 | struct dev_state *ds; |
| 701 | 693 | struct siginfo sinfo; |
| 702 | 694 | |
| 703 | 695 | |
| ... | ... | @@ -716,10 +708,33 @@ |
| 716 | 708 | kill_proc_info_as_uid(ds->discsignr, &sinfo, ds->disc_pid, ds->disc_uid, ds->disc_euid); |
| 717 | 709 | } |
| 718 | 710 | } |
| 711 | +} | |
| 712 | + | |
| 713 | +static int usbfs_notify(struct notifier_block *self, unsigned long action, void *dev) | |
| 714 | +{ | |
| 715 | + switch (action) { | |
| 716 | + case USB_DEVICE_ADD: | |
| 717 | + usbfs_add_device(dev); | |
| 718 | + break; | |
| 719 | + case USB_DEVICE_REMOVE: | |
| 720 | + usbfs_remove_device(dev); | |
| 721 | + break; | |
| 722 | + case USB_BUS_ADD: | |
| 723 | + usbfs_add_bus(dev); | |
| 724 | + break; | |
| 725 | + case USB_BUS_REMOVE: | |
| 726 | + usbfs_remove_bus(dev); | |
| 727 | + } | |
| 728 | + | |
| 719 | 729 | usbfs_update_special(); |
| 720 | 730 | usbfs_conn_disc_event(); |
| 731 | + return NOTIFY_OK; | |
| 721 | 732 | } |
| 722 | 733 | |
| 734 | +static struct notifier_block usbfs_nb = { | |
| 735 | + .notifier_call = usbfs_notify, | |
| 736 | +}; | |
| 737 | + | |
| 723 | 738 | /* --------------------------------------------------------------------- */ |
| 724 | 739 | |
| 725 | 740 | static struct proc_dir_entry *usbdir = NULL; |
| ... | ... | @@ -732,6 +747,8 @@ |
| 732 | 747 | if (retval) |
| 733 | 748 | return retval; |
| 734 | 749 | |
| 750 | + usb_register_notify(&usbfs_nb); | |
| 751 | + | |
| 735 | 752 | /* create mount point for usbfs */ |
| 736 | 753 | usbdir = proc_mkdir("usb", proc_bus); |
| 737 | 754 | |
| ... | ... | @@ -740,6 +757,7 @@ |
| 740 | 757 | |
| 741 | 758 | void usbfs_cleanup(void) |
| 742 | 759 | { |
| 760 | + usb_unregister_notify(&usbfs_nb); | |
| 743 | 761 | unregister_filesystem(&usb_fs_type); |
| 744 | 762 | if (usbdir) |
| 745 | 763 | remove_proc_entry("usb", proc_bus); |