Re: [PATCH 0/9] bitfield: add FIELD_GET_SIGNED()
From: Jonathan Cameron
Date: Fri Apr 24 2026 - 08:10:33 EST
On Fri, 17 Apr 2026 13:36:11 -0400
Yury Norov <ynorov@xxxxxxxxxx> wrote:
> The bitfields are designed in assumption that fields contain unsigned
> integer values, thus extracting the values from the field implies
> zero-extending.
>
> Some drivers need to sign-extend their fields, and currently do it like:
>
> dc_re += sign_extend32(FIELD_GET(0xfff000, tmp), 11);
> dc_im += sign_extend32(FIELD_GET(0xfff, tmp), 11);
>
> It's error-prone because it relies on user to provide the correct
> index of the most significant bit.
>
> This series adds a signed version of FIELD_GET(), which is the more
> convenient and compiles (on x86_64) to just a couple instructions:
> shl and sar.
>
> Patch #1 adds FIELD_GET_SIGNED(), and the rest of the series applies it
> tree-wide.
>
Just a quick heads up that I'm beginning to assume that this series
will land in some form. If it does can we do it as an immutable branch
as I'm suggesting it gets used in some other patches in that should land
in the new cycle.
Thanks,
Jonathan
> Yury Norov (9):
> bitfield: add FIELD_GET_SIGNED()
> x86/extable: switch to using FIELD_GET_SIGNED()
> iio: intel_dc_ti_adc: switch to using
> iio: magnetometer: yas530: switch to using FIELD_GET_SIGNED()
> iio: pressure: bmp280: switch to using
> iio: mcp9600: switch to using FIELD_GET_SIGNED()
> wifi: rtw89: switch to using FIELD_GET_SIGNED()
> rtc: rv3032: switch to using FIELD_GET_SIGNED()
> ptp: switch to using FIELD_GET_SIGNED()
>
> arch/x86/include/asm/extable_fixup_types.h | 13 ++++---------
> arch/x86/mm/extable.c | 2 +-
> drivers/iio/adc/intel_dc_ti_adc.c | 4 ++--
> drivers/iio/magnetometer/yamaha-yas530.c | 12 ++++++------
> drivers/iio/pressure/bmp280-core.c | 2 +-
> drivers/iio/temperature/mcp9600.c | 2 +-
> .../net/wireless/realtek/rtw89/rtw8852a_rfk.c | 4 ++--
> .../net/wireless/realtek/rtw89/rtw8852b_common.c | 4 ++--
> .../net/wireless/realtek/rtw89/rtw8852b_rfk.c | 4 ++--
> drivers/net/wireless/realtek/rtw89/rtw8852c.c | 4 ++--
> drivers/ptp/ptp_fc3.c | 4 ++--
> drivers/rtc/rtc-rv3032.c | 2 +-
> include/linux/bitfield.h | 16 ++++++++++++++++
> 13 files changed, 42 insertions(+), 31 deletions(-)
>