Commit 8561b10f authored by gregkh@suse.de's avatar gregkh@suse.de Committed by Greg Kroah-Hartman

[PATCH] USB: move the usb hcd code to use the new class code.

This moves a kref into the main hcd structure, which detaches it from
the class device structure.
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@suse.de>
parent 1235686f
...@@ -651,50 +651,45 @@ static int usb_rh_urb_dequeue (struct usb_hcd *hcd, struct urb *urb) ...@@ -651,50 +651,45 @@ static int usb_rh_urb_dequeue (struct usb_hcd *hcd, struct urb *urb)
/*-------------------------------------------------------------------------*/ /*-------------------------------------------------------------------------*/
/* exported only within usbcore */ /* exported only within usbcore */
struct usb_bus *usb_bus_get (struct usb_bus *bus) struct usb_bus *usb_bus_get(struct usb_bus *bus)
{ {
struct class_device *tmp; if (bus)
kref_get(&bus->kref);
return bus;
}
if (!bus) static void usb_host_release(struct kref *kref)
return NULL; {
struct usb_bus *bus = container_of(kref, struct usb_bus, kref);
tmp = class_device_get(&bus->class_dev); if (bus->release)
if (tmp) bus->release(bus);
return to_usb_bus(tmp);
else
return NULL;
} }
/* exported only within usbcore */ /* exported only within usbcore */
void usb_bus_put (struct usb_bus *bus) void usb_bus_put(struct usb_bus *bus)
{ {
if (bus) if (bus)
class_device_put(&bus->class_dev); kref_put(&bus->kref, usb_host_release);
} }
/*-------------------------------------------------------------------------*/ /*-------------------------------------------------------------------------*/
static void usb_host_release(struct class_device *class_dev) static struct class *usb_host_class;
{
struct usb_bus *bus = to_usb_bus(class_dev);
if (bus->release)
bus->release(bus);
}
static struct class usb_host_class = {
.name = "usb_host",
.release = &usb_host_release,
};
int usb_host_init(void) int usb_host_init(void)
{ {
return class_register(&usb_host_class); int retval = 0;
usb_host_class = class_create(THIS_MODULE, "usb_host");
if (IS_ERR(usb_host_class))
retval = PTR_ERR(usb_host_class);
return retval;
} }
void usb_host_cleanup(void) void usb_host_cleanup(void)
{ {
class_unregister(&usb_host_class); class_destroy(usb_host_class);
} }
/** /**
...@@ -719,8 +714,7 @@ static void usb_bus_init (struct usb_bus *bus) ...@@ -719,8 +714,7 @@ static void usb_bus_init (struct usb_bus *bus)
INIT_LIST_HEAD (&bus->bus_list); INIT_LIST_HEAD (&bus->bus_list);
class_device_initialize(&bus->class_dev); kref_init(&bus->kref);
bus->class_dev.class = &usb_host_class;
} }
/** /**
...@@ -761,7 +755,6 @@ struct usb_bus *usb_alloc_bus (struct usb_operations *op) ...@@ -761,7 +755,6 @@ struct usb_bus *usb_alloc_bus (struct usb_operations *op)
static int usb_register_bus(struct usb_bus *bus) static int usb_register_bus(struct usb_bus *bus)
{ {
int busnum; int busnum;
int retval;
down (&usb_bus_list_lock); down (&usb_bus_list_lock);
busnum = find_next_zero_bit (busmap.busmap, USB_MAXBUS, 1); busnum = find_next_zero_bit (busmap.busmap, USB_MAXBUS, 1);
...@@ -774,15 +767,15 @@ static int usb_register_bus(struct usb_bus *bus) ...@@ -774,15 +767,15 @@ static int usb_register_bus(struct usb_bus *bus)
return -E2BIG; return -E2BIG;
} }
snprintf(bus->class_dev.class_id, BUS_ID_SIZE, "usb%d", busnum); bus->class_dev = class_device_create(usb_host_class, MKDEV(0,0), bus->controller, "usb%d", busnum);
bus->class_dev.dev = bus->controller; if (IS_ERR(bus->class_dev)) {
retval = class_device_add(&bus->class_dev);
if (retval) {
clear_bit(busnum, busmap.busmap); clear_bit(busnum, busmap.busmap);
up(&usb_bus_list_lock); up(&usb_bus_list_lock);
return retval; return PTR_ERR(bus->class_dev);
} }
class_set_devdata(bus->class_dev, bus);
/* Add it to the local list of buses */ /* Add it to the local list of buses */
list_add (&bus->bus_list, &usb_bus_list); list_add (&bus->bus_list, &usb_bus_list);
up (&usb_bus_list_lock); up (&usb_bus_list_lock);
...@@ -820,7 +813,7 @@ static void usb_deregister_bus (struct usb_bus *bus) ...@@ -820,7 +813,7 @@ static void usb_deregister_bus (struct usb_bus *bus)
clear_bit (bus->busnum, busmap.busmap); clear_bit (bus->busnum, busmap.busmap);
class_device_del(&bus->class_dev); class_device_unregister(bus->class_dev);
} }
/** /**
......
...@@ -450,7 +450,7 @@ show_async (struct class_device *class_dev, char *buf) ...@@ -450,7 +450,7 @@ show_async (struct class_device *class_dev, char *buf)
*buf = 0; *buf = 0;
bus = to_usb_bus(class_dev); bus = class_get_devdata(class_dev);
hcd = bus->hcpriv; hcd = bus->hcpriv;
ehci = hcd_to_ehci (hcd); ehci = hcd_to_ehci (hcd);
next = buf; next = buf;
...@@ -496,7 +496,7 @@ show_periodic (struct class_device *class_dev, char *buf) ...@@ -496,7 +496,7 @@ show_periodic (struct class_device *class_dev, char *buf)
return 0; return 0;
seen_count = 0; seen_count = 0;
bus = to_usb_bus(class_dev); bus = class_get_devdata(class_dev);
hcd = bus->hcpriv; hcd = bus->hcpriv;
ehci = hcd_to_ehci (hcd); ehci = hcd_to_ehci (hcd);
next = buf; next = buf;
...@@ -633,7 +633,7 @@ show_registers (struct class_device *class_dev, char *buf) ...@@ -633,7 +633,7 @@ show_registers (struct class_device *class_dev, char *buf)
static char fmt [] = "%*s\n"; static char fmt [] = "%*s\n";
static char label [] = ""; static char label [] = "";
bus = to_usb_bus(class_dev); bus = class_get_devdata(class_dev);
hcd = bus->hcpriv; hcd = bus->hcpriv;
ehci = hcd_to_ehci (hcd); ehci = hcd_to_ehci (hcd);
next = buf; next = buf;
...@@ -735,7 +735,7 @@ static CLASS_DEVICE_ATTR (registers, S_IRUGO, show_registers, NULL); ...@@ -735,7 +735,7 @@ static CLASS_DEVICE_ATTR (registers, S_IRUGO, show_registers, NULL);
static inline void create_debug_files (struct ehci_hcd *ehci) static inline void create_debug_files (struct ehci_hcd *ehci)
{ {
struct class_device *cldev = &ehci_to_hcd(ehci)->self.class_dev; struct class_device *cldev = ehci_to_hcd(ehci)->self.class_dev;
class_device_create_file(cldev, &class_device_attr_async); class_device_create_file(cldev, &class_device_attr_async);
class_device_create_file(cldev, &class_device_attr_periodic); class_device_create_file(cldev, &class_device_attr_periodic);
...@@ -744,7 +744,7 @@ static inline void create_debug_files (struct ehci_hcd *ehci) ...@@ -744,7 +744,7 @@ static inline void create_debug_files (struct ehci_hcd *ehci)
static inline void remove_debug_files (struct ehci_hcd *ehci) static inline void remove_debug_files (struct ehci_hcd *ehci)
{ {
struct class_device *cldev = &ehci_to_hcd(ehci)->self.class_dev; struct class_device *cldev = ehci_to_hcd(ehci)->self.class_dev;
class_device_remove_file(cldev, &class_device_attr_async); class_device_remove_file(cldev, &class_device_attr_async);
class_device_remove_file(cldev, &class_device_attr_periodic); class_device_remove_file(cldev, &class_device_attr_periodic);
......
...@@ -481,7 +481,7 @@ show_async (struct class_device *class_dev, char *buf) ...@@ -481,7 +481,7 @@ show_async (struct class_device *class_dev, char *buf)
size_t temp; size_t temp;
unsigned long flags; unsigned long flags;
bus = to_usb_bus(class_dev); bus = class_get_devdata(class_dev);
hcd = bus->hcpriv; hcd = bus->hcpriv;
ohci = hcd_to_ohci(hcd); ohci = hcd_to_ohci(hcd);
...@@ -514,7 +514,7 @@ show_periodic (struct class_device *class_dev, char *buf) ...@@ -514,7 +514,7 @@ show_periodic (struct class_device *class_dev, char *buf)
return 0; return 0;
seen_count = 0; seen_count = 0;
bus = to_usb_bus(class_dev); bus = class_get_devdata(class_dev);
hcd = bus->hcpriv; hcd = bus->hcpriv;
ohci = hcd_to_ohci(hcd); ohci = hcd_to_ohci(hcd);
next = buf; next = buf;
...@@ -611,7 +611,7 @@ show_registers (struct class_device *class_dev, char *buf) ...@@ -611,7 +611,7 @@ show_registers (struct class_device *class_dev, char *buf)
char *next; char *next;
u32 rdata; u32 rdata;
bus = to_usb_bus(class_dev); bus = class_get_devdata(class_dev);
hcd = bus->hcpriv; hcd = bus->hcpriv;
ohci = hcd_to_ohci(hcd); ohci = hcd_to_ohci(hcd);
regs = ohci->regs; regs = ohci->regs;
...@@ -684,7 +684,7 @@ static CLASS_DEVICE_ATTR (registers, S_IRUGO, show_registers, NULL); ...@@ -684,7 +684,7 @@ static CLASS_DEVICE_ATTR (registers, S_IRUGO, show_registers, NULL);
static inline void create_debug_files (struct ohci_hcd *ohci) static inline void create_debug_files (struct ohci_hcd *ohci)
{ {
struct class_device *cldev = &ohci_to_hcd(ohci)->self.class_dev; struct class_device *cldev = ohci_to_hcd(ohci)->self.class_dev;
class_device_create_file(cldev, &class_device_attr_async); class_device_create_file(cldev, &class_device_attr_async);
class_device_create_file(cldev, &class_device_attr_periodic); class_device_create_file(cldev, &class_device_attr_periodic);
...@@ -694,7 +694,7 @@ static inline void create_debug_files (struct ohci_hcd *ohci) ...@@ -694,7 +694,7 @@ static inline void create_debug_files (struct ohci_hcd *ohci)
static inline void remove_debug_files (struct ohci_hcd *ohci) static inline void remove_debug_files (struct ohci_hcd *ohci)
{ {
struct class_device *cldev = &ohci_to_hcd(ohci)->self.class_dev; struct class_device *cldev = ohci_to_hcd(ohci)->self.class_dev;
class_device_remove_file(cldev, &class_device_attr_async); class_device_remove_file(cldev, &class_device_attr_async);
class_device_remove_file(cldev, &class_device_attr_periodic); class_device_remove_file(cldev, &class_device_attr_periodic);
......
...@@ -287,15 +287,14 @@ struct usb_bus { ...@@ -287,15 +287,14 @@ struct usb_bus {
struct dentry *usbfs_dentry; /* usbfs dentry entry for the bus */ struct dentry *usbfs_dentry; /* usbfs dentry entry for the bus */
struct class_device class_dev; /* class device for this bus */ struct class_device *class_dev; /* class device for this bus */
struct kref kref; /* handles reference counting this bus */
void (*release)(struct usb_bus *bus); /* function to destroy this bus's memory */ void (*release)(struct usb_bus *bus); /* function to destroy this bus's memory */
#if defined(CONFIG_USB_MON) || defined(CONFIG_USB_MON_MODULE) #if defined(CONFIG_USB_MON) || defined(CONFIG_USB_MON_MODULE)
struct mon_bus *mon_bus; /* non-null when associated */ struct mon_bus *mon_bus; /* non-null when associated */
int monitored; /* non-zero when monitored */ int monitored; /* non-zero when monitored */
#endif #endif
}; };
#define to_usb_bus(d) container_of(d, struct usb_bus, class_dev)
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment