Skip to contentSkip to conversation

staging: wilc1000: Return correct error codes

PATCH Superseded Amitoj Kaur Chawla 2 participants 2 messages Feb 17, 2016 Staging

v4 of 6 Superseded Latest is v6 →

lore
Share & tools
lore
#0 lore raw

PATCH v4 1/1 staging: wilc1000: Return correct error codes

This change has been made with the goal that kernel functions should return something more descriptive than -1 on failure.

The return value of alloc_etherdev on failure should return a -ENOMEM and not a -1. This was found using Coccinelle. A simplified version of the semantic patch used is:

//<smpl>
@@
expression *e;
identifier l1;
@@

e = alloc_etherdev(...);
if (e == NULL) {
...
return -1
+ -ENOMEM
;
}
//</smpl

Furthermore, introduced ret variable to store and return the corresponding error code returned by register_netdev on failure.

The two call sites store the return value in a variable which only checks that the value is non-zero, hence no change is required at the call sites.

---
Changes in v4:
-Modified register_netdev to return error code on a failure to
set up the device.
Changes in v3:
-Further checked call sites to understand how the value is
being analyzed
Changes in v2:
-Corrected semantic patch

 drivers/staging/wilc1000/linux_wlan.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)
drivers/staging/wilc1000/linux_wlan.c +5 -4
index a731b46..274f468 100644
@@ -1312,7 +1312,7 @@ EXPORT_SYMBOL_GPL(wilc_netdev_cleanup);
 int wilc_netdev_init(struct wilc **wilc, struct device *dev, int io_type,
 		     int gpio, const struct wilc_hif_func *ops)
 {
-	int i;
+	int i, ret;
 	struct wilc_vif *vif;
 	struct net_device *ndev;
 	struct wilc *wl;
@@ -1333,7 +1333,7 @@ int wilc_netdev_init(struct wilc **wilc, struct device *dev, int io_type,
 	for (i = 0; i < NUM_CONCURRENT_IFC; i++) {
 		ndev = alloc_etherdev(sizeof(struct wilc_vif));
 		if (!ndev)
-			return -1;
+			return -ENOMEM;
 
 		vif = netdev_priv(ndev);
 		memset(vif, 0, sizeof(struct wilc_vif));
@@ -1372,8 +1372,9 @@ int wilc_netdev_init(struct wilc **wilc, struct device *dev, int io_type,
 			vif->netstats.tx_bytes = 0;
 		}
 
-		if (register_netdev(ndev))
-			return -1;
+		ret = register_netdev(ndev);
+		if (ret)
+			return ret;
 
 		vif->iftype = STATION_MODE;
 		vif->mac_opened = 0;
Signature · 1 line
1.9.1
Reviewed-by on v4 1/1
#1 lore raw
Quoted 22 lines · On Wednesday 17 February 2016 20:12:02 Amitoj Kaur Chawla wrote:

This change has been made with the goal that kernel functions should return something more descriptive than -1 on failure.

The return value of alloc_etherdev on failure should return a -ENOMEM and not a -1. This was found using Coccinelle. A simplified version of the semantic patch used is:

//<smpl>
@@
expression *e;
identifier l1;
@@

e = alloc_etherdev(...);
if (e == NULL) {
...
return -1
+ -ENOMEM
;
}
//</smpl

Quoted 9 lines

Furthermore, introduced ret variable to store and return the corresponding error code returned by register_netdev on failure.

The two call sites store the return value in a variable which only checks that the value is non-zero, hence no change is required at the call sites.