Re: [PATCH] Check return value of device_add and device_create_file
David Brownell <[email protected]>
| Newsgroups | gmane.linux.usb.devel |
|---|---|
| Message-ID | <[email protected]> |
On Tuesday 17 April 2007 4:22 pm, Erik Hovland wrote: > The functions device_add and device_create_file return status and > that status is annotated as 'must check'. > > This patch checks the return values and then unwinds work as necessary. This should already be fixed by a patch in Greg's USB queue ... http://www.kernel.org/pub/linux/kernel/people/gregkh/gregkh-2.6/gregkh-03-usb/ pxa2xx_udc-cleanups-use-platform_get_irq.patch Right? > Signed-off-by: Erik Hovland <[email protected]> > --- > > drivers/usb/gadget/pxa2xx_udc.c | 18 ++++++++++++++++-- > 1 files changed, 16 insertions(+), 2 deletions(-) > > diff --git a/drivers/usb/gadget/pxa2xx_udc.c b/drivers/usb/gadget/pxa2xx_udc.c > index f01890d..8165920 100644 > --- a/drivers/usb/gadget/pxa2xx_udc.c > +++ b/drivers/usb/gadget/pxa2xx_udc.c > @@ -1635,7 +1635,13 @@ int usb_gadget_register_driver(struct usb_gadget_driver *driver) > dev->gadget.dev.driver = &driver->driver; > dev->pullup = 1; > > - device_add (&dev->gadget.dev); > + if ((retval = device_add (&dev->gadget.dev))) { > + DMSG("device add failed --> error %d\n", retval); > + > + dev->driver = NULL; > + dev->gadget.dev.driver = NULL; > + return retval; > + } > retval = driver->bind(&dev->gadget); > if (retval) { > DMSG("bind to driver %s --> error %d\n", > @@ -1646,7 +1652,15 @@ int usb_gadget_register_driver(struct usb_gadget_driver *driver) > dev->gadget.dev.driver = NULL; > return retval; > } > - device_create_file(dev->dev, &dev_attr_function); > + if ((retval = device_create_file(dev->dev, &dev_attr_function))) { > + DMSG("create device file failed\n"); > + driver->unbind(&dev->gadget); > + device_del (&dev->gadget.dev); > + > + dev->driver = NULL; > + dev->gadget.dev.driver = NULL; > + return retval; > + } > > /* ... then enable host detection and ep0; and we're ready > * for set_configuration as well as eventual disconnect. > > -- > Erik Hovland > mail: [email protected] > web: http://hovland.org/ > PGP/GPG public key available on request > ------------------------------------------------------------------------- This SF.net email is sponsored by DB2 Express Download DB2 Express C - the FREE version of DB2 express and take control of your XML. No limits. Just data. Click to get it now. http://sourceforge.net/powerbar/db2/ _______________________________________________ [email protected] To unsubscribe, use the last form field at: https://lists.sourceforge.net/lists/listinfo/linux-usb-devel