[PATCH v2] video/saa7164: Fix sparse warning: Using plain integer as NULL pointer

2011-01-30 Thread Peter Huewe
From: Peter Huewe peterhu...@gmx.de

This patch fixes the warning Using plain integer as NULL pointer,
generated by sparse, by replacing
if(var == 0)
with
if (!var)
after an allocation
and all other offending 0s with NULL.

KernelVersion: linus' tree-1f0324c

Signed-off-by: Peter Huewe peterhu...@gmx.de
---
v2: I changed the patch according to Julia's hints. 
i.e. using if(!buf) instead of if(buf==NULL) after the kmalloc family,
and other allocations.

 drivers/media/video/saa7164/saa7164-api.c |   10 +-
 drivers/media/video/saa7164/saa7164-buffer.c  |   16 
 drivers/media/video/saa7164/saa7164-bus.c |8 
 drivers/media/video/saa7164/saa7164-cmd.c |   10 +-
 drivers/media/video/saa7164/saa7164-core.c|8 
 drivers/media/video/saa7164/saa7164-dvb.c |4 ++--
 drivers/media/video/saa7164/saa7164-encoder.c |8 
 drivers/media/video/saa7164/saa7164-fw.c  |2 +-
 drivers/media/video/saa7164/saa7164-vbi.c |8 
 9 files changed, 37 insertions(+), 37 deletions(-)

diff --git a/drivers/media/video/saa7164/saa7164-api.c 
b/drivers/media/video/saa7164/saa7164-api.c
index bd86d97..8a98ab6 100644
--- a/drivers/media/video/saa7164/saa7164-api.c
+++ b/drivers/media/video/saa7164/saa7164-api.c
@@ -743,7 +743,7 @@ int saa7164_api_configure_dif(struct saa7164_port *port, 
u32 std)
 int saa7164_api_initialize_dif(struct saa7164_port *port)
 {
struct saa7164_dev *dev = port-dev;
-   struct saa7164_port *p = 0;
+   struct saa7164_port *p = NULL;
int ret = -EINVAL;
u32 std = 0;
 
@@ -926,9 +926,9 @@ int saa7164_api_configure_port_mpeg2ps(struct saa7164_dev 
*dev,
 
 int saa7164_api_dump_subdevs(struct saa7164_dev *dev, u8 *buf, int len)
 {
-   struct saa7164_port *tsport = 0;
-   struct saa7164_port *encport = 0;
-   struct saa7164_port *vbiport = 0;
+   struct saa7164_port *tsport = NULL;
+   struct saa7164_port *encport = NULL;
+   struct saa7164_port *vbiport = NULL;
u32 idx, next_offset;
int i;
struct tmComResDescrHeader *hdr, *t;
@@ -1340,7 +1340,7 @@ int saa7164_api_enum_subdevs(struct saa7164_dev *dev)
 
/* Allocate enough storage for all of the descs */
buf = kzalloc(buflen, GFP_KERNEL);
-   if (buf == NULL)
+   if (!buf)
return SAA_ERR_NO_RESOURCES;
 
/* Retrieve them */
diff --git a/drivers/media/video/saa7164/saa7164-buffer.c 
b/drivers/media/video/saa7164/saa7164-buffer.c
index ddd2521..66696fa 100644
--- a/drivers/media/video/saa7164/saa7164-buffer.c
+++ b/drivers/media/video/saa7164/saa7164-buffer.c
@@ -93,7 +93,7 @@ struct saa7164_buffer *saa7164_buffer_alloc(struct 
saa7164_port *port,
u32 len)
 {
struct tmHWStreamParameters *params = port-hw_streamingparams;
-   struct saa7164_buffer *buf = 0;
+   struct saa7164_buffer *buf = NULL;
struct saa7164_dev *dev = port-dev;
int i;
 
@@ -103,7 +103,7 @@ struct saa7164_buffer *saa7164_buffer_alloc(struct 
saa7164_port *port,
}
 
buf = kzalloc(sizeof(struct saa7164_buffer), GFP_KERNEL);
-   if (buf == NULL) {
+   if (!buf) {
log_warn(%s() SAA_ERR_NO_RESOURCES\n, __func__);
goto ret;
}
@@ -157,7 +157,7 @@ fail2:
 fail1:
kfree(buf);
 
-   buf = 0;
+   buf = NULL;
 ret:
return buf;
 }
@@ -289,14 +289,14 @@ struct saa7164_user_buffer 
*saa7164_buffer_alloc_user(struct saa7164_dev *dev,
struct saa7164_user_buffer *buf;
 
buf = kzalloc(sizeof(struct saa7164_user_buffer), GFP_KERNEL);
-   if (buf == 0)
-   return 0;
+   if (!buf)
+   return NULL;
 
buf-data = kzalloc(len, GFP_KERNEL);
 
-   if (buf-data == 0) {
+   if (!buf-data) {
kfree(buf);
-   return 0;
+   return NULL;
}
 
buf-actual_size = len;
@@ -315,7 +315,7 @@ void saa7164_buffer_dealloc_user(struct saa7164_user_buffer 
*buf)
return;
 
kfree(buf-data);
-   buf-data = 0;
+   buf-data = NULL;
 
kfree(buf);
 }
diff --git a/drivers/media/video/saa7164/saa7164-bus.c 
b/drivers/media/video/saa7164/saa7164-bus.c
index b2b0d97..466e1b0 100644
--- a/drivers/media/video/saa7164/saa7164-bus.c
+++ b/drivers/media/video/saa7164/saa7164-bus.c
@@ -158,7 +158,7 @@ int saa7164_bus_set(struct saa7164_dev *dev, struct 
tmComResInfo* msg,
return SAA_ERR_BAD_PARAMETER;
}
 
-   if ((msg-size  0)  (buf == 0)) {
+   if ((msg-size  0)  (buf == NULL)) {
printk(KERN_ERR %s() Missing message buffer\n, __func__);
return SAA_ERR_BAD_PARAMETER;
}
@@ -315,7 +315,7 @@ int saa7164_bus_get(struct saa7164_dev *dev, struct 
tmComResInfo* msg,
 
saa7164_bus_verify(dev);
 
-   if (msg == 0)
+   if (msg == NULL)
return ret;
 

Re: [PATCH v2] video/saa7164: Fix sparse warning: Using plain integer as NULL pointer

2011-01-30 Thread Devin Heitmueller
On Sun, Jan 30, 2011 at 2:33 PM, Peter Huewe peterhu...@gmx.de wrote:
 From: Peter Huewe peterhu...@gmx.de

 This patch fixes the warning Using plain integer as NULL pointer,
 generated by sparse, by replacing
        if(var == 0)
 with
        if (!var)
 after an allocation
 and all other offending 0s with NULL.

 KernelVersion: linus' tree-1f0324c

 Signed-off-by: Peter Huewe peterhu...@gmx.de
 ---
 v2: I changed the patch according to Julia's hints.
 i.e. using if(!buf) instead of if(buf==NULL) after the kmalloc family,
 and other allocations.

Ok, so now we've gone from eliminating a couple of sparse warnings
to going through the rest of the code and jamming in some alternate
coding style when there was nothing wrong with it in the first place.

Don't get me wrong, I appreciate the role of the kernel janitors in
general, but this patch is crap.  It's changes like this that just
lower the signal/noise ratio on *real* work going on, and increasing
the likelihood that some well intentioned janitor screwed up one of
the conversions.

After all, it's not like the author of this patch actually tried the
resulting code.  He only has to mess up one of those two line changes
and we go from driver that works perfectly well to driver that is
100% broken.

There are much better uses of the maintainer's time than going through
patches like this to make sure the submitter didn't screw up the a
conversion that provides no real value.

A change like this:

-   if (buf == NULL) {
+   if (!buf) {

is a worthless change, and there is is a higher chance that one of
them gets screwed up in the patch than what we had to start with.

Devin

-- 
Devin J. Heitmueller - Kernel Labs
http://www.kernellabs.com
--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html