* [PATCH] iio: magnetometer: bmc150: simplify member access formatting
@ 2026-06-07 14:21 Hungyu Lin
2026-06-08 17:50 ` Jonathan Cameron
0 siblings, 1 reply; 2+ messages in thread
From: Hungyu Lin @ 2026-06-07 14:21 UTC (permalink / raw)
To: Jonathan Cameron
Cc: linux-iio, linux-kernel, David Lechner, Nuno Sá,
Andy Shevchenko, Hungyu Lin
Keep the structure member dereference on a single line to
improve readability.
Signed-off-by: Hungyu Lin <dennylin0707@gmail.com>
---
drivers/iio/magnetometer/bmc150_magn.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/drivers/iio/magnetometer/bmc150_magn.c b/drivers/iio/magnetometer/bmc150_magn.c
index bf2551988008..d2075a18e6a7 100644
--- a/drivers/iio/magnetometer/bmc150_magn.c
+++ b/drivers/iio/magnetometer/bmc150_magn.c
@@ -311,8 +311,7 @@ static int bmc150_magn_set_odr(struct bmc150_magn_data *data, int val)
ret = regmap_update_bits(data->regmap,
BMC150_MAGN_REG_OPMODE_ODR,
BMC150_MAGN_MASK_ODR,
- bmc150_magn_samp_freq_table[i].
- reg_val <<
+ bmc150_magn_samp_freq_table[i].reg_val <<
BMC150_MAGN_SHIFT_ODR);
if (ret < 0)
return ret;
--
2.34.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] iio: magnetometer: bmc150: simplify member access formatting
2026-06-07 14:21 [PATCH] iio: magnetometer: bmc150: simplify member access formatting Hungyu Lin
@ 2026-06-08 17:50 ` Jonathan Cameron
0 siblings, 0 replies; 2+ messages in thread
From: Jonathan Cameron @ 2026-06-08 17:50 UTC (permalink / raw)
To: Hungyu Lin
Cc: linux-iio, linux-kernel, David Lechner, Nuno Sá,
Andy Shevchenko
On Sun, 7 Jun 2026 14:21:20 +0000
Hungyu Lin <dennylin0707@gmail.com> wrote:
> Keep the structure member dereference on a single line to
> improve readability.
>
> Signed-off-by: Hungyu Lin <dennylin0707@gmail.com>
> ---
> drivers/iio/magnetometer/bmc150_magn.c | 3 +--
> 1 file changed, 1 insertion(+), 2 deletions(-)
>
> diff --git a/drivers/iio/magnetometer/bmc150_magn.c b/drivers/iio/magnetometer/bmc150_magn.c
> index bf2551988008..d2075a18e6a7 100644
> --- a/drivers/iio/magnetometer/bmc150_magn.c
> +++ b/drivers/iio/magnetometer/bmc150_magn.c
> @@ -311,8 +311,7 @@ static int bmc150_magn_set_odr(struct bmc150_magn_data *data, int val)
> ret = regmap_update_bits(data->regmap,
> BMC150_MAGN_REG_OPMODE_ODR,
> BMC150_MAGN_MASK_ODR,
> - bmc150_magn_samp_freq_table[i].
> - reg_val <<
> + bmc150_magn_samp_freq_table[i].reg_val <<
> BMC150_MAGN_SHIFT_ODR);
That is indeed ugly!
However, preferred route if we are touching the code is to use field prep for these rather
than explicit shifts (allowing the shift declaration to be dropped!) If you want
to make that change though it needs to be driver wide rather than just for this
one case.
FIELD_PREP(BMC150_MAGN_MASK_ODR,
bmc150_magn_samp_freq_table[i].reg_val),
Given that whole block is very long line, it may be worth looking to see if a broader
refactor can be done to make the whole thing more readable.
For this type of code there is a standard trick - invert the check in the loop
After a bit more tidying up (which is fine in one patch I think given this
is all about improving this function)
static int bmc150_magn_set_odr(struct bmc150_magn_data *data, int val)
{
for (unsigned int i = 0; i < ARRAY_SIZE(bmc150_magn_samp_freq_table); i++) {
if (bmc150_magn_samp_freq_table[i].freq != val)
continue;
return regmap_update_bits(data->regmap,
BMC150_MAGN_REG_OPMODE_ODR,
BMC150_MAGN_MASK_ODR,
FIELD_PREP(BMC150_MAGN_MASK_ODR,
bmc150_magn_samp_freq_table[i].reg_val));
}
return -EINVAL;
}
I don't really like the line going that near the absolute limit of 100 but
it seems to me that introducing a local variable would result in slightly
less readable code.
Anyhow, tidy it up along the lies of that code but also apply FIELD_PREP()
FIELD_GET() for all appropriate fields (and check for the relevant includes)
Thanks,
Jonathan
> if (ret < 0)
> return ret;
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-06-08 17:50 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-06-07 14:21 [PATCH] iio: magnetometer: bmc150: simplify member access formatting Hungyu Lin
2026-06-08 17:50 ` Jonathan Cameron
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox