staging: wilc1000: Return correct error codes
PATCH v2 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, 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.
---
Changes in v2:
-corrected semantic patch
drivers/staging/wilc1000/linux_wlan.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/staging/wilc1000/linux_wlan.c +2 -2
@@ -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
Quoted 22 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_etherdevon failure should return a-ENOMEMand 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 5 lines
Furthermore, return
-ENODEVon failure ofregister_netdev()instead of -1.The two call sites store the return value in a variable, hence no change is required at the call site.
This is not a reasonable justification. You have to check what happens to these variables, and argue why the change in value is not a problem.
julia
Quoted 39 lines
Signed-off-by Amitoj Kaur Chawla <[email protected]>---
Changes in v2:
-corrected semantic patchdrivers/staging/wilc1000/linux_wlan.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)drivers/staging/wilc1000/linux_wlan.c +2
-3@@ -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/20160217044728.GA8935%40amitoj-Inspiron-3542.
For more options, visit https://groups.google.com/d/optout.