From: David Lechner <dlechner@baylibre.com>
To: Jonathan Cameron <jic23@kernel.org>,
Rafael Lopes Santana <santanarl@usp.br>
Cc: nuno.sa@analog.com, andy@kernel.org, linux-iio@vger.kernel.org
Subject: Re: [PATCH] Replace manual bitfield manipulations with field_get
Date: Tue, 5 May 2026 08:52:44 -0500 [thread overview]
Message-ID: <946edc28-dbf4-490a-98df-615e1a4f6b21@baylibre.com> (raw)
In-Reply-To: <20260505131642.75f3c72a@jic23-huawei>
On 5/5/26 7:16 AM, Jonathan Cameron wrote:
> On Thu, 30 Apr 2026 22:15:46 -0300
> Rafael Lopes Santana <santanarl@usp.br> wrote:
>
>> From: Rafael Lopes Santana <santanarl@usp.br>
>>
>> Signed-off-by: Rafael Lopes Santana <santanarl@usp.br>
> Hi Rafael,
>
> Additional comments inline.
>
> Given this is packing code that is using shifts in one direction even
> in your new version I'm not seeing a clear advantage to this change.
>
>> ---
>> drivers/iio/proximity/aw96103.c | 10 +++++-----
>> 1 file changed, 5 insertions(+), 5 deletions(-)
>>
>> diff --git a/drivers/iio/proximity/aw96103.c b/drivers/iio/proximity/aw96103.c
>> index 3472a2c36e44..a8a6ae02438a 100644
>> --- a/drivers/iio/proximity/aw96103.c
>> +++ b/drivers/iio/proximity/aw96103.c
>> @@ -591,7 +591,7 @@ static void aw96103_cfg_update(const struct firmware *fw, void *data)
>> }
>>
>> for (i = 0; i < aw96103->max_channels; i++) {
>> - if ((aw96103->chan_en >> i) & 0x01)
>> + if ((field_get(BIT(i), aw96103->chan_en)))
>> aw96103->channels_arr[i].used = true;
>> else
>> aw96103->channels_arr[i].used = false;
>> @@ -643,10 +643,10 @@ static irqreturn_t aw96103_irq(int irq, void *data)
>> if (!aw96103->channels_arr[i].used)
>> continue;
>>
>> - curr_status = (((curr_status_val >> (24 + i)) & 0x1)) |
>> - (((curr_status_val >> (16 + i)) & 0x1) << 1) |
>> - (((curr_status_val >> (8 + i)) & 0x1) << 2) |
>> - (((curr_status_val >> i) & 0x1) << 3);
>> + curr_status = (field_get(BIT(24+i), curr_status_val)) |
>
> Look at coding style for the kernel. You are missing some white space here.
>
> I don't like this but if you were to do it for consistency it would be
>
> curr_status = FIELD_PREP(BIT(0), field_get(BIT(24 + i), cur_status_val) |
> FIELD_PREP(BIT(1), field_get(BIT(16 + i), cur_status_val) |
> FIELD_PREP(BIT(2), field_get(BIT(8 + i), cur_status_val) |
> FIELD_PREP(BIT(3), field_get(BIT(i), cur_status_val);
I actually find this much quicker to understand the intention of the code.
>
> The benefit of that is slightly more than what you have but it's still ugly enough
> I'm not sure it's worth doing. Note FIELD_PREP() in this direction as the mask is constant
>
> Given the bit smashing going on here is always going to be ugly I'm not sure
> any of these are better than the original though I'm open to hearing what others
> think of this more complete version.
>
>
>> + ((field_get(BIT(16+i), curr_status_val)) << 1) |
>> + ((field_get(BIT(8+i), curr_status_val)) << 2) |
>> + ((field_get(BIT(i), curr_status_val)) << 3);
>> if (aw96103->channels_arr[i].old_irq_status == curr_status)
>> continue;
>>
>
next prev parent reply other threads:[~2026-05-05 13:52 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-01 1:15 [PATCH] Replace manual bitfield manipulations with field_get Rafael Lopes Santana
2026-05-01 12:30 ` Andy Shevchenko
2026-05-01 14:34 ` Joshua Crofts
2026-05-01 14:38 ` Joshua Crofts
2026-05-01 18:18 ` Andy Shevchenko
2026-05-01 18:41 ` Joshua Crofts
2026-05-01 18:47 ` Andy Shevchenko
2026-05-05 12:16 ` Jonathan Cameron
2026-05-05 13:52 ` David Lechner [this message]
2026-05-05 16:14 ` 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=946edc28-dbf4-490a-98df-615e1a4f6b21@baylibre.com \
--to=dlechner@baylibre.com \
--cc=andy@kernel.org \
--cc=jic23@kernel.org \
--cc=linux-iio@vger.kernel.org \
--cc=nuno.sa@analog.com \
--cc=santanarl@usp.br \
/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