linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Dan Carpenter <dan.carpenter@oracle.com>
To: Kees Cook <keescook@chromium.org>, Nicolai Stange <nicstange@gmail.com>
Cc: Oliver Hartkopp <socketcan@hartkopp.net>,
	Patrick Bellasi <patrick.bellasi@arm.com>,
	linux-sparse@vger.kernel.org, Mao Wenan <maowenan@huawei.com>,
	davem@davemloft.net, netdev@vger.kernel.org,
	linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org,
	Ingo Molnar <mingo@kernel.org>
Subject: Re: [PATCH net-next] net: can: Fix compiling warning
Date: Tue, 13 Aug 2019 15:48:39 +0300	[thread overview]
Message-ID: <20190813124838.GN1935@kadam> (raw)
In-Reply-To: <201908121001.0AC0A90@keescook>

On Mon, Aug 12, 2019 at 10:19:27AM -0700, Kees Cook wrote:
> On Wed, Aug 07, 2019 at 01:50:42PM +0300, Dan Carpenter wrote:
> > On Tue, Aug 06, 2019 at 06:41:44PM +0200, Oliver Hartkopp wrote:
> > > I compiled the code (the original version), but I do not get that "Should it
> > > be static?" warning:
> > > 
> > > user@box:~/net-next$ make C=1
> > >   CALL    scripts/checksyscalls.sh
> > >   CALL    scripts/atomic/check-atomics.sh
> > >   DESCEND  objtool
> > >   CHK     include/generated/compile.h
> > >   CHECK   net/can/af_can.c
> > > ./include/linux/sched.h:609:43: error: bad integer constant expression
> > > ./include/linux/sched.h:609:73: error: invalid named zero-width bitfield
> > > `value'
> > > ./include/linux/sched.h:610:43: error: bad integer constant expression
> > > ./include/linux/sched.h:610:67: error: invalid named zero-width bitfield
> > > `bucket_id'
> > >   CC [M]  net/can/af_can.o
> > 
> > The sched.h errors suppress Sparse warnings so it's broken/useless now.
> > The code looks like this:
> > 
> > include/linux/sched.h
> >    613  struct uclamp_se {
> >    614          unsigned int value              : bits_per(SCHED_CAPACITY_SCALE);
> >    615          unsigned int bucket_id          : bits_per(UCLAMP_BUCKETS);
> >    616          unsigned int active             : 1;
> >    617          unsigned int user_defined       : 1;
> >    618  };
> > 
> > bits_per() is zero and Sparse doesn't like zero sized bitfields.
> 
> I just noticed these sparse warnings too -- what's happening here? Are
> they _supposed_ to be 0-width fields? It doesn't look like it to me:

I'm sorr, I don't even know what code I was looking at before.  I think
my cscope database was stale?  You're right.  Sparse doesn't think it's
zero, it knows that it is 11 and 3.

What's happening is that it's failing the test in in
bad_integer_constant_expression():

	if (!(expr->flags & CEF_ICE))

The ICE in CEF_ICE stands for Integer Constant Expression.  The rule
here is that enums are not constant expressions in c99.  See the
explanation in commit 274c154704db ("constexpr: introduce additional
expression constness tracking flags").

I don't think the CEF_ICE is set properly in evaluate_conditional_expression().
If conditional is constant and it's true and the ->cond_true expression
is constant then the result should be constant as well.  It shouldn't
matter if the cond_false is constant.  But instead it is ANDing all
three sub expressions:

	expr->flags = (expr->conditional->flags & (*true)->flags &
			expr->cond_false->flags & ~CEF_CONST_MASK);

Or actually in this case it's doing:

	if (expr->conditional->flags & (CEF_ACE | CEF_ADDR))
		expr->flags = (*true)->flags & expr->cond_false->flags & ~CEF_CONST_MASK;

But it's the same problem because it's should ignore cond_false.

regards,
dan carpenter

  reply	other threads:[~2019-08-13 12:49 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-08-02  3:36 [PATCH net-next] net: can: Fix compiling warning Mao Wenan
2019-08-02  8:10 ` Oliver Hartkopp
2019-08-02  8:39   ` maowenan
2019-08-06 13:52   ` Dan Carpenter
2019-08-06 16:41     ` Oliver Hartkopp
2019-08-07 10:50       ` Dan Carpenter
2019-08-12 17:19         ` Kees Cook
2019-08-13 12:48           ` Dan Carpenter [this message]
2019-08-12  5:48       ` maowenan
2019-08-12  8:11         ` Oliver Hartkopp
2019-08-02  8:59 ` Sergei Shtylyov
2019-08-05  1:13   ` maowenan
2019-08-05  1:26     ` [PATCH net-next v2] " Mao Wenan
2019-08-05 10:56       ` [v2] " Markus Elfring
2019-08-05 11:57         ` [PATCH net-next v3] net: can: Fix compiling warnings for two functions Mao Wenan
2019-08-05 17:30           ` David Miller
2019-08-06  1:37             ` [PATCH net-next v4] " Mao Wenan
2019-08-06 11:37               ` [v4] " Markus Elfring
2019-08-06 14:40                 ` [PATCH net-next v5] net: can: Fix sparse " Mao Wenan
2019-08-05  1:22 [PATCH net-next] net: can: Fix compiling warning Mao Wenan
2019-08-05  1:22 ` maowenan

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=20190813124838.GN1935@kadam \
    --to=dan.carpenter@oracle.com \
    --cc=davem@davemloft.net \
    --cc=keescook@chromium.org \
    --cc=kernel-janitors@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-sparse@vger.kernel.org \
    --cc=maowenan@huawei.com \
    --cc=mingo@kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=nicstange@gmail.com \
    --cc=patrick.bellasi@arm.com \
    --cc=socketcan@hartkopp.net \
    /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;
as well as URLs for NNTP newsgroup(s).