All of lore.kernel.org
 help / color / mirror / Atom feed
From: Josh Triplett <josh@joshtriplett.org>
To: Christopher Li <sparse@chrisli.org>
Cc: "devel@driverdev.osuosl.org" <devel@driverdev.osuosl.org>,
	Linux-Sparse <linux-sparse@vger.kernel.org>,
	"Marcos A. Di Pietro" <marcosadp@gmail.com>,
	Dan Carpenter <dan.carpenter@oracle.com>
Subject: Re: [PATCH] Staging/comedi: Fixes static analysis warning raised by sparse
Date: Sat, 28 Jun 2014 12:20:25 -0700	[thread overview]
Message-ID: <20140628192020.GA2501@thin> (raw)
In-Reply-To: <CANeU7Qki9Fg=Vz8gryT1bL+BMnjuvWZTH7uNvyk-HjdSPsiiyg@mail.gmail.com>

On Sat, Jun 28, 2014 at 11:07:48AM -0700, Christopher Li wrote:
> On Wed, Jun 11, 2014 at 2:45 PM,  <josh@joshtriplett.org> wrote:
> > On Thu, Jun 12, 2014 at 12:24:25AM +0300, Dan Carpenter wrote:
> >> Let's forward this to the Sparse mailing list.
> >>
> >> We're seeing a Sparse false positive testing
> 
> No, this is a valid complain. See my point follows.
> 
> >> drivers/staging/comedi/drivers/ni_pcimio.c.
> >>
> >>   CHECK   drivers/staging/comedi/drivers/ni_pcimio.c
> >> drivers/staging/comedi/drivers/ni_stc.h:720:26: warning: shift too big (4294967295) for type int
> >> drivers/staging/comedi/drivers/ni_stc.h:720:26: warning: shift too big (4294967295) for type int
> >> drivers/staging/comedi/drivers/ni_stc.h:720:26: warning: shift too big (4294967295) for type int
> >> drivers/staging/comedi/drivers/ni_stc.h:720:26: warning: shift too big (4294967295) for type int
> >>
> >> I have created some test code to demonstrate the problem (attached).
> >>
> >> The check_shift_count() warning is only supposed to be printed for
> >> number literals but because of the way inline functions are expanded it
> >> still complains even though channel is a variable.
> >
> > Thanks for the test case; this definitely makes no sense.  I don't think
> > Sparse will suddenly develop enough range analysis or reachability
> > analysis to handle this case; I think the right answer is to avoid
> > giving such warnings for shifts with a non-constant RHS.
> 
> Sparse can handle inline function expand and some constant
> propagate. In this case, sparse seems doing the right thing.
> Sparse actually sees the channel value being  4294967295 (-1).
> 
> >> static inline unsigned ni_stc_dma_channel_select_bitfield(unsigned channel)
> 
> This is the bug. See this channel is *unsigned*. When -1 pass into
> channel, it become a really large number 4294967295.
> The code does request C compiler to perform left shift 4294967295 bits.
> Which did not make sense.
> 
> >> {
> >>       if (channel < 4)
> >>               return 1 << channel;
> >>       return 0;
> >> }
> >>
> >> static inline void filter(int channel)
> >> {
> >>       if (channel < 0)
> >>               return;
> >>       ni_stc_dma_channel_select_bitfield(channel);
> 
> See this channel is *signed*, with -1 convert to 4294967295.
> This is a bug in the kernel source not sparse.

Except that "filter" has an "int channel" (signed), so it can
successfully test "channel < 0" and return early; it'll never call
ni_stc_dma_channel_select_bitfield(channel) with a negative number.

I do agree that this code should sort out the signedness of its types,
but in this case I don't think the bad shift can actually happen, making
this a false positive.

- Josh Triplett

  reply	other threads:[~2014-06-28 19:20 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <53965E53.5080504@gmail.com>
     [not found] ` <20140610054741.GE5500@mwanda>
     [not found]   ` <DC148C5AA1CEBA4E87973D432B1C2D8825E9AE6A@P3PWEX4MB008.ex4.secureserver.net>
     [not found]     ` <20140611065612.GQ5015@mwanda>
     [not found]       ` <DC148C5AA1CEBA4E87973D432B1C2D8825E9CBD6@P3PWEX4MB008.ex4.secureserver.net>
2014-06-11 21:24         ` [PATCH] Staging/comedi: Fixes static analysis warning raised by sparse Dan Carpenter
2014-06-11 21:45           ` josh
2014-06-15 19:32             ` Sam Ravnborg
2014-06-16  7:40               ` Dan Carpenter
2014-06-16  8:06                 ` Sam Ravnborg
2014-06-28 18:07             ` Christopher Li
2014-06-28 19:20               ` Josh Triplett [this message]
2014-06-29  3:09                 ` Christopher Li
2014-06-30 17:49                   ` Christopher Li
2014-06-30 18:32                     ` Christopher Li

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=20140628192020.GA2501@thin \
    --to=josh@joshtriplett.org \
    --cc=dan.carpenter@oracle.com \
    --cc=devel@driverdev.osuosl.org \
    --cc=linux-sparse@vger.kernel.org \
    --cc=marcosadp@gmail.com \
    --cc=sparse@chrisli.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.