diff options
-rw-r--r-- | drivers/usb/core/hcd.c | 61 | ||||
-rw-r--r-- | drivers/usb/host/ehci-dbg.c | 10 | ||||
-rw-r--r-- | drivers/usb/host/ohci-dbg.c | 10 | ||||
-rw-r--r-- | include/linux/usb.h | 5 |
4 files changed, 39 insertions, 47 deletions
diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c index 266e9e06a9f5..d041782e0c8b 100644 --- a/drivers/usb/core/hcd.c +++ b/drivers/usb/core/hcd.c | |||
@@ -651,50 +651,45 @@ static int usb_rh_urb_dequeue (struct usb_hcd *hcd, struct urb *urb) | |||
651 | /*-------------------------------------------------------------------------*/ | 651 | /*-------------------------------------------------------------------------*/ |
652 | 652 | ||
653 | /* exported only within usbcore */ | 653 | /* exported only within usbcore */ |
654 | struct usb_bus *usb_bus_get (struct usb_bus *bus) | 654 | struct usb_bus *usb_bus_get(struct usb_bus *bus) |
655 | { | 655 | { |
656 | struct class_device *tmp; | 656 | if (bus) |
657 | kref_get(&bus->kref); | ||
658 | return bus; | ||
659 | } | ||
657 | 660 | ||
658 | if (!bus) | 661 | static void usb_host_release(struct kref *kref) |
659 | return NULL; | 662 | { |
663 | struct usb_bus *bus = container_of(kref, struct usb_bus, kref); | ||
660 | 664 | ||
661 | tmp = class_device_get(&bus->class_dev); | 665 | if (bus->release) |
662 | if (tmp) | 666 | bus->release(bus); |
663 | return to_usb_bus(tmp); | ||
664 | else | ||
665 | return NULL; | ||
666 | } | 667 | } |
667 | 668 | ||
668 | /* exported only within usbcore */ | 669 | /* exported only within usbcore */ |
669 | void usb_bus_put (struct usb_bus *bus) | 670 | void usb_bus_put(struct usb_bus *bus) |
670 | { | 671 | { |
671 | if (bus) | 672 | if (bus) |
672 | class_device_put(&bus->class_dev); | 673 | kref_put(&bus->kref, usb_host_release); |
673 | } | 674 | } |
674 | 675 | ||
675 | /*-------------------------------------------------------------------------*/ | 676 | /*-------------------------------------------------------------------------*/ |
676 | 677 | ||
677 | static void usb_host_release(struct class_device *class_dev) | 678 | static struct class *usb_host_class; |
678 | { | ||
679 | struct usb_bus *bus = to_usb_bus(class_dev); | ||
680 | |||
681 | if (bus->release) | ||
682 | bus->release(bus); | ||
683 | } | ||
684 | |||
685 | static struct class usb_host_class = { | ||
686 | .name = "usb_host", | ||
687 | .release = &usb_host_release, | ||
688 | }; | ||
689 | 679 | ||
690 | int usb_host_init(void) | 680 | int usb_host_init(void) |
691 | { | 681 | { |
692 | return class_register(&usb_host_class); | 682 | int retval = 0; |
683 | |||
684 | usb_host_class = class_create(THIS_MODULE, "usb_host"); | ||
685 | if (IS_ERR(usb_host_class)) | ||
686 | retval = PTR_ERR(usb_host_class); | ||
687 | return retval; | ||
693 | } | 688 | } |
694 | 689 | ||
695 | void usb_host_cleanup(void) | 690 | void usb_host_cleanup(void) |
696 | { | 691 | { |
697 | class_unregister(&usb_host_class); | 692 | class_destroy(usb_host_class); |
698 | } | 693 | } |
699 | 694 | ||
700 | /** | 695 | /** |
@@ -719,8 +714,7 @@ static void usb_bus_init (struct usb_bus *bus) | |||
719 | 714 | ||
720 | INIT_LIST_HEAD (&bus->bus_list); | 715 | INIT_LIST_HEAD (&bus->bus_list); |
721 | 716 | ||
722 | class_device_initialize(&bus->class_dev); | 717 | kref_init(&bus->kref); |
723 | bus->class_dev.class = &usb_host_class; | ||
724 | } | 718 | } |
725 | 719 | ||
726 | /** | 720 | /** |
@@ -761,7 +755,6 @@ struct usb_bus *usb_alloc_bus (struct usb_operations *op) | |||
761 | static int usb_register_bus(struct usb_bus *bus) | 755 | static int usb_register_bus(struct usb_bus *bus) |
762 | { | 756 | { |
763 | int busnum; | 757 | int busnum; |
764 | int retval; | ||
765 | 758 | ||
766 | down (&usb_bus_list_lock); | 759 | down (&usb_bus_list_lock); |
767 | busnum = find_next_zero_bit (busmap.busmap, USB_MAXBUS, 1); | 760 | busnum = find_next_zero_bit (busmap.busmap, USB_MAXBUS, 1); |
@@ -774,15 +767,15 @@ static int usb_register_bus(struct usb_bus *bus) | |||
774 | return -E2BIG; | 767 | return -E2BIG; |
775 | } | 768 | } |
776 | 769 | ||
777 | snprintf(bus->class_dev.class_id, BUS_ID_SIZE, "usb%d", busnum); | 770 | bus->class_dev = class_device_create(usb_host_class, MKDEV(0,0), bus->controller, "usb%d", busnum); |
778 | bus->class_dev.dev = bus->controller; | 771 | if (IS_ERR(bus->class_dev)) { |
779 | retval = class_device_add(&bus->class_dev); | ||
780 | if (retval) { | ||
781 | clear_bit(busnum, busmap.busmap); | 772 | clear_bit(busnum, busmap.busmap); |
782 | up(&usb_bus_list_lock); | 773 | up(&usb_bus_list_lock); |
783 | return retval; | 774 | return PTR_ERR(bus->class_dev); |
784 | } | 775 | } |
785 | 776 | ||
777 | class_set_devdata(bus->class_dev, bus); | ||
778 | |||
786 | /* Add it to the local list of buses */ | 779 | /* Add it to the local list of buses */ |
787 | list_add (&bus->bus_list, &usb_bus_list); | 780 | list_add (&bus->bus_list, &usb_bus_list); |
788 | up (&usb_bus_list_lock); | 781 | up (&usb_bus_list_lock); |
@@ -820,7 +813,7 @@ static void usb_deregister_bus (struct usb_bus *bus) | |||
820 | 813 | ||
821 | clear_bit (bus->busnum, busmap.busmap); | 814 | clear_bit (bus->busnum, busmap.busmap); |
822 | 815 | ||
823 | class_device_del(&bus->class_dev); | 816 | class_device_unregister(bus->class_dev); |
824 | } | 817 | } |
825 | 818 | ||
826 | /** | 819 | /** |
diff --git a/drivers/usb/host/ehci-dbg.c b/drivers/usb/host/ehci-dbg.c index 9b347d765383..2ff11d53567b 100644 --- a/drivers/usb/host/ehci-dbg.c +++ b/drivers/usb/host/ehci-dbg.c | |||
@@ -450,7 +450,7 @@ show_async (struct class_device *class_dev, char *buf) | |||
450 | 450 | ||
451 | *buf = 0; | 451 | *buf = 0; |
452 | 452 | ||
453 | bus = to_usb_bus(class_dev); | 453 | bus = class_get_devdata(class_dev); |
454 | hcd = bus->hcpriv; | 454 | hcd = bus->hcpriv; |
455 | ehci = hcd_to_ehci (hcd); | 455 | ehci = hcd_to_ehci (hcd); |
456 | next = buf; | 456 | next = buf; |
@@ -496,7 +496,7 @@ show_periodic (struct class_device *class_dev, char *buf) | |||
496 | return 0; | 496 | return 0; |
497 | seen_count = 0; | 497 | seen_count = 0; |
498 | 498 | ||
499 | bus = to_usb_bus(class_dev); | 499 | bus = class_get_devdata(class_dev); |
500 | hcd = bus->hcpriv; | 500 | hcd = bus->hcpriv; |
501 | ehci = hcd_to_ehci (hcd); | 501 | ehci = hcd_to_ehci (hcd); |
502 | next = buf; | 502 | next = buf; |
@@ -633,7 +633,7 @@ show_registers (struct class_device *class_dev, char *buf) | |||
633 | static char fmt [] = "%*s\n"; | 633 | static char fmt [] = "%*s\n"; |
634 | static char label [] = ""; | 634 | static char label [] = ""; |
635 | 635 | ||
636 | bus = to_usb_bus(class_dev); | 636 | bus = class_get_devdata(class_dev); |
637 | hcd = bus->hcpriv; | 637 | hcd = bus->hcpriv; |
638 | ehci = hcd_to_ehci (hcd); | 638 | ehci = hcd_to_ehci (hcd); |
639 | next = buf; | 639 | next = buf; |
@@ -735,7 +735,7 @@ static CLASS_DEVICE_ATTR (registers, S_IRUGO, show_registers, NULL); | |||
735 | 735 | ||
736 | static inline void create_debug_files (struct ehci_hcd *ehci) | 736 | static inline void create_debug_files (struct ehci_hcd *ehci) |
737 | { | 737 | { |
738 | struct class_device *cldev = &ehci_to_hcd(ehci)->self.class_dev; | 738 | struct class_device *cldev = ehci_to_hcd(ehci)->self.class_dev; |
739 | 739 | ||
740 | class_device_create_file(cldev, &class_device_attr_async); | 740 | class_device_create_file(cldev, &class_device_attr_async); |
741 | class_device_create_file(cldev, &class_device_attr_periodic); | 741 | class_device_create_file(cldev, &class_device_attr_periodic); |
@@ -744,7 +744,7 @@ static inline void create_debug_files (struct ehci_hcd *ehci) | |||
744 | 744 | ||
745 | static inline void remove_debug_files (struct ehci_hcd *ehci) | 745 | static inline void remove_debug_files (struct ehci_hcd *ehci) |
746 | { | 746 | { |
747 | struct class_device *cldev = &ehci_to_hcd(ehci)->self.class_dev; | 747 | struct class_device *cldev = ehci_to_hcd(ehci)->self.class_dev; |
748 | 748 | ||
749 | class_device_remove_file(cldev, &class_device_attr_async); | 749 | class_device_remove_file(cldev, &class_device_attr_async); |
750 | class_device_remove_file(cldev, &class_device_attr_periodic); | 750 | class_device_remove_file(cldev, &class_device_attr_periodic); |
diff --git a/drivers/usb/host/ohci-dbg.c b/drivers/usb/host/ohci-dbg.c index 62f53a213808..c58408c95c3d 100644 --- a/drivers/usb/host/ohci-dbg.c +++ b/drivers/usb/host/ohci-dbg.c | |||
@@ -481,7 +481,7 @@ show_async (struct class_device *class_dev, char *buf) | |||
481 | size_t temp; | 481 | size_t temp; |
482 | unsigned long flags; | 482 | unsigned long flags; |
483 | 483 | ||
484 | bus = to_usb_bus(class_dev); | 484 | bus = class_get_devdata(class_dev); |
485 | hcd = bus->hcpriv; | 485 | hcd = bus->hcpriv; |
486 | ohci = hcd_to_ohci(hcd); | 486 | ohci = hcd_to_ohci(hcd); |
487 | 487 | ||
@@ -514,7 +514,7 @@ show_periodic (struct class_device *class_dev, char *buf) | |||
514 | return 0; | 514 | return 0; |
515 | seen_count = 0; | 515 | seen_count = 0; |
516 | 516 | ||
517 | bus = to_usb_bus(class_dev); | 517 | bus = class_get_devdata(class_dev); |
518 | hcd = bus->hcpriv; | 518 | hcd = bus->hcpriv; |
519 | ohci = hcd_to_ohci(hcd); | 519 | ohci = hcd_to_ohci(hcd); |
520 | next = buf; | 520 | next = buf; |
@@ -611,7 +611,7 @@ show_registers (struct class_device *class_dev, char *buf) | |||
611 | char *next; | 611 | char *next; |
612 | u32 rdata; | 612 | u32 rdata; |
613 | 613 | ||
614 | bus = to_usb_bus(class_dev); | 614 | bus = class_get_devdata(class_dev); |
615 | hcd = bus->hcpriv; | 615 | hcd = bus->hcpriv; |
616 | ohci = hcd_to_ohci(hcd); | 616 | ohci = hcd_to_ohci(hcd); |
617 | regs = ohci->regs; | 617 | regs = ohci->regs; |
@@ -684,7 +684,7 @@ static CLASS_DEVICE_ATTR (registers, S_IRUGO, show_registers, NULL); | |||
684 | 684 | ||
685 | static inline void create_debug_files (struct ohci_hcd *ohci) | 685 | static inline void create_debug_files (struct ohci_hcd *ohci) |
686 | { | 686 | { |
687 | struct class_device *cldev = &ohci_to_hcd(ohci)->self.class_dev; | 687 | struct class_device *cldev = ohci_to_hcd(ohci)->self.class_dev; |
688 | 688 | ||
689 | class_device_create_file(cldev, &class_device_attr_async); | 689 | class_device_create_file(cldev, &class_device_attr_async); |
690 | class_device_create_file(cldev, &class_device_attr_periodic); | 690 | class_device_create_file(cldev, &class_device_attr_periodic); |
@@ -694,7 +694,7 @@ static inline void create_debug_files (struct ohci_hcd *ohci) | |||
694 | 694 | ||
695 | static inline void remove_debug_files (struct ohci_hcd *ohci) | 695 | static inline void remove_debug_files (struct ohci_hcd *ohci) |
696 | { | 696 | { |
697 | struct class_device *cldev = &ohci_to_hcd(ohci)->self.class_dev; | 697 | struct class_device *cldev = ohci_to_hcd(ohci)->self.class_dev; |
698 | 698 | ||
699 | class_device_remove_file(cldev, &class_device_attr_async); | 699 | class_device_remove_file(cldev, &class_device_attr_async); |
700 | class_device_remove_file(cldev, &class_device_attr_periodic); | 700 | class_device_remove_file(cldev, &class_device_attr_periodic); |
diff --git a/include/linux/usb.h b/include/linux/usb.h index 2d1ac5058534..3d508bf08402 100644 --- a/include/linux/usb.h +++ b/include/linux/usb.h | |||
@@ -287,15 +287,14 @@ struct usb_bus { | |||
287 | 287 | ||
288 | struct dentry *usbfs_dentry; /* usbfs dentry entry for the bus */ | 288 | struct dentry *usbfs_dentry; /* usbfs dentry entry for the bus */ |
289 | 289 | ||
290 | struct class_device class_dev; /* class device for this bus */ | 290 | struct class_device *class_dev; /* class device for this bus */ |
291 | struct kref kref; /* handles reference counting this bus */ | ||
291 | void (*release)(struct usb_bus *bus); /* function to destroy this bus's memory */ | 292 | void (*release)(struct usb_bus *bus); /* function to destroy this bus's memory */ |
292 | #if defined(CONFIG_USB_MON) || defined(CONFIG_USB_MON_MODULE) | 293 | #if defined(CONFIG_USB_MON) || defined(CONFIG_USB_MON_MODULE) |
293 | struct mon_bus *mon_bus; /* non-null when associated */ | 294 | struct mon_bus *mon_bus; /* non-null when associated */ |
294 | int monitored; /* non-zero when monitored */ | 295 | int monitored; /* non-zero when monitored */ |
295 | #endif | 296 | #endif |
296 | }; | 297 | }; |
297 | #define to_usb_bus(d) container_of(d, struct usb_bus, class_dev) | ||
298 | |||
299 | 298 | ||
300 | /* -------------------------------------------------------------------------- */ | 299 | /* -------------------------------------------------------------------------- */ |
301 | 300 | ||