Skip to contentSkip to conversation

staging: rtl8192e: Clean up tests on the results of functions that return NULL on failure.

PATCH Superseded G Pooja Shamili 2 participants 2 messages Mar 6, 2016 – Mar 11, 2016 Staging

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 staging: rtl8192e: Clean up tests on the results of functions that return NULL on failure.

Functions returning NULL as a return value on failure can be tested for as !x, NULL == x or x == NULL. As !x is commonly used, all the tests need to be modified to use !x for a consistent coding style. In this patch, the function kzalloc is considered.

Coccinelle is used to achieve this, the semantic patch being:

@@
expression E;
statement S;
@@

E = kzalloc(...);

if (
(
+ !
E
- == NULL
|
+ !
- NULL ==
E
)
) S

---
Changes from Version 1:
* Changed the name in the From: and Signed-off-by: to full
name.

 drivers/staging/rtl8192e/rtllib_wx.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/staging/rtl8192e/rtllib_wx.c +2 -2
index 84e6272..8060410 100644
@@ -373,7 +373,7 @@ int rtllib_wx_set_encode(struct rtllib_device *ieee,
 		/* take WEP into use */
 		new_crypt = kzalloc(sizeof(struct lib80211_crypt_data),
 				    GFP_KERNEL);
-		if (new_crypt == NULL)
+		if (!new_crypt)
 			return -ENOMEM;
 		new_crypt->ops = lib80211_get_crypto_ops("R-WEP");
 		if (!new_crypt->ops) {
@@ -618,7 +618,7 @@ int rtllib_wx_set_encode_ext(struct rtllib_device *ieee,
 		lib80211_crypt_delayed_deinit(&ieee->crypt_info, crypt);
 
 		new_crypt = kzalloc(sizeof(*new_crypt), GFP_KERNEL);
-		if (new_crypt == NULL) {
+		if (!new_crypt) {
 			ret = -ENOMEM;
 			goto done;
 		}
Signature · 1 line
2.1.4
maintainer
#1 lore raw
Quoted 26 lines · G Pooja Shamili

Functions returning NULL as a return value on failure can be tested for as !x, NULL == x or x == NULL. As !x is commonly used, all the tests need to be modified to use !x for a consistent coding style. In this patch, the function kzalloc is considered.

Coccinelle is used to achieve this, the semantic patch being:

@@
expression E;
statement S;
@@

E = kzalloc(...);

if (
(

(quoted diff) +1 -0
+	!

E

(quoted diff) +0 -1
-	== NULL

|

(quoted diff) +1 -1
+	!
-	NULL ==

E
)
) S

Quoted 5 lines

---
Changes from Version 1:
* Changed the name in the From: and Signed-off-by: to full
name.

You sent me 2 patches with pretty much the identical subject line, yet they all did 3 different things. Please fix up and resend as a patch series.

thanks,

greg k-h