* [PATCH v2] iio: freq: admv1014: Fix warning about dubious x & !y and improve readability
@ 2022-05-11 9:00 Antoniu Miclaus
2022-05-14 15:11 ` Jonathan Cameron
0 siblings, 1 reply; 2+ messages in thread
From: Antoniu Miclaus @ 2022-05-11 9:00 UTC (permalink / raw)
To: jic23, linux-iio, linux-kernel; +Cc: Antoniu Miclaus, Jonathan Cameron
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>
Signed-off-by: Antoniu Miclaus <antoniu.miclaus@analog.com>
---
changes in v2:
- fix the logic for the input mode set bits
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..1aac5665b5de 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_IF_MODE) ? 0 : 1) |
+ FIELD_PREP(ADMV1014_BB_AMP_PD_MSK,
+ (st->input_mode == ADMV1014_IF_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);
--
2.36.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH v2] iio: freq: admv1014: Fix warning about dubious x & !y and improve readability
2022-05-11 9:00 [PATCH v2] iio: freq: admv1014: Fix warning about dubious x & !y and improve readability Antoniu Miclaus
@ 2022-05-14 15:11 ` Jonathan Cameron
0 siblings, 0 replies; 2+ messages in thread
From: Jonathan Cameron @ 2022-05-14 15:11 UTC (permalink / raw)
To: Antoniu Miclaus; +Cc: linux-iio, linux-kernel, Jonathan Cameron
On Wed, 11 May 2022 12:00:06 +0300
Antoniu Miclaus <antoniu.miclaus@analog.com> wrote:
> 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>
> Signed-off-by: Antoniu Miclaus <antoniu.miclaus@analog.com>
Thanks.
Applied tot he fixes-togreg branch of iio.git.
Thanks,
Jonathan
> ---
> changes in v2:
> - fix the logic for the input mode set bits
> 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..1aac5665b5de 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_IF_MODE) ? 0 : 1) |
> + FIELD_PREP(ADMV1014_BB_AMP_PD_MSK,
> + (st->input_mode == ADMV1014_IF_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);
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2022-05-14 15:03 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-05-11 9:00 [PATCH v2] iio: freq: admv1014: Fix warning about dubious x & !y and improve readability Antoniu Miclaus
2022-05-14 15:11 ` Jonathan Cameron
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox