public inbox for linux-iio@vger.kernel.org
 help / color / mirror / Atom feed
From: Jonathan Cameron <jic23@kernel.org>
To: linux-iio@vger.kernel.org
Cc: Jonathan Cameron <Jonathan.Cameron@huawei.com>,
	Antoniu Miclaus <antoniu.miclaus@analog.com>
Subject: Re: [PATCH] iio: freq: admv1014: Fix warning about dubious x & !y and improve readability
Date: Sun, 10 Apr 2022 18:16:28 +0100	[thread overview]
Message-ID: <20220410181628.084fcf3b@jic23-huawei> (raw)
In-Reply-To: <20220319181401.136810-1-jic23@kernel.org>

On Sat, 19 Mar 2022 18:14:01 +0000
Jonathan Cameron <jic23@kernel.org> wrote:

> From: Jonathan Cameron <Jonathan.Cameron@huawei.com>
> 
> The warning comes from __BF_FIELD_CHECK()
> specifically
> 
> BUILD_BUG_ON_MSG(__builtin_constant_p(_val) ?		\
> 		 ~((_mask) >> __bf_shf(_mask)) & (_val) : 0, \
> 		 _pfx "value too large for the field"); \
> 
> The code was using !(enum value) which is not particularly easy to follow
> so replace that with explicit matching and use of ? 0 : 1; or ? 1 : 0;
> to improve readability.
> 
> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
> Cc: Antoniu Miclaus <antoniu.miclaus@analog.com>

Antoniu, or anyone else who has time, can you sanity check this one?
I'd like to clean up the warning asap but don't really trust myself
enough to not have done something stupid ;)

Jonathan

> ---
>  drivers/iio/frequency/admv1014.c | 6 ++++--
>  1 file changed, 4 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/iio/frequency/admv1014.c b/drivers/iio/frequency/admv1014.c
> index a7994f8e6b9b..802835efbec7 100644
> --- a/drivers/iio/frequency/admv1014.c
> +++ b/drivers/iio/frequency/admv1014.c
> @@ -700,8 +700,10 @@ static int admv1014_init(struct admv1014_state *st)
>  			 ADMV1014_DET_EN_MSK;
>  
>  	enable_reg = FIELD_PREP(ADMV1014_P1DB_COMPENSATION_MSK, st->p1db_comp ? 3 : 0) |
> -		     FIELD_PREP(ADMV1014_IF_AMP_PD_MSK, !(st->input_mode)) |
> -		     FIELD_PREP(ADMV1014_BB_AMP_PD_MSK, st->input_mode) |
> +		     FIELD_PREP(ADMV1014_IF_AMP_PD_MSK,
> +				(st->input_mode == ADMV1014_IQ_MODE) ? 0 : 1) |
> +		     FIELD_PREP(ADMV1014_BB_AMP_PD_MSK,
> +				(st->input_mode == ADMV1014_IQ_MODE) ? 1 : 0) |
>  		     FIELD_PREP(ADMV1014_DET_EN_MSK, st->det_en);
>  
>  	return __admv1014_spi_update_bits(st, ADMV1014_REG_ENABLE, enable_reg_msk, enable_reg);


  reply	other threads:[~2022-04-10 17:08 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-19 18:14 [PATCH] iio: freq: admv1014: Fix warning about dubious x & !y and improve readability Jonathan Cameron
2022-04-10 17:16 ` Jonathan Cameron [this message]
2022-04-11  7:18   ` Miclaus, Antoniu
2022-04-11  8:44     ` Jonathan Cameron

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=20220410181628.084fcf3b@jic23-huawei \
    --to=jic23@kernel.org \
    --cc=Jonathan.Cameron@huawei.com \
    --cc=antoniu.miclaus@analog.com \
    --cc=linux-iio@vger.kernel.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox