staging: wilc1000: Return correct error codes
PATCH v5 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 on an alloc_etherdev failure should return a -ENOMEM and not -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 v5:
-Modified commit message to avoid misleading description of
the change made.
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
@@ -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
Quoted 5 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 on an
alloc_etherdevfailure should return a-ENOMEMand not -1.
Actually, this should be "should be -ENOMEM", not "should return a -ENOMEM". A return value can't itself return.
julia
Quoted 88 lines
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
;
}
//</smplFurthermore, introduced
retvariable to store and return the corresponding error code returned byregister_netdevon 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.
Signed-off-by Amitoj Kaur Chawla <[email protected]>Reviewed-by Arnd Bergmann <[email protected]>---
Changes in v5:
-Modified commit message to avoid misleading description of
the change made.
Changes in v4:
-Modifiedregister_netdevto 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 patchdrivers/staging/wilc1000/linux_wlan.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)drivers/staging/wilc1000/linux_wlan.c +5
-5@@ -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 ; --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/20160217145756.GA3049%40amitoj-Inspiron-3542.
For more options, visit https://groups.google.com/d/optout.