Skip to contentSkip to conversation

video: fbdev: Fix Warning comparing pointer to 0 reported by coccicheck

PATCH Superseded Shobhit Kukreti 3 participants 5 messages Jun 1, 2019 – Jun 21, 2019 Framebuffer layer

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 video: fbdev: Fix Warning comparing pointer to 0 reported by coccicheck

drivers/video/fbdev/controlfb.c: WARNING comparing pointer to 0 drivers/video/fbdev/controlfb.c: WARNING comparing pointer to 0 drivers/video/fbdev/controlfb.c: WARNING comparing pointer to 0

---
 drivers/video/fbdev/controlfb.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/video/fbdev/controlfb.c +4 -4
index 7af8db2..07907c5 100644
@@ -182,7 +182,7 @@ int init_module(void)
 	int ret = -ENXIO;
 
 	dp = of_find_node_by_name(NULL, "control");
-	if (dp != 0 && !control_of_init(dp))
+	if (dp != NULL && !control_of_init(dp))
 		ret = 0;
 	of_node_put(dp);
 
@@ -580,7 +580,7 @@ static int __init control_init(void)
 	control_setup(option);
 
 	dp = of_find_node_by_name(NULL, "control");
-	if (dp != 0 && !control_of_init(dp))
+	if (dp != NULL && !control_of_init(dp))
 		ret = 0;
 	of_node_put(dp);
 
@@ -683,8 +683,8 @@ static int __init control_of_init(struct device_node *dp)
 		return -ENXIO;
 	}
 	p = kzalloc(sizeof(*p), GFP_KERNEL);
-	if (p = 0)
-		return -ENXIO;
+	if (p = NULL)
+		return -ENOMEM;
 	control_fb = p;	/* save it for cleanups */
 
 	/* Map in frame buffer and registers */
Signature · 1 line
2.7.4
#1 lore raw
Quoted 33 lines · Shobhit Kukreti

drivers/video/fbdev/controlfb.c: WARNING comparing pointer to 0 drivers/video/fbdev/controlfb.c: WARNING comparing pointer to 0 drivers/video/fbdev/controlfb.c: WARNING comparing pointer to 0

---
 drivers/video/fbdev/controlfb.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/video/fbdev/controlfb.c +2 -2
index 7af8db2..07907c5 100644
@@ -182,7 +182,7 @@ int init_module(void)
        int ret = -ENXIO;
 
        dp = of_find_node_by_name(NULL, "control");
-       if (dp != 0 && !control_of_init(dp))
+       if (dp != NULL && !control_of_init(dp))
                ret = 0;
        of_node_put(dp);
 
@@ -580,7 +580,7 @@ static int __init control_init(void)
        control_setup(option);
 
        dp = of_find_node_by_name(NULL, "control");
-       if (dp != 0 && !control_of_init(dp))
+       if (dp != NULL && !control_of_init(dp))
                ret = 0;
        of_node_put(dp);
 

drivers/video/fbdev/controlfb.c static int __init control_of_init(struct device_node *dp) · line 687

Quoted 7 lines
drivers/video/fbdev/controlfb.c +2 -2
@@ -683,8 +683,8 @@ static int __init control_of_init(struct device_node *dp)
                return -ENXIO;
        }
        p = kzalloc(sizeof(*p), GFP_KERNEL);
-       if (p = 0)
-               return -ENXIO;
+       if (p = NULL)
+               return -ENOMEM;

IMHO the above should be described in the commit message.

Quoted 6 lines
drivers/video/fbdev/controlfb.c +0 -1
        control_fb = p; /* save it for cleanups */
 
        /* Map in frame buffer and registers */
--

2.7.4

#2 lore raw

PATCH v2 1/1 video: fbdev: Fix Warning comparing pointer to 0 reported by coccicheck

From: Shobhit Kukreti <[email protected]>

Fixed Warning Comparing Pointer to 0. Changed return value to -ENOMEM to report kzalloc failure

drivers/video/fbdev/controlfb.c: WARNING comparing pointer to 0 drivers/video/fbdev/controlfb.c: WARNING comparing pointer to 0 drivers/video/fbdev/controlfb.c: WARNING comparing pointer to 0

---
Changes in v2:
- Modified commit message to report change in return type

 drivers/video/fbdev/controlfb.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/video/fbdev/controlfb.c +4 -4
index 7af8db2..07907c5 100644
@@ -182,7 +182,7 @@ int init_module(void)
 	int ret = -ENXIO;
 
 	dp = of_find_node_by_name(NULL, "control");
-	if (dp != 0 && !control_of_init(dp))
+	if (dp != NULL && !control_of_init(dp))
 		ret = 0;
 	of_node_put(dp);
 
@@ -580,7 +580,7 @@ static int __init control_init(void)
 	control_setup(option);
 
 	dp = of_find_node_by_name(NULL, "control");
-	if (dp != 0 && !control_of_init(dp))
+	if (dp != NULL && !control_of_init(dp))
 		ret = 0;
 	of_node_put(dp);
 
@@ -683,8 +683,8 @@ static int __init control_of_init(struct device_node *dp)
 		return -ENXIO;
 	}
 	p = kzalloc(sizeof(*p), GFP_KERNEL);
-	if (p = 0)
-		return -ENXIO;
+	if (p = NULL)
+		return -ENOMEM;
 	control_fb = p;	/* save it for cleanups */
 
 	/* Map in frame buffer and registers */
Signature · 1 line
2.7.4
Reviewed-by on v2 1/1
#3 lore raw
Quoted 41 lines · On Mon, Jun 3, 2019 at 1:21 PM <[email protected]> wrote:

From: Shobhit Kukreti <[email protected]>

Fixed Warning Comparing Pointer to 0. Changed return value to -ENOMEM to report kzalloc failure

drivers/video/fbdev/controlfb.c: WARNING comparing pointer to 0 drivers/video/fbdev/controlfb.c: WARNING comparing pointer to 0 drivers/video/fbdev/controlfb.c: WARNING comparing pointer to 0

---
Changes in v2:
- Modified commit message to report change in return type

 drivers/video/fbdev/controlfb.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/video/fbdev/controlfb.c +2 -2
index 7af8db2..07907c5 100644
@@ -182,7 +182,7 @@ int init_module(void)
        int ret = -ENXIO;
 
        dp = of_find_node_by_name(NULL, "control");
-       if (dp != 0 && !control_of_init(dp))
+       if (dp != NULL && !control_of_init(dp))
                ret = 0;
        of_node_put(dp);
 
@@ -580,7 +580,7 @@ static int __init control_init(void)
        control_setup(option);
 
        dp = of_find_node_by_name(NULL, "control");
-       if (dp != 0 && !control_of_init(dp))
+       if (dp != NULL && !control_of_init(dp))
                ret = 0;
        of_node_put(dp);
 

drivers/video/fbdev/controlfb.c static int __init control_of_init(struct device_node *dp) · line 686

Quoted 6 lines
drivers/video/fbdev/controlfb.c +1 -2
@@ -683,8 +683,8 @@ static int __init control_of_init(struct device_node *dp)
                return -ENXIO;
        }
        p = kzalloc(sizeof(*p), GFP_KERNEL);
-       if (p = 0)
-               return -ENXIO;
+       if (p = NULL)

nit: I would have use !p (same for the others above). Maybe checkpatch with --strict would warn for those (can't remember from top of my head).

Anyway:

Quoted 7 lines
drivers/video/fbdev/controlfb.c +1 -1
+               return -ENOMEM;
        control_fb = p; /* save it for cleanups */
 
        /* Map in frame buffer and registers */
--

2.7.4

Reviewed-by Mathieu Malaterre
#4 lore raw
Quoted 53 lines · Mathieu Malaterre
Quoted 41 lines · On Mon, Jun 3, 2019 at 1:21 PM <[email protected]> wrote:

From: Shobhit Kukreti <[email protected]>

Fixed Warning Comparing Pointer to 0. Changed return value to -ENOMEM to report kzalloc failure

drivers/video/fbdev/controlfb.c: WARNING comparing pointer to 0 drivers/video/fbdev/controlfb.c: WARNING comparing pointer to 0 drivers/video/fbdev/controlfb.c: WARNING comparing pointer to 0

---
Changes in v2:
- Modified commit message to report change in return type

 drivers/video/fbdev/controlfb.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/video/fbdev/controlfb.c +2 -2
index 7af8db2..07907c5 100644
@@ -182,7 +182,7 @@ int init_module(void)
        int ret = -ENXIO;
 
        dp = of_find_node_by_name(NULL, "control");
-       if (dp != 0 && !control_of_init(dp))
+       if (dp != NULL && !control_of_init(dp))
                ret = 0;
        of_node_put(dp);
 
@@ -580,7 +580,7 @@ static int __init control_init(void)
        control_setup(option);
 
        dp = of_find_node_by_name(NULL, "control");
-       if (dp != 0 && !control_of_init(dp))
+       if (dp != NULL && !control_of_init(dp))
                ret = 0;
        of_node_put(dp);
 

drivers/video/fbdev/controlfb.c static int __init control_of_init(struct device_node *dp) · line 686

Quoted 6 lines
drivers/video/fbdev/controlfb.c +1 -2
@@ -683,8 +683,8 @@ static int __init control_of_init(struct device_node *dp)
                return -ENXIO;
        }
        p = kzalloc(sizeof(*p), GFP_KERNEL);
-       if (p = 0)
-               return -ENXIO;
+       if (p = NULL)

nit: I would have use !p (same for the others above). Maybe checkpatch with --strict would warn for those (can't remember from top of my head).

Quoted 8 lines

Anyway:

Quoted 4 lines
drivers/video/fbdev/controlfb.c +1 -0
+               return -ENOMEM;
        control_fb = p; /* save it for cleanups */
 
        /* Map in frame buffer and registers */

Patch queued (with some fixups, please see below) for v5.3, thanks.

Best regards,
--
Bartlomiej Zolnierkiewicz
Samsung R&D Institute Poland
Samsung Electronics

From: Shobhit Kukreti <[email protected]>
Subject: [PATCH] video: fbdev: controlfb: fix warnings about comparing pointer to 0

Fix warnings aboout comparing pointer to 0 reported by coccicheck:

drivers/video/fbdev/controlfb.c: WARNING comparing pointer to 0 drivers/video/fbdev/controlfb.c: WARNING comparing pointer to 0 drivers/video/fbdev/controlfb.c: WARNING comparing pointer to 0

Also while at it change return value to -ENOMEM on kzalloc() failure.

---
 drivers/video/fbdev/controlfb.c |    8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

Index: b/drivers/video/fbdev/controlfb.c =================================--- a/drivers/video/fbdev/controlfb.c +++ b/drivers/video/fbdev/controlfb.c
@@ -182,7 +182,7 @@ int init_module(void)
int ret = -ENXIO;

dp = of_find_node_by_name(NULL, "control");
- if (dp != 0 && !control_of_init(dp))
+ if (dp && !control_of_init(dp))
ret = 0;
of_node_put(dp);

@@ -580,7 +580,7 @@ static int __init control_init(void)
control_setup(option);

dp = of_find_node_by_name(NULL, "control");
- if (dp != 0 && !control_of_init(dp))
+ if (dp && !control_of_init(dp))
ret = 0;
of_node_put(dp);

@@ -683,8 +683,8 @@ static int __init control_of_init(struct
return -ENXIO;
}
p = kzalloc(sizeof(*p), GFP_KERNEL);
- if (p = 0)
- return -ENXIO;
+ if (!p)
+ return -ENOMEM;
control_fb = p; /* save it for cleanups */

/* Map in frame buffer and registers */