Commit 6bea476c authored by David Brownell's avatar David Brownell Committed by Greg Kroah-Hartman

USB: gadget driver unbind() is optional; section fixes; misc

Allow gadget drivers to omit the unbind() method.  When they're
statically linked, that's an appropriate memory saving tweak.

Similarly, provide consistent/simpler handling for a should-not-happen
error case:  removing a peripheral controller driver when a gadget
driver is still loaded.  Such code dates back to early versions of the
first implementation of the gadget API, and has never been triggered.

Includes relevant section annotation fixs for gmidi.c, file_storage.c,
and serial.c; we don't yet have an "init or exit" annotation.  Also
some whitespace fixes in gmidi.c (space at EOL, before tabs, etc).
Signed-off-by: default avatarDavid Brownell <dbrownell@users.sourceforge.net>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@suse.de>
parent 5f8364b7
...@@ -1574,7 +1574,6 @@ int usb_gadget_register_driver (struct usb_gadget_driver *driver) ...@@ -1574,7 +1574,6 @@ int usb_gadget_register_driver (struct usb_gadget_driver *driver)
if (!driver if (!driver
|| driver->speed != USB_SPEED_FULL || driver->speed != USB_SPEED_FULL
|| !driver->bind || !driver->bind
|| !driver->unbind
|| !driver->setup) { || !driver->setup) {
DBG("bad parameter.\n"); DBG("bad parameter.\n");
return -EINVAL; return -EINVAL;
...@@ -1611,7 +1610,7 @@ int usb_gadget_unregister_driver (struct usb_gadget_driver *driver) ...@@ -1611,7 +1610,7 @@ int usb_gadget_unregister_driver (struct usb_gadget_driver *driver)
{ {
struct at91_udc *udc = &controller; struct at91_udc *udc = &controller;
if (!driver || driver != udc->driver) if (!driver || driver != udc->driver || !driver->unbind)
return -EINVAL; return -EINVAL;
local_irq_disable(); local_irq_disable();
...@@ -1731,10 +1730,10 @@ static int __devexit at91udc_remove(struct platform_device *pdev) ...@@ -1731,10 +1730,10 @@ static int __devexit at91udc_remove(struct platform_device *pdev)
DBG("remove\n"); DBG("remove\n");
pullup(udc, 0); if (udc->driver)
return -EBUSY;
if (udc->driver != 0) pullup(udc, 0);
usb_gadget_unregister_driver(udc->driver);
device_init_wakeup(&pdev->dev, 0); device_init_wakeup(&pdev->dev, 0);
remove_debug_file(udc); remove_debug_file(udc);
......
...@@ -779,7 +779,7 @@ usb_gadget_register_driver (struct usb_gadget_driver *driver) ...@@ -779,7 +779,7 @@ usb_gadget_register_driver (struct usb_gadget_driver *driver)
return -EINVAL; return -EINVAL;
if (dum->driver) if (dum->driver)
return -EBUSY; return -EBUSY;
if (!driver->bind || !driver->unbind || !driver->setup if (!driver->bind || !driver->setup
|| driver->speed == USB_SPEED_UNKNOWN) || driver->speed == USB_SPEED_UNKNOWN)
return -EINVAL; return -EINVAL;
...@@ -837,7 +837,8 @@ usb_gadget_register_driver (struct usb_gadget_driver *driver) ...@@ -837,7 +837,8 @@ usb_gadget_register_driver (struct usb_gadget_driver *driver)
err_bind_driver: err_bind_driver:
driver_unregister (&driver->driver); driver_unregister (&driver->driver);
err_register: err_register:
driver->unbind (&dum->gadget); if (driver->unbind)
driver->unbind (&dum->gadget);
spin_lock_irq (&dum->lock); spin_lock_irq (&dum->lock);
dum->pullup = 0; dum->pullup = 0;
set_link_state (dum); set_link_state (dum);
...@@ -857,7 +858,7 @@ usb_gadget_unregister_driver (struct usb_gadget_driver *driver) ...@@ -857,7 +858,7 @@ usb_gadget_unregister_driver (struct usb_gadget_driver *driver)
if (!dum) if (!dum)
return -ENODEV; return -ENODEV;
if (!driver || driver != dum->driver) if (!driver || driver != dum->driver || !driver->unbind)
return -EINVAL; return -EINVAL;
dev_dbg (udc_dev(dum), "unregister gadget driver '%s'\n", dev_dbg (udc_dev(dum), "unregister gadget driver '%s'\n",
......
...@@ -4100,7 +4100,7 @@ static struct usb_gadget_driver fsg_driver = { ...@@ -4100,7 +4100,7 @@ static struct usb_gadget_driver fsg_driver = {
#endif #endif
.function = (char *) longname, .function = (char *) longname,
.bind = fsg_bind, .bind = fsg_bind,
.unbind = __exit_p(fsg_unbind), .unbind = fsg_unbind,
.disconnect = fsg_disconnect, .disconnect = fsg_disconnect,
.setup = fsg_setup, .setup = fsg_setup,
.suspend = fsg_suspend, .suspend = fsg_suspend,
......
...@@ -123,7 +123,7 @@ struct gmidi_device { ...@@ -123,7 +123,7 @@ struct gmidi_device {
struct usb_request *req; /* for control responses */ struct usb_request *req; /* for control responses */
u8 config; u8 config;
struct usb_ep *in_ep, *out_ep; struct usb_ep *in_ep, *out_ep;
struct snd_card *card; struct snd_card *card;
struct snd_rawmidi *rmidi; struct snd_rawmidi *rmidi;
struct snd_rawmidi_substream *in_substream; struct snd_rawmidi_substream *in_substream;
struct snd_rawmidi_substream *out_substream; struct snd_rawmidi_substream *out_substream;
...@@ -490,7 +490,7 @@ static void gmidi_complete(struct usb_ep *ep, struct usb_request *req) ...@@ -490,7 +490,7 @@ static void gmidi_complete(struct usb_ep *ep, struct usb_request *req)
int status = req->status; int status = req->status;
switch (status) { switch (status) {
case 0: /* normal completion */ case 0: /* normal completion */
if (ep == dev->out_ep) { if (ep == dev->out_ep) {
/* we received stuff. /* we received stuff.
req is queued again, below */ req is queued again, below */
...@@ -505,7 +505,7 @@ static void gmidi_complete(struct usb_ep *ep, struct usb_request *req) ...@@ -505,7 +505,7 @@ static void gmidi_complete(struct usb_ep *ep, struct usb_request *req)
break; break;
/* this endpoint is normally active while we're configured */ /* this endpoint is normally active while we're configured */
case -ECONNABORTED: /* hardware forced ep reset */ case -ECONNABORTED: /* hardware forced ep reset */
case -ECONNRESET: /* request dequeued */ case -ECONNRESET: /* request dequeued */
case -ESHUTDOWN: /* disconnect from host */ case -ESHUTDOWN: /* disconnect from host */
VDBG(dev, "%s gone (%d), %d/%d\n", ep->name, status, VDBG(dev, "%s gone (%d), %d/%d\n", ep->name, status,
...@@ -656,7 +656,7 @@ gmidi_set_config(struct gmidi_device *dev, unsigned number, gfp_t gfp_flags) ...@@ -656,7 +656,7 @@ gmidi_set_config(struct gmidi_device *dev, unsigned number, gfp_t gfp_flags)
case USB_SPEED_LOW: speed = "low"; break; case USB_SPEED_LOW: speed = "low"; break;
case USB_SPEED_FULL: speed = "full"; break; case USB_SPEED_FULL: speed = "full"; break;
case USB_SPEED_HIGH: speed = "high"; break; case USB_SPEED_HIGH: speed = "high"; break;
default: speed = "?"; break; default: speed = "?"; break;
} }
dev->config = number; dev->config = number;
...@@ -1308,7 +1308,7 @@ static struct usb_gadget_driver gmidi_driver = { ...@@ -1308,7 +1308,7 @@ static struct usb_gadget_driver gmidi_driver = {
.speed = USB_SPEED_FULL, .speed = USB_SPEED_FULL,
.function = (char *)longname, .function = (char *)longname,
.bind = gmidi_bind, .bind = gmidi_bind,
.unbind = __exit_p(gmidi_unbind), .unbind = gmidi_unbind,
.setup = gmidi_setup, .setup = gmidi_setup,
.disconnect = gmidi_disconnect, .disconnect = gmidi_disconnect,
...@@ -1316,7 +1316,7 @@ static struct usb_gadget_driver gmidi_driver = { ...@@ -1316,7 +1316,7 @@ static struct usb_gadget_driver gmidi_driver = {
.suspend = gmidi_suspend, .suspend = gmidi_suspend,
.resume = gmidi_resume, .resume = gmidi_resume,
.driver = { .driver = {
.name = (char *)shortname, .name = (char *)shortname,
.owner = THIS_MODULE, .owner = THIS_MODULE,
}, },
......
...@@ -1432,7 +1432,6 @@ int usb_gadget_register_driver(struct usb_gadget_driver *driver) ...@@ -1432,7 +1432,6 @@ int usb_gadget_register_driver(struct usb_gadget_driver *driver)
if (!driver if (!driver
|| driver->speed != USB_SPEED_FULL || driver->speed != USB_SPEED_FULL
|| !driver->bind || !driver->bind
|| !driver->unbind
|| !driver->disconnect || !driver->disconnect
|| !driver->setup) || !driver->setup)
return -EINVAL; return -EINVAL;
...@@ -1495,7 +1494,7 @@ int usb_gadget_unregister_driver(struct usb_gadget_driver *driver) ...@@ -1495,7 +1494,7 @@ int usb_gadget_unregister_driver(struct usb_gadget_driver *driver)
if (!dev) if (!dev)
return -ENODEV; return -ENODEV;
if (!driver || driver != dev->driver) if (!driver || driver != dev->driver || !driver->unbind)
return -EINVAL; return -EINVAL;
spin_lock_irqsave(&dev->lock, flags); spin_lock_irqsave(&dev->lock, flags);
...@@ -1808,13 +1807,8 @@ static void goku_remove(struct pci_dev *pdev) ...@@ -1808,13 +1807,8 @@ static void goku_remove(struct pci_dev *pdev)
struct goku_udc *dev = pci_get_drvdata(pdev); struct goku_udc *dev = pci_get_drvdata(pdev);
DBG(dev, "%s\n", __FUNCTION__); DBG(dev, "%s\n", __FUNCTION__);
/* start with the driver above us */
if (dev->driver) { BUG_ON(dev->driver);
/* should have been done already by driver model core */
WARN(dev, "pci remove, driver '%s' is still registered\n",
dev->driver->driver.name);
usb_gadget_unregister_driver(dev->driver);
}
#ifdef CONFIG_USB_GADGET_DEBUG_FILES #ifdef CONFIG_USB_GADGET_DEBUG_FILES
remove_proc_entry(proc_node_name, NULL); remove_proc_entry(proc_node_name, NULL);
......
...@@ -422,9 +422,10 @@ int usb_gadget_register_driver(struct usb_gadget_driver *driver) ...@@ -422,9 +422,10 @@ int usb_gadget_register_driver(struct usb_gadget_driver *driver)
DEBUG("%s: %s\n", __FUNCTION__, driver->driver.name); DEBUG("%s: %s\n", __FUNCTION__, driver->driver.name);
if (!driver if (!driver
|| driver->speed != USB_SPEED_FULL || driver->speed != USB_SPEED_FULL
|| !driver->bind || !driver->bind
|| !driver->unbind || !driver->disconnect || !driver->setup) || !driver->disconnect
|| !driver->setup)
return -EINVAL; return -EINVAL;
if (!dev) if (!dev)
return -ENODEV; return -ENODEV;
...@@ -471,7 +472,7 @@ int usb_gadget_unregister_driver(struct usb_gadget_driver *driver) ...@@ -471,7 +472,7 @@ int usb_gadget_unregister_driver(struct usb_gadget_driver *driver)
if (!dev) if (!dev)
return -ENODEV; return -ENODEV;
if (!driver || driver != dev->driver) if (!driver || driver != dev->driver || !driver->unbind)
return -EINVAL; return -EINVAL;
spin_lock_irqsave(&dev->lock, flags); spin_lock_irqsave(&dev->lock, flags);
...@@ -2125,9 +2126,11 @@ static int lh7a40x_udc_remove(struct platform_device *pdev) ...@@ -2125,9 +2126,11 @@ static int lh7a40x_udc_remove(struct platform_device *pdev)
DEBUG("%s: %p\n", __FUNCTION__, pdev); DEBUG("%s: %p\n", __FUNCTION__, pdev);
if (dev->driver)
return -EBUSY;
udc_disable(dev); udc_disable(dev);
remove_proc_files(); remove_proc_files();
usb_gadget_unregister_driver(dev->driver);
free_irq(IRQ_USBINTR, dev); free_irq(IRQ_USBINTR, dev);
......
...@@ -2020,7 +2020,6 @@ int usb_gadget_register_driver (struct usb_gadget_driver *driver) ...@@ -2020,7 +2020,6 @@ int usb_gadget_register_driver (struct usb_gadget_driver *driver)
if (!driver if (!driver
|| driver->speed != USB_SPEED_HIGH || driver->speed != USB_SPEED_HIGH
|| !driver->bind || !driver->bind
|| !driver->unbind
|| !driver->setup) || !driver->setup)
return -EINVAL; return -EINVAL;
if (!dev) if (!dev)
...@@ -2107,7 +2106,7 @@ int usb_gadget_unregister_driver (struct usb_gadget_driver *driver) ...@@ -2107,7 +2106,7 @@ int usb_gadget_unregister_driver (struct usb_gadget_driver *driver)
if (!dev) if (!dev)
return -ENODEV; return -ENODEV;
if (!driver || driver != dev->driver) if (!driver || driver != dev->driver || !driver->unbind)
return -EINVAL; return -EINVAL;
spin_lock_irqsave (&dev->lock, flags); spin_lock_irqsave (&dev->lock, flags);
...@@ -2803,13 +2802,7 @@ static void net2280_remove (struct pci_dev *pdev) ...@@ -2803,13 +2802,7 @@ static void net2280_remove (struct pci_dev *pdev)
{ {
struct net2280 *dev = pci_get_drvdata (pdev); struct net2280 *dev = pci_get_drvdata (pdev);
/* start with the driver above us */ BUG_ON(dev->driver);
if (dev->driver) {
/* should have been done already by driver model core */
WARN (dev, "pci remove, driver '%s' is still registered\n",
dev->driver->driver.name);
usb_gadget_unregister_driver (dev->driver);
}
/* then clean up the resources we allocated during probe() */ /* then clean up the resources we allocated during probe() */
net2280_led_shutdown (dev); net2280_led_shutdown (dev);
......
...@@ -2043,7 +2043,6 @@ int usb_gadget_register_driver (struct usb_gadget_driver *driver) ...@@ -2043,7 +2043,6 @@ int usb_gadget_register_driver (struct usb_gadget_driver *driver)
// FIXME if otg, check: driver->is_otg // FIXME if otg, check: driver->is_otg
|| driver->speed < USB_SPEED_FULL || driver->speed < USB_SPEED_FULL
|| !driver->bind || !driver->bind
|| !driver->unbind
|| !driver->setup) || !driver->setup)
return -EINVAL; return -EINVAL;
...@@ -2087,9 +2086,11 @@ int usb_gadget_register_driver (struct usb_gadget_driver *driver) ...@@ -2087,9 +2086,11 @@ int usb_gadget_register_driver (struct usb_gadget_driver *driver)
status = otg_set_peripheral(udc->transceiver, &udc->gadget); status = otg_set_peripheral(udc->transceiver, &udc->gadget);
if (status < 0) { if (status < 0) {
ERR("can't bind to transceiver\n"); ERR("can't bind to transceiver\n");
driver->unbind (&udc->gadget); if (driver->unbind) {
udc->gadget.dev.driver = NULL; driver->unbind (&udc->gadget);
udc->driver = NULL; udc->gadget.dev.driver = NULL;
udc->driver = NULL;
}
goto done; goto done;
} }
} else { } else {
...@@ -2117,7 +2118,7 @@ int usb_gadget_unregister_driver (struct usb_gadget_driver *driver) ...@@ -2117,7 +2118,7 @@ int usb_gadget_unregister_driver (struct usb_gadget_driver *driver)
if (!udc) if (!udc)
return -ENODEV; return -ENODEV;
if (!driver || driver != udc->driver) if (!driver || driver != udc->driver || !driver->unbind)
return -EINVAL; return -EINVAL;
if (machine_is_omap_innovator() || machine_is_omap_osk()) if (machine_is_omap_innovator() || machine_is_omap_osk())
...@@ -2870,6 +2871,8 @@ static int __exit omap_udc_remove(struct platform_device *pdev) ...@@ -2870,6 +2871,8 @@ static int __exit omap_udc_remove(struct platform_device *pdev)
if (!udc) if (!udc)
return -ENODEV; return -ENODEV;
if (udc->driver)
return -EBUSY;
udc->done = &done; udc->done = &done;
......
...@@ -1623,7 +1623,6 @@ int usb_gadget_register_driver(struct usb_gadget_driver *driver) ...@@ -1623,7 +1623,6 @@ int usb_gadget_register_driver(struct usb_gadget_driver *driver)
if (!driver if (!driver
|| driver->speed < USB_SPEED_FULL || driver->speed < USB_SPEED_FULL
|| !driver->bind || !driver->bind
|| !driver->unbind
|| !driver->disconnect || !driver->disconnect
|| !driver->setup) || !driver->setup)
return -EINVAL; return -EINVAL;
...@@ -1694,7 +1693,7 @@ int usb_gadget_unregister_driver(struct usb_gadget_driver *driver) ...@@ -1694,7 +1693,7 @@ int usb_gadget_unregister_driver(struct usb_gadget_driver *driver)
if (!dev) if (!dev)
return -ENODEV; return -ENODEV;
if (!driver || driver != dev->driver) if (!driver || driver != dev->driver || !driver->unbind)
return -EINVAL; return -EINVAL;
local_irq_disable(); local_irq_disable();
...@@ -2638,9 +2637,11 @@ static int __exit pxa2xx_udc_remove(struct platform_device *pdev) ...@@ -2638,9 +2637,11 @@ static int __exit pxa2xx_udc_remove(struct platform_device *pdev)
{ {
struct pxa2xx_udc *dev = platform_get_drvdata(pdev); struct pxa2xx_udc *dev = platform_get_drvdata(pdev);
if (dev->driver)
return -EBUSY;
udc_disable(dev); udc_disable(dev);
remove_proc_files(); remove_proc_files();
usb_gadget_unregister_driver(dev->driver);
if (dev->got_irq) { if (dev->got_irq) {
free_irq(IRQ_USB, dev); free_irq(IRQ_USB, dev);
......
...@@ -296,7 +296,7 @@ static struct usb_gadget_driver gs_gadget_driver = { ...@@ -296,7 +296,7 @@ static struct usb_gadget_driver gs_gadget_driver = {
#endif /* CONFIG_USB_GADGET_DUALSPEED */ #endif /* CONFIG_USB_GADGET_DUALSPEED */
.function = GS_LONG_NAME, .function = GS_LONG_NAME,
.bind = gs_bind, .bind = gs_bind,
.unbind = __exit_p(gs_unbind), .unbind = gs_unbind,
.setup = gs_setup, .setup = gs_setup,
.disconnect = gs_disconnect, .disconnect = gs_disconnect,
.driver = { .driver = {
......
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