From: Markus Elfring <[email protected]>
Date: Thu, 1 Feb 2018 17:51:23 +0100
Two update suggestions were taken into account
from static source code analysis.
Markus Elfring (2):
Delete an error message for a failed memory allocation
Return an error code only as a constant
drivers/i2c/busses/i2c-tiny-usb.c | 17 ++++-------------
1 file changed, 4 insertions(+), 13 deletions(-)
--
2.16.1
From: Markus Elfring <[email protected]>
Date: Thu, 1 Feb 2018 17:36:50 +0100
Omit an extra message for a memory allocation failure in this function.
This issue was detected by using the Coccinelle software.
Signed-off-by: Markus Elfring <[email protected]>
---
drivers/i2c/busses/i2c-tiny-usb.c | 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)
diff --git a/drivers/i2c/busses/i2c-tiny-usb.c b/drivers/i2c/busses/i2c-tiny-usb.c
index a2e3dd715380..e210e36df123 100644
--- a/drivers/i2c/busses/i2c-tiny-usb.c
+++ b/drivers/i2c/busses/i2c-tiny-usb.c
@@ -230,10 +230,8 @@ static int i2c_tiny_usb_probe(struct usb_interface *interface,
/* allocate memory for our device state and initialize it */
dev = kzalloc(sizeof(*dev), GFP_KERNEL);
- if (dev == NULL) {
- dev_err(&interface->dev, "Out of memory\n");
+ if (!dev)
goto error;
- }
dev->usb_dev = usb_get_dev(interface_to_usbdev(interface));
dev->interface = interface;
--
2.16.1
From: Markus Elfring <[email protected]>
Date: Thu, 1 Feb 2018 17:45:21 +0100
* Return an error code without storing it in an intermediate variable.
* Delete the label "error" and local variable "retval"
which became unnecessary with this refactoring.
Signed-off-by: Markus Elfring <[email protected]>
---
drivers/i2c/busses/i2c-tiny-usb.c | 13 +++----------
1 file changed, 3 insertions(+), 10 deletions(-)
diff --git a/drivers/i2c/busses/i2c-tiny-usb.c b/drivers/i2c/busses/i2c-tiny-usb.c
index e210e36df123..2416bb0d8a88 100644
--- a/drivers/i2c/busses/i2c-tiny-usb.c
+++ b/drivers/i2c/busses/i2c-tiny-usb.c
@@ -223,7 +223,6 @@ static int i2c_tiny_usb_probe(struct usb_interface *interface,
const struct usb_device_id *id)
{
struct i2c_tiny_usb *dev;
- int retval = -ENOMEM;
u16 version;
dev_dbg(&interface->dev, "probing usb device\n");
@@ -231,7 +230,7 @@ static int i2c_tiny_usb_probe(struct usb_interface *interface,
/* allocate memory for our device state and initialize it */
dev = kzalloc(sizeof(*dev), GFP_KERNEL);
if (!dev)
- goto error;
+ return -ENOMEM;
dev->usb_dev = usb_get_dev(interface_to_usbdev(interface));
dev->interface = interface;
@@ -257,8 +256,8 @@ static int i2c_tiny_usb_probe(struct usb_interface *interface,
if (usb_write(&dev->adapter, CMD_SET_DELAY, delay, 0, NULL, 0) != 0) {
dev_err(&dev->adapter.dev,
"failure setting delay to %dus\n", delay);
- retval = -EIO;
- goto error;
+ i2c_tiny_usb_free(dev);
+ return -EIO;
}
dev->adapter.dev.parent = &dev->interface->dev;
@@ -270,12 +269,6 @@ static int i2c_tiny_usb_probe(struct usb_interface *interface,
dev_info(&dev->adapter.dev, "connected i2c-tiny-usb device\n");
return 0;
-
- error:
- if (dev)
- i2c_tiny_usb_free(dev);
-
- return retval;
}
static void i2c_tiny_usb_disconnect(struct usb_interface *interface)
--
2.16.1