lkml.org 
[lkml]   [2017]   [Oct]   [29]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH] smsc95xx: Use common error handling code in smsc95xx_write_eeprom()
Date
From: Markus Elfring <elfring@users.sourceforge.net>
Date: Sun, 29 Oct 2017 11:08:34 +0100

Add a jump target so that a specific error message is stored only once
at the end of this function implementation.
Replace two calls of the function "netdev_warn" by goto statements.

This issue was detected by using the Coccinelle software.

Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
drivers/net/usb/smsc95xx.c | 16 ++++++++--------
1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/drivers/net/usb/smsc95xx.c b/drivers/net/usb/smsc95xx.c
index 309b88acd3d0..6a82e8055e9d 100644
--- a/drivers/net/usb/smsc95xx.c
+++ b/drivers/net/usb/smsc95xx.c
@@ -399,10 +399,8 @@ static int smsc95xx_write_eeprom(struct usbnet *dev, u32 offset, u32 length,
/* Issue write/erase enable command */
val = E2P_CMD_BUSY_ | E2P_CMD_EWEN_;
ret = smsc95xx_write_reg(dev, E2P_CMD, val);
- if (ret < 0) {
- netdev_warn(dev->net, "Error writing E2P_DATA\n");
- return ret;
- }
+ if (ret < 0)
+ goto report_write_failure;

ret = smsc95xx_wait_eeprom(dev);
if (ret < 0)
@@ -413,10 +411,8 @@ static int smsc95xx_write_eeprom(struct usbnet *dev, u32 offset, u32 length,
/* Fill data register */
val = data[i];
ret = smsc95xx_write_reg(dev, E2P_DATA, val);
- if (ret < 0) {
- netdev_warn(dev->net, "Error writing E2P_DATA\n");
- return ret;
- }
+ if (ret < 0)
+ goto report_write_failure;

/* Send "write" command */
val = E2P_CMD_BUSY_ | E2P_CMD_WRITE_ | (offset & E2P_CMD_ADDR_);
@@ -434,6 +430,10 @@ static int smsc95xx_write_eeprom(struct usbnet *dev, u32 offset, u32 length,
}

return 0;
+
+report_write_failure:
+ netdev_warn(dev->net, "Error writing E2P_DATA\n");
+ return ret;
}

static int __must_check smsc95xx_write_reg_async(struct usbnet *dev, u16 index,
--
2.14.3
\
 
 \ /
  Last update: 2017-10-29 11:15    [W:0.024 / U:28.400 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site