From: J Freyensee <james_p_freyensee@linux.intel.com>
To: Sam Ravnborg <sam@ravnborg.org>
Cc: Chris Ball <cjb@laptop.org>, Venkatraman S <svenkatr@ti.com>,
linux-mmc@vger.kernel.org, linux-sparse@vger.kernel.org
Subject: Re: [PATCH 2/2] mmc: fix integer assignments to pointer
Date: Tue, 23 Aug 2011 15:40:46 -0700 [thread overview]
Message-ID: <4E542C6E.5080507@linux.intel.com> (raw)
In-Reply-To: <20110823165620.GA9132@merkur.ravnborg.org>
On 08/23/2011 09:56 AM, Sam Ravnborg wrote:
> On Tue, Aug 23, 2011 at 12:31:55PM -0400, Chris Ball wrote:
>> Hi,
>>
>> [Adding linux-sparse@ to CC]
>>
>> On Tue, Aug 23 2011, Venkatraman S wrote:
>>> Fix the sparse warning output
>>> "warning: Using plain integer as NULL pointer"
>>>
>>> Signed-off-by: Venkatraman S<svenkatr@ti.com>
>>> ---
>>> drivers/mmc/card/block.c | 4 ++--
>>> drivers/mmc/core/core.c | 2 +-
>>> drivers/mmc/core/mmc_ops.c | 4 ++--
>>> drivers/mmc/core/sdio_ops.c | 2 +-
>>> 4 files changed, 6 insertions(+), 6 deletions(-)
>>>
>>> diff --git a/drivers/mmc/card/block.c b/drivers/mmc/card/block.c
>>> index 1ff5486..e702c61 100644
>>> --- a/drivers/mmc/card/block.c
>>> +++ b/drivers/mmc/card/block.c
>>> @@ -291,7 +291,7 @@ static int mmc_blk_ioctl_cmd(struct block_device *bdev,
>>> struct mmc_card *card;
>>> struct mmc_command cmd = {0};
>>> struct mmc_data data = {0};
>>> - struct mmc_request mrq = {0};
>>> + struct mmc_request mrq = {NULL};
>>> struct scatterlist sg;
>>> int err;
>>> [...]
>>
>> The sparse warning is mistaken. Or I'm mistaken. But I suspect it's
>> the sparse warning.
>>
Okay, stupid question times:
>>> - struct mmc_request mrq = {0};
this is 'struct mmc_request mrq' and not 'struct mmc_request *mrq', right?
Then I think the sparse warning is correct. From my experience, sparse
is very clear: if any variable is defined as a pointer, you use NULL to
reset the pointer instead of '0', and if any variable is a normal
variable, you use '0' to reset the variable. I don't think sparse is
smart enough to look at the underlying variables, which in this case,
mrq contains members that are pointers to something.
in this case, the defined variable is not a pointer, rather a variable
named mrq that is of type 'struct mmc_request'. Therefore, 0 is correct
to use and NULL is incorrect.
If you want it to be sparse-correct as well as human-readable correct,
you probably should write the code that explicitly shows assigning each
pointer member of mrq to NULL, ie:
struct mmc_request mrq;
mrq.sbc = NULL;
mrq.cmd = NULL;
mrq.data = NULL;
.
.
etc.
>> The {0} syntax is covered by:
>>
>> [6.7.8.21] If there are fewer initializers in a brace-enclosed list
>> than there are elements or members of an aggregate, or fewer
>> characters in a string literal used to initialize an array of known
>> size than there are elements in the array, the remainder of the
>> aggregate shall be initialized implicitly the same as objects that
>> have static storage duration.
>>
>> So we're not assigning 0 to a pointer, or whatever sparse thinks we're
>> doing -- we're initializing every member of the struct with 0, which is
>> a good and safe way to initialize it.
>>
>> Sparse folks, any comment?
>
> The struct looks like this:
> struct mmc_request {
> struct mmc_command *sbc; /* SET_BLOCK_COUNT for multiblock */
> struct mmc_command *cmd;
> struct mmc_data *data;
> struct mmc_command *stop;
>
> struct completion completion;
> void (*done)(struct mmc_request *);/* completion function */
> };
>
>
> So you assing '0' to sbc - which is a pointer.
> So sparse warning is correct.
>
> Sam
> --
> To unsubscribe from this list: send the line "unsubscribe linux-mmc" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
--
J (James/Jay) Freyensee
Storage Technology Group
Intel Corporation
next prev parent reply other threads:[~2011-08-23 22:40 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-08-23 15:46 [PATCH 0/2] mmc: trivial patches to fix sparse warnings Venkatraman S
2011-08-23 15:46 ` [PATCH 1/2] mmc: queue: declare mmc_alloc_sg as static Venkatraman S
2011-08-23 15:46 ` [PATCH 2/2] mmc: fix integer assignments to pointer Venkatraman S
2011-08-23 16:31 ` Chris Ball
2011-08-23 16:56 ` Sam Ravnborg
2011-08-23 17:36 ` Chris Ball
2011-08-23 22:40 ` J Freyensee [this message]
2011-08-24 11:23 ` S, Venkatraman
2011-08-23 17:28 ` Josh Triplett
2011-08-23 18:04 ` Ben Pfaff
2011-08-23 18:13 ` Josh Triplett
2011-08-23 18:28 ` Chris Ball
2011-08-23 20:22 ` Sam Ravnborg
2011-08-23 20:38 ` Sam Ravnborg
2011-08-24 18:33 ` S, Venkatraman
2011-08-23 20:43 ` Ben Pfaff
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4E542C6E.5080507@linux.intel.com \
--to=james_p_freyensee@linux.intel.com \
--cc=cjb@laptop.org \
--cc=linux-mmc@vger.kernel.org \
--cc=linux-sparse@vger.kernel.org \
--cc=sam@ravnborg.org \
--cc=svenkatr@ti.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox