[PATCH] Check return value of device_add and device_create_file

Erik Hovland <[email protected]>
Newsgroups gmane.linux.usb.devel
Message-ID <[email protected]>
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.

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
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.