2012-06-08 00:14:32

by Hartley Sweeten

[permalink] [raw]
Subject: [PATCH] staging: comedi: serial2002: quiet NULL pointer sparse noise

Quiet a number of sparse warnings in this file:

warning: Using plain integer as NULL pointer

Signed-off-by: H Hartley Sweeten <[email protected]>
Cc: Ian Abbott <[email protected]>
Cc: Mori Hess <[email protected]>
Cc: Greg Kroah-Hartman <[email protected]>

---

diff --git a/drivers/staging/comedi/drivers/serial2002.c b/drivers/staging/comedi/drivers/serial2002.c
index 9200310..c25808c 100644
--- a/drivers/staging/comedi/drivers/serial2002.c
+++ b/drivers/staging/comedi/drivers/serial2002.c
@@ -643,7 +643,7 @@ err_alloc_configs:

if (result) {
if (devpriv->tty) {
- filp_close(devpriv->tty, 0);
+ filp_close(devpriv->tty, NULL);
devpriv->tty = NULL;
}
}
@@ -653,8 +653,8 @@ err_alloc_configs:

static void serial_2002_close(struct comedi_device *dev)
{
- if (!IS_ERR(devpriv->tty) && (devpriv->tty != 0))
- filp_close(devpriv->tty, 0);
+ if (!IS_ERR(devpriv->tty) && devpriv->tty)
+ filp_close(devpriv->tty, NULL);
}

static int serial2002_di_rinsn(struct comedi_device *dev,
@@ -819,7 +819,7 @@ static int serial2002_attach(struct comedi_device *dev,
s->subdev_flags = SDF_READABLE | SDF_GROUND;
s->n_chan = 0;
s->maxdata = 1;
- s->range_table = 0;
+ s->range_table = NULL;
s->insn_read = &serial2002_ai_rinsn;

/* analog output subdevice */
@@ -828,7 +828,7 @@ static int serial2002_attach(struct comedi_device *dev,
s->subdev_flags = SDF_WRITEABLE;
s->n_chan = 0;
s->maxdata = 1;
- s->range_table = 0;
+ s->range_table = NULL;
s->insn_write = &serial2002_ao_winsn;
s->insn_read = &serial2002_ao_rinsn;

@@ -838,7 +838,7 @@ static int serial2002_attach(struct comedi_device *dev,
s->subdev_flags = SDF_READABLE | SDF_LSAMPL;
s->n_chan = 0;
s->maxdata = 1;
- s->range_table = 0;
+ s->range_table = NULL;
s->insn_read = &serial2002_ei_rinsn;

return 1;


2012-06-08 06:45:14

by Ian Abbott

[permalink] [raw]
Subject: Re: [PATCH] staging: comedi: serial2002: quiet NULL pointer sparse noise

On 08/06/12 01:14, H Hartley Sweeten wrote:
> Quiet a number of sparse warnings in this file:
>
> warning: Using plain integer as NULL pointer

I wonder why sparse warns about that for a literal, unadorned 0? I
suppose NULL is more explicit, but a plain 0 means the same as NULL in a
pointer context (unlike a zero from some random expression).

--
-=( Ian Abbott @ MEV Ltd. E-mail: <[email protected]> )=-
-=( Tel: +44 (0)161 477 1898 FAX: +44 (0)161 718 3587 )=-

2012-06-08 06:51:52

by Dan Carpenter

[permalink] [raw]
Subject: Re: [PATCH] staging: comedi: serial2002: quiet NULL pointer sparse noise

On Fri, Jun 08, 2012 at 07:46:19AM +0100, Ian Abbott wrote:
> On 08/06/12 01:14, H Hartley Sweeten wrote:
> >Quiet a number of sparse warnings in this file:
> >
> >warning: Using plain integer as NULL pointer
>
> I wonder why sparse warns about that for a literal, unadorned 0? I
> suppose NULL is more explicit, but a plain 0 means the same as NULL
> in a pointer context (unlike a zero from some random expression).
>

http://lwn.net/Articles/93574/

regards,
dan carpenter

2012-06-08 09:07:39

by Ian Abbott

[permalink] [raw]
Subject: Re: [PATCH] staging: comedi: serial2002: quiet NULL pointer sparse noise

On 2012/06/08 07:51 AM, Dan Carpenter wrote:
> On Fri, Jun 08, 2012 at 07:46:19AM +0100, Ian Abbott wrote:
>> On 08/06/12 01:14, H Hartley Sweeten wrote:
>>> Quiet a number of sparse warnings in this file:
>>>
>>> warning: Using plain integer as NULL pointer
>>
>> I wonder why sparse warns about that for a literal, unadorned 0? I
>> suppose NULL is more explicit, but a plain 0 means the same as NULL
>> in a pointer context (unlike a zero from some random expression).
>
> http://lwn.net/Articles/93574/

Thanks for the link. I understand the intent to make null pointer
constants easier to recognize. Still, the text of the sparse warning
message "Using plain integer as NULL pointer" is technically incorrect
since 0 is not an integer (plain or otherwise) in a pointer context,
it's a null pointer constant.

I wonder if it also issues that warning for a struct initializer such as
{0} where the first member of the struct is a pointer, or would it
expect you to use {NULL} which is more confusing when the struct
contains a mixture of pointer and non-pointer members?

--
-=( Ian Abbott @ MEV Ltd. E-mail: <[email protected]> )=-
-=( Tel: +44 (0)161 477 1898 FAX: +44 (0)161 718 3587 )=-

2012-06-08 09:49:15

by Dan Carpenter

[permalink] [raw]
Subject: Re: [PATCH] staging: comedi: serial2002: quiet NULL pointer sparse noise

On Fri, Jun 08, 2012 at 10:07:30AM +0100, Ian Abbott wrote:
> I wonder if it also issues that warning for a struct initializer such as
> {0} where the first member of the struct is a pointer, or would it
> expect you to use {NULL} which is more confusing when the struct
> contains a mixture of pointer and non-pointer members?
>

It does warn about that. The fix is to just say:

struct foo bar = {};

regards,
dan carpenter