mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Johannes Berg <johannes@sipsolutions.net>
To: linux-wireless@vger.kernel.org
Cc: linux-kernel@vger.kernel.org, John Garry <john.garry@huawei.com>,
	nbd@nbd.name
Subject: Re: [PATCH] bitfield: use BUILD_BUG_ON_ZERO()
Date: Fri, 12 Oct 2018 21:45:03 +0200	[thread overview]
Message-ID: <18f6349cacfb6dc6fe8f1d12685ff6368c1cfbe0.camel@sipsolutions.net> (raw)
In-Reply-To: <20181012092104.2361-1-johannes@sipsolutions.net> (sfid-20181012_112145_400521_10F221F7)

Umm, I really should've tested this :-)

As John points out, it can't possibly compile, e.g. because

> +#define __BF_FIELD_CHECK(_mask, _reg, _val)				\
> +	BUILD_BUG_ON_ZERO(!__builtin_constant_p(_mask)) +		\

this isn't actually a constant expression.

This would be harmless, since e.g.

> +	BUILD_BUG_ON_ZERO((_mask) == 0) +				\

this already forces _mask to be a constant, but

> +	BUILD_BUG_ON_ZERO(__builtin_constant_p(_val) ?			\
> +				~((_mask) >> __bf_shf(_mask)) & (_val) : 0) + \

we can't actually replicate this check.

We could just remove this as well, at the expense of not getting any
warnings if you write something like

	FIELD_PREP(0xf, 32);

Realistically, FIELD_PREP() is the only one that makes sense in a pure
constant context though, so we could just add __FIELD_PREP for that,
*with* all the checks. I'll send out a patch in a second that has this
and also adds __{u,le,be}{16,32,64}encode_bits().

johannes


  reply	other threads:[~2018-10-12 19:45 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-10-12  9:21 Johannes Berg
2018-10-12 19:45 ` Johannes Berg [this message]
2018-10-13  1:22 ` kbuild test robot
2018-10-13  1:26 ` kbuild test robot

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=18f6349cacfb6dc6fe8f1d12685ff6368c1cfbe0.camel@sipsolutions.net \
    --to=johannes@sipsolutions.net \
    --cc=john.garry@huawei.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-wireless@vger.kernel.org \
    --cc=nbd@nbd.name \
    /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

all inboxes | Powered by JetHome®