Skip to contentSkip to conversation

Staging: rtl8723au: Clean up tests if NULL returned on failure

PATCH In review Bhumika Goyal 2 participants 2 messages Feb 24, 2016 Staging

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Staging: rtl8723au: Clean up tests if NULL returned on failure

Some functions like kmalloc/usb_alloc_urb returns Null as their return value on failure. !x is generally preferred over x==NULL or NULL==x. So make use of !x if the value returned on failure by these functions is NULL. Done using coccinelle:

@@
expression e;
statement S;
@@
e = \(kmalloc\|devm_kzalloc\|kmalloc_array

     \|devm_ioremap\|usb_alloc_urb\|alloc_netdev\)(...);

- if(e==NULL)
+ if(!e)
S

---
 drivers/staging/rtl8723au/hal/rtl8723a_hal_init.c | 4 ++--
 drivers/staging/rtl8723au/os_dep/xmit_linux.c     | 2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)
drivers/staging/rtl8723au/hal/rtl8723a_hal_init.c +2 -2
index e3dc889..71d0549 100644
@@ -399,7 +399,7 @@ hal_ReadEFuse_WiFi(struct rtw_adapter *padapter,
 	}
 
 	efuseTbl = kmalloc(EFUSE_MAP_LEN_8723A, GFP_KERNEL);
-	if (efuseTbl == NULL) {
+	if (!efuseTbl) {
 		DBG_8723A("%s: alloc efuseTbl fail!\n", __func__);
 		return;
 	}
@@ -491,7 +491,7 @@ hal_ReadEFuse_BT(struct rtw_adapter *padapter,
 	}
 
 	efuseTbl = kmalloc(EFUSE_BT_MAP_LEN, GFP_KERNEL);
-	if (efuseTbl == NULL) {
+	if (!efuseTbl) {
 		DBG_8723A("%s: efuseTbl malloc fail!\n", __func__);
 		return;
 	}
drivers/staging/rtl8723au/os_dep/xmit_linux.c +1 -1
index 9a14074..64be72a 100644
@@ -37,7 +37,7 @@ int rtw_os_xmit_resource_alloc23a(struct rtw_adapter *padapter,
 
 	for (i = 0; i < 8; i++) {
 		pxmitbuf->pxmit_urb[i] = usb_alloc_urb(0, GFP_KERNEL);
-		if (pxmitbuf->pxmit_urb[i] == NULL) {
+		if (!pxmitbuf->pxmit_urb[i]) {
 			DBG_8723A("pxmitbuf->pxmit_urb[i]==NULL");
 			return _FAIL;
 		}
Signature · 1 line
1.9.1
#1 lore raw
Quoted 26 lines · Bhumika Goyal

Some functions like kmalloc/usb_alloc_urb returns Null as their return value on failure. !x is generally preferred over x==NULL or NULL==x. So make use of !x if the value returned on failure by these functions is NULL. Done using coccinelle:

@@
expression e;
statement S;
@@
e = \(kmalloc\|devm_kzalloc\|kmalloc_array

     \|devm_ioremap\|usb_alloc_urb\|alloc_netdev\)(...);

- if(e==NULL)
+ if(!e)
S

---
 drivers/staging/rtl8723au/hal/rtl8723a_hal_init.c | 4 ++--
 drivers/staging/rtl8723au/os_dep/xmit_linux.c     | 2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)
drivers/staging/rtl8723au/hal/rtl8723a_hal_init.c +0 -0
index e3dc889..71d0549 100644

drivers/staging/rtl8723au/hal/rtl8723a_hal_init.c hal_ReadEFuse_WiFi(struct rtw_adapter *padapter, · line 403

Quoted 6 lines
drivers/staging/rtl8723au/hal/rtl8723a_hal_init.c +1 -1
@@ -399,7 +399,7 @@ hal_ReadEFuse_WiFi(struct rtw_adapter *padapter,
 	}
 
 	efuseTbl = kmalloc(EFUSE_MAP_LEN_8723A, GFP_KERNEL);
-	if (efuseTbl == NULL) {
+	if (!efuseTbl) {
 		DBG_8723A("%s: alloc efuseTbl fail!\n", __func__);

Unrelated to the change you are doing, kmalloc generates a complete backtrace on failure, so there is no need for these debug messages.

julia

Quoted 34 lines
drivers/staging/rtl8723au/hal/rtl8723a_hal_init.c +1 -1
 		return;
 	}
@@ -491,7 +491,7 @@ hal_ReadEFuse_BT(struct rtw_adapter *padapter,
 	}
 
 	efuseTbl = kmalloc(EFUSE_BT_MAP_LEN, GFP_KERNEL);
-	if (efuseTbl == NULL) {
+	if (!efuseTbl) {
 		DBG_8723A("%s: efuseTbl malloc fail!\n", __func__);
 		return;
 	}
drivers/staging/rtl8723au/os_dep/xmit_linux.c +1 -1
index 9a14074..64be72a 100644
@@ -37,7 +37,7 @@ int rtw_os_xmit_resource_alloc23a(struct rtw_adapter *padapter,
 
 	for (i = 0; i < 8; i++) {
 		pxmitbuf->pxmit_urb[i] = usb_alloc_urb(0, GFP_KERNEL);
-		if (pxmitbuf->pxmit_urb[i] == NULL) {
+		if (!pxmitbuf->pxmit_urb[i]) {
 			DBG_8723A("pxmitbuf->pxmit_urb[i]==NULL");
 			return _FAIL;
 		}
Signature · 8 lines
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/1456309437-7356-1-git-send-email-bhumirks%40gmail.com.
For more options, visit https://groups.google.com/d/optout.