Skip to contentSkip to conversation

staging: wilc1000: Return correct error codes

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

v1 of 6 Superseded Latest is v6 →

lore
Share & tools
lore
#0 lore raw

PATCH 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) {
...
goto l1;
}
l1:
...
return -1
+ -ENOMEM
;
//</smpl

Furthermore, return -ENODEV on failure of register_netdev() instead of -1.

The two call sites store the return value in a variable, hence no change is required at the call site.

---
 drivers/staging/wilc1000/linux_wlan.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/staging/wilc1000/linux_wlan.c +2 -2
index a731b46..4f8b21d 100644
@@ -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));
@@ -1373,7 +1373,7 @@ int wilc_netdev_init(struct wilc **wilc, struct device *dev, int io_type,
 		}
 
 		if (register_netdev(ndev))
-			return -1;
+			return -ENODEV;
 
 		vif->iftype = STATION_MODE;
 		vif->mac_opened = 0;
Signature · 1 line
1.9.1
#1 lore raw
Quoted 25 lines · Amitoj Kaur Chawla

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) {
...
goto l1;
}
l1:
...
return -1
+ -ENOMEM
;
//</smpl

Quoted 5 lines

Furthermore, return -ENODEV on failure of register_netdev() instead of -1.

The two call sites store the return value in a variable, hence no change is required at the call site.

You need to analyze what happens to the values of these variables.

julia

Quoted 38 lines
---
 drivers/staging/wilc1000/linux_wlan.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/staging/wilc1000/linux_wlan.c +2 -3
index a731b46..4f8b21d 100644
@@ -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));
@@ -1373,7 +1373,7 @@ int wilc_netdev_init(struct wilc **wilc, struct device *dev, int io_type,
 		}
 
 		if (register_netdev(ndev))
-			return -1;
+			return -ENODEV;
 
 		vif->iftype = STATION_MODE;
 		vif->mac_opened = 0;
--

1.9.1

--
You received this message because you are subscribed to the Google Groups "outreachy-kernel" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected].
To view this discussion on the web visit https://groups.google.com/d/msgid/outreachy-kernel/20160217044347.GA8876%40amitoj-Inspiron-3542.
For more options, visit https://groups.google.com/d/optout.