staging: rtl8712: rtl871x_ioctl_linux: Clean up tests if NULL returned on failure
authorBhaktipriya Shridhar <bhaktipriya96@gmail.com>
Sun, 20 Mar 2016 20:40:21 +0000 (02:10 +0530)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Mon, 28 Mar 2016 14:30:36 +0000 (07:30 -0700)
Some functions like kmalloc/kzalloc return NULL on failure.
When NULL represents failure, !x is commonly used.

This was done using Coccinelle:

@@
expression *e;
identifier l1;
@@

e = \(kmalloc\|kzalloc\|kcalloc\|devm_kzalloc\)(...);
...
- e == NULL
+ !e

Signed-off-by: Bhaktipriya Shridhar <bhaktipriya96@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/staging/rtl8712/rtl871x_ioctl_linux.c

index 1b9e249..6c02e9b 100644 (file)
@@ -399,7 +399,7 @@ static int wpa_set_encryption(struct net_device *dev, struct ieee_param *param,
                if (wep_key_len > 0) {
                        wep_key_len = wep_key_len <= 5 ? 5 : 13;
                        pwep = kzalloc(sizeof(*pwep), GFP_ATOMIC);
-                       if (pwep == NULL)
+                       if (!pwep)
                                return -ENOMEM;
                        pwep->KeyLength = wep_key_len;
                        pwep->Length = wep_key_len +
@@ -1793,7 +1793,7 @@ static int r871x_wx_set_enc_ext(struct net_device *dev,
 
        param_len = sizeof(struct ieee_param) + pext->key_len;
        param = kzalloc(param_len, GFP_ATOMIC);
-       if (param == NULL)
+       if (!param)
                return -ENOMEM;
        param->cmd = IEEE_CMD_SET_ENCRYPTION;
        eth_broadcast_addr(param->sta_addr);