Skip to contentSkip to conversation

staging: gdm724x: use !x instead of x == NULL

PATCH New Somya Anand 1 participant 5 messages Mar 16, 2015

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

PATCH 1/5 staging: gdm724x: use !x instead of x == NULL

Functions like devm_kzalloc, kmalloc_array, devm_ioremap, usb_alloc_urb, alloc_netdev return NULL as a return value on failure. Generally, When NULL represents failure, !x is commonly used.

This patch cleans up the tests on the results of these functions, thereby using !x instead of x == NULL or NULL == x. This is done via following coccinelle script:
@prob_7@
identifier x;
statement S;
@@

(
x = devm_kzalloc(...);
|
x = usb_alloc_urb(...);
|
x = kmalloc_array(...);
|
x = devm_ioremap(...);
|
x = alloc_netdev(...);
)
...
- if(NULL == x)
+ if(!x)
S
Further we have used isomorphism characteristics of coccinelle to indicate x == NULL and NULL == x are equivalent. This is done via following iso script.

Expression
@ is_null @ expression X; @@
X == NULL <=> NULL == X

---
 drivers/staging/gdm724x/gdm_lte.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/staging/gdm724x/gdm_lte.c +1 -1
index 7c4a77b..a8d2cff 100644
@@ -889,7 +889,7 @@ int register_lte_device(struct phy_dev *phy_dev,
 		/* Allocate netdev */
 		net = alloc_netdev(sizeof(struct nic), pdn_dev_name,
 				   NET_NAME_UNKNOWN, ether_setup);
-		if (net == NULL) {
+		if (!net) {
 			pr_err("alloc_netdev failed\n");
 			ret = -ENOMEM;
 			goto err;
Signature · 1 line
1.9.1
#1 lore raw

PATCH 2/5 Staging: gdm72xx: use !x instead of x == NULL

Functions like devm_kzalloc, kmalloc_array, devm_ioremap, usb_alloc_urb, alloc_netdev return NULL as a return value on failure. Generally, When NULL represents failure, !x is commonly used.

This patch cleans up the tests on the results of these functions, thereby using !x instead of x == NULL or NULL == x. This is done via following coccinelle script:
@prob_7@
identifier x;
statement S;
@@

(
x = devm_kzalloc(...);
|
x = usb_alloc_urb(...);
|
x = kmalloc_array(...);
|
x = devm_ioremap(...);
|
x = alloc_netdev(...);
)
...
- if(NULL == x)
+ if(!x)
S
Further we have used isomorphism characteristics of coccinelle to indicate x == NULL and NULL == x are equivalent. This is done via following iso script.

Expression
@ is_null @ expression X; @@
X == NULL <=> NULL == X

---
 drivers/staging/gdm72xx/gdm_wimax.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/staging/gdm72xx/gdm_wimax.c +1 -1
index 9cab54b..cd79dcd 100644
@@ -749,7 +749,7 @@ int register_wimax_device(struct phy_dev *phy_dev, struct device *pdev)
 	dev = alloc_netdev(sizeof(*nic), "wm%d", NET_NAME_UNKNOWN,
 			   ether_setup);
 
-	if (dev == NULL) {
+	if (!dev) {
 		pr_err("alloc_etherdev failed\n");
 		return -ENOMEM;
 	}
Signature · 1 line
1.9.1
#2 lore raw

PATCH 3/5 Staging: goldfish: use !x instead of x == NULL

In reply to Somya Anand

Functions like devm_kzalloc, kmalloc_array, devm_ioremap, usb_alloc_urb, alloc_netdev return NULL as a return value on failure. Generally, When NULL represents failure, !x is commonly used.

This patch cleans up the tests on the results of these functions, thereby using !x instead of x == NULL or NULL == x. This is done via following coccinelle script:
@prob_7@
identifier x;
statement S;
@@

(
x = devm_kzalloc(...);
|
x = usb_alloc_urb(...);
|
x = kmalloc_array(...);
|
x = devm_ioremap(...);
|
x = alloc_netdev(...);
)
...
- if(NULL == x)
+ if(!x)
S
Further we have used isomorphism characteristics of coccinelle to indicate x == NULL and NULL == x are equivalent. This is done via following iso script.

Expression
@ is_null @ expression X; @@
X == NULL <=> NULL == X

---
 drivers/staging/goldfish/goldfish_audio.c | 2 +-
 drivers/staging/goldfish/goldfish_nand.c  | 6 +++---
 2 files changed, 4 insertions(+), 4 deletions(-)
drivers/staging/goldfish/goldfish_audio.c +1 -1
index f200359..c9ee18b 100644
@@ -273,7 +273,7 @@ static int goldfish_audio_probe(struct platform_device *pdev)
 	dma_addr_t buf_addr;
 
 	data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL);
-	if (data == NULL)
+	if (!data)
 		return -ENOMEM;
 	spin_lock_init(&data->lock);
 	init_waitqueue_head(&data->wait);
drivers/staging/goldfish/goldfish_nand.c +3 -3
index d68f216..213877a 100644
@@ -330,7 +330,7 @@ static int goldfish_nand_init_device(struct platform_device *pdev,
 	mtd->priv = nand;
 
 	name = devm_kzalloc(&pdev->dev, name_len + 1, GFP_KERNEL);
-	if (name == NULL)
+	if (!name)
 		return -ENOMEM;
 	mtd->name = name;
 
@@ -383,7 +383,7 @@ static int goldfish_nand_probe(struct platform_device *pdev)
 		return -ENODEV;
 
 	base = devm_ioremap(&pdev->dev, r->start, PAGE_SIZE);
-	if (base == NULL)
+	if (!base)
 		return -ENOMEM;
 
 	version = readl(base + NAND_VERSION);
@@ -399,7 +399,7 @@ static int goldfish_nand_probe(struct platform_device *pdev)
 
 	nand = devm_kzalloc(&pdev->dev, sizeof(*nand) +
 				sizeof(struct mtd_info) * num_dev, GFP_KERNEL);
-	if (nand == NULL)
+	if (!nand)
 		return -ENOMEM;
 
 	mutex_init(&nand->lock);
Signature · 1 line
1.9.1
#3 lore raw

PATCH 4/5 Staging: iio: use !x instead of x == NULL

In reply to Somya Anand

Functions like devm_kzalloc, kmalloc_array, devm_ioremap, usb_alloc_urb, alloc_netdev return NULL as a return value on failure. Generally, When NULL represents failure, !x is commonly used.

This patch cleans up the tests on the results of these functions, thereby using !x instead of x == NULL or NULL == x. This is done via following coccinelle script:
@prob_7@
identifier x;
statement S;
@@

(
x = devm_kzalloc(...);
|
x = usb_alloc_urb(...);
|
x = kmalloc_array(...);
|
x = devm_ioremap(...);
|
x = alloc_netdev(...);
)
...
- if(NULL == x)
+ if(!x)
S
Further we have used isomorphism characteristics of coccinelle to indicate x == NULL and NULL == x are equivalent. This is done via following iso script.

Expression
@ is_null @ expression X; @@
X == NULL <=> NULL == X

---
 drivers/staging/iio/trigger/iio-trig-bfin-timer.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/staging/iio/trigger/iio-trig-bfin-timer.c +1 -1
index 2af8d67..3c1c8c6 100644
@@ -183,7 +183,7 @@ static int iio_bfin_tmr_trigger_probe(struct platform_device *pdev)
 	int ret;
 
 	st = devm_kzalloc(&pdev->dev, sizeof(*st), GFP_KERNEL);
-	if (st == NULL)
+	if (!st)
 		return -ENOMEM;
 
 	st->irq = platform_get_irq(pdev, 0);
Signature · 1 line
1.9.1
#4 lore raw

PATCH 5/5 Staging: nvec: use !x instead of x == NULL

In reply to Somya Anand

Functions like devm_kzalloc, kmalloc_array, devm_ioremap, usb_alloc_urb, alloc_netdev return NULL as a return value on failure. Generally, When NULL represents failure, !x is commonly used.

This patch cleans up the tests on the results of these functions, thereby using !x instead of x == NULL or NULL == x. This is done via following coccinelle script:
@prob_7@
identifier x;
statement S;
@@

(
x = devm_kzalloc(...);
|
x = usb_alloc_urb(...);
|
x = kmalloc_array(...);
|
x = devm_ioremap(...);
|
x = alloc_netdev(...);
)
...
- if(NULL == x)
+ if(!x)
S
Further we have used isomorphism characteristics of coccinelle to indicate x == NULL and NULL == x are equivalent. This is done via following iso script.

Expression
@ is_null @ expression X; @@
X == NULL <=> NULL == X

---
 drivers/staging/nvec/nvec.c       | 2 +-
 drivers/staging/nvec/nvec_paz00.c | 2 +-
 drivers/staging/nvec/nvec_power.c | 2 +-
 drivers/staging/nvec/nvec_ps2.c   | 2 +-
 4 files changed, 4 insertions(+), 4 deletions(-)
drivers/staging/nvec/nvec.c +1 -1
index 5868ebb..1bdc8d0 100644
@@ -803,7 +803,7 @@ static int tegra_nvec_probe(struct platform_device *pdev)
 	}
 
 	nvec = devm_kzalloc(&pdev->dev, sizeof(struct nvec_chip), GFP_KERNEL);
-	if (nvec == NULL)
+	if (!nvec)
 		return -ENOMEM;
 
 	platform_set_drvdata(pdev, nvec);
drivers/staging/nvec/nvec_paz00.c +1 -1
index f0cea0e..68146bf 100644
@@ -51,7 +51,7 @@ static int nvec_paz00_probe(struct platform_device *pdev)
 	int ret = 0;
 
 	led = devm_kzalloc(&pdev->dev, sizeof(*led), GFP_KERNEL);
-	if (led == NULL)
+	if (!led)
 		return -ENOMEM;
 
 	led->cdev.max_brightness = NVEC_LED_MAX;
drivers/staging/nvec/nvec_power.c +1 -1
index 6a1459d..3621b66 100644
@@ -378,7 +378,7 @@ static int nvec_power_probe(struct platform_device *pdev)
 	struct nvec_chip *nvec = dev_get_drvdata(pdev->dev.parent);
 
 	power = devm_kzalloc(&pdev->dev, sizeof(struct nvec_power), GFP_NOWAIT);
-	if (power == NULL)
+	if (!power)
 		return -ENOMEM;
 
 	dev_set_drvdata(&pdev->dev, power);
drivers/staging/nvec/nvec_ps2.c +1 -1
index 4fd63c2..6ebbc82 100644
@@ -109,7 +109,7 @@ static int nvec_mouse_probe(struct platform_device *pdev)
 	char mouse_reset[] = { NVEC_PS2, SEND_COMMAND, PSMOUSE_RST, 3 };
 
 	ser_dev = devm_kzalloc(&pdev->dev, sizeof(struct serio), GFP_KERNEL);
-	if (ser_dev == NULL)
+	if (!ser_dev)
 		return -ENOMEM;
 
 	ser_dev->id.type = SERIO_PS_PSTHRU;
Signature · 1 line
1.9.1