Skip to contentSkip to conversation

Clean up tests if NULL returned on failure

PATCH In review simran singhal 2 participants 4 messages Mar 3, 2017 – Mar 9, 2017

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

cover Clean up tests if NULL returned on failure

This patch series tests if functions like kmalloc/kzalloc return NULL on failure. When NULL represents failure, !x is commonly used.

simran singhal (2):
staging: media: Clean up tests if NULL returned on failure
staging: rtl8192e: Clean up tests if NULL returned on failure

 drivers/staging/media/atomisp/pci/atomisp2/atomisp_fops.c | 2 +-
 drivers/staging/media/davinci_vpfe/vpfe_mc_capture.c      | 4 ++--
 drivers/staging/media/lirc/lirc_zilog.c                   | 6 +++---
 drivers/staging/rtl8192e/rtllib_crypt_ccmp.c              | 2 +-
 drivers/staging/rtl8192e/rtllib_crypt_tkip.c              | 2 +-
 drivers/staging/rtl8192e/rtllib_crypt_wep.c               | 2 +-
 drivers/staging/rtl8192e/rtllib_softmac.c                 | 2 +-
 drivers/staging/rtl8192e/rtllib_wx.c                      | 4 ++--
 8 files changed, 12 insertions(+), 12 deletions(-)
Signature · 1 line
2.7.4
#1 lore raw

PATCH 1/2 staging: media: Clean up tests if NULL returned on failure

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

---
 drivers/staging/media/atomisp/pci/atomisp2/atomisp_fops.c | 2 +-
 drivers/staging/media/davinci_vpfe/vpfe_mc_capture.c      | 4 ++--
 drivers/staging/media/lirc/lirc_zilog.c                   | 6 +++---
 3 files changed, 6 insertions(+), 6 deletions(-)
drivers/staging/media/atomisp/pci/atomisp2/atomisp_fops.c +1 -1
index 20e581e..e5a7407 100644
@@ -1100,7 +1100,7 @@ int atomisp_videobuf_mmap_mapper(struct videobuf_queue *q,
 			continue;
 
 		map = kzalloc(sizeof(struct videobuf_mapping), GFP_KERNEL);
-		if (map == NULL) {
+		if (!map) {
 			mutex_unlock(&q->vb_lock);
 			return -ENOMEM;
 		}
drivers/staging/media/davinci_vpfe/vpfe_mc_capture.c +2 -2
index 32109cd..bffe215 100644
@@ -228,7 +228,7 @@ static int vpfe_enable_clock(struct vpfe_device *vpfe_dev)
 
 	vpfe_dev->clks = kcalloc(vpfe_cfg->num_clocks,
 				 sizeof(*vpfe_dev->clks), GFP_KERNEL);
-	if (vpfe_dev->clks == NULL)
+	if (!vpfe_dev->clks)
 		return -ENOMEM;
 
 	for (i = 0; i < vpfe_cfg->num_clocks; i++) {
@@ -348,7 +348,7 @@ static int register_i2c_devices(struct vpfe_device *vpfe_dev)
 	vpfe_dev->sd =
 		  kcalloc(num_subdevs, sizeof(struct v4l2_subdev *),
 			  GFP_KERNEL);
-	if (vpfe_dev->sd == NULL)
+	if (!vpfe_dev->sd)
 		return -ENOMEM;
 
 	for (i = 0, k = 0; i < num_subdevs; i++) {
drivers/staging/media/lirc/lirc_zilog.c +3 -3
index 34aac3e..4836182 100644
@@ -1475,7 +1475,7 @@ static int ir_probe(struct i2c_client *client, const struct i2c_device_id *id)
 	ir = get_ir_device_by_adapter(adap);
 	if (ir == NULL) {
 		ir = kzalloc(sizeof(struct IR), GFP_KERNEL);
-		if (ir == NULL) {
+		if (!ir) {
 			ret = -ENOMEM;
 			goto out_no_ir;
 		}
@@ -1515,7 +1515,7 @@ static int ir_probe(struct i2c_client *client, const struct i2c_device_id *id)
 
 		/* Set up a struct IR_tx instance */
 		tx = kzalloc(sizeof(struct IR_tx), GFP_KERNEL);
-		if (tx == NULL) {
+		if (!tx) {
 			ret = -ENOMEM;
 			goto out_put_xx;
 		}
@@ -1559,7 +1559,7 @@ static int ir_probe(struct i2c_client *client, const struct i2c_device_id *id)
 
 		/* Set up a struct IR_rx instance */
 		rx = kzalloc(sizeof(struct IR_rx), GFP_KERNEL);
-		if (rx == NULL) {
+		if (!rx) {
 			ret = -ENOMEM;
 			goto out_put_xx;
 		}
Signature · 1 line
2.7.4
maintainer
#2 lore raw

Re: [PATCH 1/2] staging: media: Clean up tests if NULL returned on failure

Quoted 14 lines · simran singhal

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

Quoted 6 lines
---
 drivers/staging/media/atomisp/pci/atomisp2/atomisp_fops.c | 2 +-
 drivers/staging/media/davinci_vpfe/vpfe_mc_capture.c      | 4 ++--
 drivers/staging/media/lirc/lirc_zilog.c                   | 6 +++---
 3 files changed, 6 insertions(+), 6 deletions(-)

Please break this up into one patch per driver.

thanks,

greg k-h

#3 lore raw

PATCH 2/2 staging: rtl8192e: Clean up tests if NULL returned on failure

In reply to simran singhal

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

---
 drivers/staging/rtl8192e/rtllib_crypt_ccmp.c | 2 +-
 drivers/staging/rtl8192e/rtllib_crypt_tkip.c | 2 +-
 drivers/staging/rtl8192e/rtllib_crypt_wep.c  | 2 +-
 drivers/staging/rtl8192e/rtllib_softmac.c    | 2 +-
 drivers/staging/rtl8192e/rtllib_wx.c         | 4 ++--
 5 files changed, 6 insertions(+), 6 deletions(-)
drivers/staging/rtl8192e/rtllib_crypt_ccmp.c +1 -1
index bc45cf0..ed2e06f 100644
@@ -63,7 +63,7 @@ static void *rtllib_ccmp_init(int key_idx)
 	struct rtllib_ccmp_data *priv;
 
 	priv = kzalloc(sizeof(*priv), GFP_ATOMIC);
-	if (priv == NULL)
+	if (!priv)
 		goto fail;
 	priv->key_idx = key_idx;
 
drivers/staging/rtl8192e/rtllib_crypt_tkip.c +1 -1
index ae103b0..580b57a 100644
@@ -63,7 +63,7 @@ static void *rtllib_tkip_init(int key_idx)
 	struct rtllib_tkip_data *priv;
 
 	priv = kzalloc(sizeof(*priv), GFP_ATOMIC);
-	if (priv == NULL)
+	if (!priv)
 		goto fail;
 	priv->key_idx = key_idx;
 	priv->tx_tfm_arc4 = crypto_alloc_skcipher("ecb(arc4)", 0,
drivers/staging/rtl8192e/rtllib_crypt_wep.c +1 -1
index b3343a5..f5a1bc5 100644
@@ -37,7 +37,7 @@ static void *prism2_wep_init(int keyidx)
 	struct prism2_wep_data *priv;
 
 	priv = kzalloc(sizeof(*priv), GFP_ATOMIC);
-	if (priv == NULL)
+	if (!priv)
 		goto fail;
 	priv->key_idx = keyidx;
 
drivers/staging/rtl8192e/rtllib_softmac.c +1 -1
index eeda17d..4bdc3ba 100644
@@ -3328,7 +3328,7 @@ static int rtllib_wpa_set_encryption(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;
 		}
drivers/staging/rtl8192e/rtllib_wx.c +2 -2
index b1500ee..9f3824a 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.7.4