Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 17200583 authored by Alan Stern's avatar Alan Stern Committed by Greg Kroah-Hartman
Browse files

usbcore: trim down usb_bus structure



As part of the ongoing program to flatten out the HCD bus-glue layer,
this patch (as771b) eliminates the hcpriv, release, and kref fields
from struct usb_bus.  hcpriv and release were not being used for
anything worthwhile, and kref has been moved into the enclosing
usb_hcd structure.

Along with those changes, the patch gets rid of usb_bus_get and
usb_bus_put, replacing them with usb_get_hcd and usb_put_hcd.

The one interesting aspect is that the dev_set_drvdata call was
removed from usb_put_hcd, where it clearly doesn't belong.  This means
the driver private data won't get reset to NULL.  It shouldn't cause
any problems, since the private data is undefined when no driver is
bound.

Signed-off-by: default avatarAlan Stern <stern@rowland.harvard.edu>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@suse.de>
parent dd990f16
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -104,7 +104,7 @@ void *hcd_buffer_alloc (
	dma_addr_t		*dma
)
{
	struct usb_hcd		*hcd = bus->hcpriv;
	struct usb_hcd		*hcd = bus_to_hcd(bus);
	int 			i;

	/* some USB hosts just use PIO */
@@ -127,7 +127,7 @@ void hcd_buffer_free (
	dma_addr_t		dma
)
{
	struct usb_hcd		*hcd = bus->hcpriv;
	struct usb_hcd		*hcd = bus_to_hcd(bus);
	int 			i;

	if (!addr)
+23 −44
Original line number Diff line number Diff line
@@ -664,31 +664,6 @@ static int usb_rh_urb_dequeue (struct usb_hcd *hcd, struct urb *urb)

/*-------------------------------------------------------------------------*/

/* exported only within usbcore */
struct usb_bus *usb_bus_get(struct usb_bus *bus)
{
	if (bus)
		kref_get(&bus->kref);
	return bus;
}

static void usb_host_release(struct kref *kref)
{
	struct usb_bus *bus = container_of(kref, struct usb_bus, kref);

	if (bus->release)
		bus->release(bus);
}

/* exported only within usbcore */
void usb_bus_put(struct usb_bus *bus)
{
	if (bus)
		kref_put(&bus->kref, usb_host_release);
}

/*-------------------------------------------------------------------------*/

static struct class *usb_host_class;

int usb_host_init(void)
@@ -720,15 +695,12 @@ static void usb_bus_init (struct usb_bus *bus)
	bus->devnum_next = 1;

	bus->root_hub = NULL;
	bus->hcpriv = NULL;
	bus->busnum = -1;
	bus->bandwidth_allocated = 0;
	bus->bandwidth_int_reqs  = 0;
	bus->bandwidth_isoc_reqs = 0;

	INIT_LIST_HEAD (&bus->bus_list);

	kref_init(&bus->kref);
}

/*-------------------------------------------------------------------------*/
@@ -1081,7 +1053,7 @@ static void urb_unlink (struct urb *urb)
int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags)
{
	int			status;
	struct usb_hcd		*hcd = urb->dev->bus->hcpriv;
	struct usb_hcd		*hcd = bus_to_hcd(urb->dev->bus);
	struct usb_host_endpoint *ep;
	unsigned long		flags;

@@ -1189,7 +1161,8 @@ int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags)
/* called in any context */
int usb_hcd_get_frame_number (struct usb_device *udev)
{
	struct usb_hcd	*hcd = (struct usb_hcd *)udev->bus->hcpriv;
	struct usb_hcd	*hcd = bus_to_hcd(udev->bus);

	if (!HC_IS_RUNNING (hcd->state))
		return -ESHUTDOWN;
	return hcd->driver->get_frame_number (hcd);
@@ -1262,7 +1235,7 @@ int usb_hcd_unlink_urb (struct urb *urb, int status)
	spin_lock (&hcd_data_lock);

	sys = &urb->dev->dev;
	hcd = urb->dev->bus->hcpriv;
	hcd = bus_to_hcd(urb->dev->bus);
	if (hcd == NULL) {
		retval = -ENODEV;
		goto done;
@@ -1333,7 +1306,7 @@ void usb_hcd_endpoint_disable (struct usb_device *udev,
	struct usb_hcd		*hcd;
	struct urb		*urb;

	hcd = udev->bus->hcpriv;
	hcd = bus_to_hcd(udev->bus);

	WARN_ON (!HC_IS_RUNNING (hcd->state) && hcd->state != HC_STATE_HALT &&
			udev->state != USB_STATE_NOTATTACHED);
@@ -1673,14 +1646,6 @@ EXPORT_SYMBOL_GPL (usb_hc_died);

/*-------------------------------------------------------------------------*/

static void hcd_release (struct usb_bus *bus)
{
	struct usb_hcd *hcd;

	hcd = container_of(bus, struct usb_hcd, self);
	kfree(hcd);
}

/**
 * usb_create_hcd - create and initialize an HCD structure
 * @driver: HC driver that will use this hcd
@@ -1705,10 +1670,9 @@ struct usb_hcd *usb_create_hcd (const struct hc_driver *driver,
		return NULL;
	}
	dev_set_drvdata(dev, hcd);
	kref_init(&hcd->kref);

	usb_bus_init(&hcd->self);
	hcd->self.hcpriv = hcd;
	hcd->self.release = &hcd_release;
	hcd->self.controller = dev;
	hcd->self.bus_name = bus_name;
	hcd->self.uses_dma = (dev->dma_mask != NULL);
@@ -1725,10 +1689,25 @@ struct usb_hcd *usb_create_hcd (const struct hc_driver *driver,
}
EXPORT_SYMBOL (usb_create_hcd);

static void hcd_release (struct kref *kref)
{
	struct usb_hcd *hcd = container_of (kref, struct usb_hcd, kref);

	kfree(hcd);
}

struct usb_hcd *usb_get_hcd (struct usb_hcd *hcd)
{
	if (hcd)
		kref_get (&hcd->kref);
	return hcd;
}
EXPORT_SYMBOL (usb_get_hcd);

void usb_put_hcd (struct usb_hcd *hcd)
{
	dev_set_drvdata(hcd->self.controller, NULL);
	usb_bus_put(&hcd->self);
	if (hcd)
		kref_put (&hcd->kref, hcd_release);
}
EXPORT_SYMBOL (usb_put_hcd);

+7 −6
Original line number Diff line number Diff line
@@ -55,12 +55,13 @@

/*-------------------------------------------------------------------------*/

struct usb_hcd {	/* usb_bus.hcpriv points to this */
struct usb_hcd {

	/*
	 * housekeeping
	 */
	struct usb_bus		self;		/* hcd is-a bus */
	struct kref		kref;		/* reference counter */

	const char		*product_desc;	/* product/vendor string */
	char			irq_descr[24];	/* driver + bus # */
@@ -129,8 +130,10 @@ static inline struct usb_bus *hcd_to_bus (struct usb_hcd *hcd)
	return &hcd->self;
}


// urb.hcpriv is really hardware-specific
static inline struct usb_hcd *bus_to_hcd (struct usb_bus *bus)
{
	return container_of(bus, struct usb_hcd, self);
}

struct hcd_timeout {	/* timeouts we allocate */
	struct list_head	timeout_list;
@@ -210,6 +213,7 @@ extern int usb_hcd_get_frame_number (struct usb_device *udev);

extern struct usb_hcd *usb_create_hcd (const struct hc_driver *driver,
		struct device *dev, char *bus_name);
extern struct usb_hcd *usb_get_hcd (struct usb_hcd *hcd);
extern void usb_put_hcd (struct usb_hcd *hcd);
extern int usb_add_hcd(struct usb_hcd *hcd,
		unsigned int irqnum, unsigned long irqflags);
@@ -356,9 +360,6 @@ extern struct list_head usb_bus_list;
extern struct mutex usb_bus_list_lock;
extern wait_queue_head_t usb_kill_urb_queue;

extern struct usb_bus *usb_bus_get (struct usb_bus *bus);
extern void usb_bus_put (struct usb_bus *bus);

extern void usb_enable_root_hub_irq (struct usb_bus *bus);

extern int usb_find_interface_driver (struct usb_device *dev,
+2 −3
Original line number Diff line number Diff line
@@ -169,7 +169,7 @@ static void usb_release_dev(struct device *dev)
	udev = to_usb_device(dev);

	usb_destroy_configuration(udev);
	usb_bus_put(udev->bus);
	usb_put_hcd(bus_to_hcd(udev->bus));
	kfree(udev->product);
	kfree(udev->manufacturer);
	kfree(udev->serial);
@@ -197,8 +197,7 @@ usb_alloc_dev(struct usb_device *parent, struct usb_bus *bus, unsigned port1)
	if (!dev)
		return NULL;

	bus = usb_bus_get(bus);
	if (!bus) {
	if (!usb_get_hcd(bus_to_hcd(bus))) {
		kfree(dev);
		return NULL;
	}
+2 −6
Original line number Diff line number Diff line
@@ -889,11 +889,9 @@ EXPORT_SYMBOL (net2280_set_fifo_mode);
static void
dummy_gadget_release (struct device *dev)
{
#if 0		/* usb_bus_put isn't EXPORTed! */
	struct dummy	*dum = gadget_dev_to_dummy (dev);

	usb_bus_put (&dummy_to_hcd (dum)->self);
#endif
	usb_put_hcd (dummy_to_hcd (dum));
}

static int dummy_udc_probe (struct platform_device *pdev)
@@ -915,9 +913,7 @@ static int dummy_udc_probe (struct platform_device *pdev)
	if (rc < 0)
		return rc;

#if 0		/* usb_bus_get isn't EXPORTed! */
	usb_bus_get (&dummy_to_hcd (dum)->self);
#endif
	usb_get_hcd (dummy_to_hcd (dum));

	platform_set_drvdata (pdev, dum);
	device_create_file (&dum->gadget.dev, &dev_attr_function);
Loading