Skip to contentSkip to conversation

0 -> NULL, for arch/arm

PATCH Applied Yoann Padioleau 6 participants 8 messages Jul 27, 2007 – Jul 31, 2007

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

PATCH 2/68 0 -> NULL, for arch/arm

When comparing a pointer, it's clearer to compare it to NULL than to 0.

Here is an excerpt of the semantic patch:

@@
expression *E;
@@

E =
- 0
+ NULL

@@
expression *E;
@@

E !- 0
+ NULL

---

 common/dmabounce.c |    2 +-
 mach-omap1/clock.c |    2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
arch/arm/common/dmabounce.c +1 -1
index b36b1e8..74ff750 100644
@@ -238,7 +238,7 @@ map_single(struct device *dev, void *ptr
 		struct safe_buffer *buf;
 
 		buf = alloc_safe_buffer(device_info, ptr, size, dir);
-		if (buf = 0) {
+		if (buf = NULL) {
 			dev_err(dev, "%s: unable to map unsafe buffer %p!\n",
 			       __func__, ptr);
 			return 0;
arch/arm/mach-omap1/clock.c +1 -1
index f625f6d..b7e1b22 100644
@@ -193,7 +193,7 @@ static int calc_dsor_exp(struct clk *clk
 		return -EINVAL;
 
 	parent = clk->parent;
-	if (unlikely(parent = 0))
+	if (unlikely(parent = NULL))
 		return -EIO;
 
 	realrate = parent->rate;
#1 lore raw

arch/arm/common/dmabounce.c map_single(struct device *dev, void *ptr · line 241

Quoted 3 lines · Yoann Padioleau
arch/arm/common/dmabounce.c +1 -1
 		buf = alloc_safe_buffer(device_info, ptr, size, dir);
-		if (buf = 0) {
+		if (buf = NULL) {
		if (!buf)

surely...

#2 lore raw
Quoted 7 lines · Al Viro

arch/arm/common/dmabounce.c map_single(struct device *dev, void *ptr · line 241

Quoted 3 lines · Yoann Padioleau
arch/arm/common/dmabounce.c +1 -1
 		buf = alloc_safe_buffer(device_info, ptr, size, dir);
-		if (buf = 0) {
+		if (buf = NULL) {
		if (!buf)

surely...

Definitely the preferred form.

Yoann, please remember to CC folk.

Signature · 3 lines
Russell King
 Linux kernel    2.6 ARM Linux   - http://www.arm.linux.org.uk/
 maintainer of:
#3 lore raw
In reply to Al Viro
Quoted 7 lines · Al Viro

arch/arm/common/dmabounce.c map_single(struct device *dev, void *ptr · line 241

Quoted 3 lines · Yoann Padioleau
arch/arm/common/dmabounce.c +1 -1
 		buf = alloc_safe_buffer(device_info, ptr, size, dir);
-		if (buf = 0) {
+		if (buf = NULL) {
		if (!buf)

surely...

Makes it look like it's used as a bool.

Jan

#4 lore raw
Quoted 11 lines · Jan Engelhardt
Quoted 7 lines · Al Viro

arch/arm/common/dmabounce.c map_single(struct device *dev, void *ptr · line 241

Quoted 3 lines · Yoann Padioleau
arch/arm/common/dmabounce.c +1 -1
 		buf = alloc_safe_buffer(device_info, ptr, size, dir);
-		if (buf = 0) {
+		if (buf = NULL) {
		if (!buf)

surely...

Makes it look like it's used as a bool.

bool variables are rarely named buf, so no.

#5 lore raw
Quoted 10 lines · Alexey Dobriyan
Quoted 9 lines · Jan Engelhardt
Quoted 7 lines · Al Viro

arch/arm/common/dmabounce.c map_single(struct device *dev, void *ptr · line 241

Quoted 3 lines · Yoann Padioleau
arch/arm/common/dmabounce.c +1 -1
 		buf = alloc_safe_buffer(device_info, ptr, size, dir);
-		if (buf = 0) {
+		if (buf = NULL) {
		if (!buf)

surely...

Quoted 3 lines
Quoted 1 line

Makes it look like it's used as a bool.

bool variables are rarely named buf, so no.

Whatever. Java is good in one point: the ! operator requires a bool.

Jan

#6 lore raw
Quoted 3 lines · Jan Engelhardt
Quoted 1 line

bool variables are rarely named buf, so no.

Whatever. Java is good in one point: the ! operator requires a bool.

Language and style advocacy -> that way. Use of scalar types, including pointers, in conditional contexts is both 100% legal and, what's more important, idiomatic C.

#7 lore raw
In reply to Jan Engelhardt
Quoted 12 lines · Jan Engelhardt
Quoted 9 lines · Al Viro

arch/arm/common/dmabounce.c map_single(struct device *dev, void *ptr · line 241

Quoted 4 lines · Yoann Padioleau
arch/arm/common/dmabounce.c +1 -1
 		buf = alloc_safe_buffer(device_info, ptr, size, dir);
-		if (buf = 0) {
+		if (buf = NULL) {
		if (!buf)

surely...

Quoted 2 lines

Makes it look like it's used as a bool.

But the conditional checking for a pointer and a boolean is the same; 0 = NULL = 'false' and the rest is valid/'true'. So IMHO it is a cleaner way to write it. But then again, some people like to abuse the '!' on "regular" variables.

Richard Knutsson