Non-const bitfield helpers
Subsystems (20)
Geert Uytterhoeven
maintainerv5 cover Non-const bitfield helpers
Hi all,
<linux/bitfield.h> contains various helpers for accessing bitfields, as typically used in hardware registers for memory-mapped I/O blocks. These helpers ensure type safety, and deduce automatically shift values from mask values, avoiding mistakes due to inconsistent shifts and masks, and leading to a reduction in source code size.
The existing FIELD_{GET,PREP}() macros are limited to compile-time constants. However, it is very common to prepare or extract bitfield elements where the bitfield mask is not a compile-time constant (e.g. it comes from a table, or is created by shifting a compile-time constant). To avoid this limitation, the AT91 clock driver introduced its own field_{prep,get}() macros. During the past four years, these have been copied to multiple drivers, and more copies are on their way[1], leading to the obvious review comment "please move this to <linux/bitfield.h>".
Hence this series
1. Takes preparatory steps in drivers definining local
field_{get,prep}() macros (patches 1-10),
2. Makes field_{prep,get}() available for general use (patch 11),
3. Converts drivers with local variants to the common helpers (patches
12-21),
4. Converts a few Renesas drivers to the existing FIELD_{GET,PREP}()
and the new field_{get,prep}() helpers (patches 22-23).Alternatives would be to use the typed {u*,be*,le*,...}_{get,encode}_bits() macros instead (which currently do not work with non-constant masks either, and the first attempt to change that generates much worse code), or to store the low bit and width of the mask instead (which would require changing all code that passes masks directly, and also generates worse code).
Changes compared to v4[2]:
- Add preparatory patches to #undef field_{get,prep}() in individual drivers before defining local variants,
- Update new smi330 IIO IMU driver,
- Add Acked-by,
- Document that mask must be non-zero,
- Document typical usage pattern,
- Recommend using FIELD_{PREP,GET}() directly to ensure compile-time constant masks,
- Check BITS_PER_TYPE(mask) instead of sizeof(mask),
- Wire field_{get,prep}() to FIELD_{GET,PREP}() when mask is constant, to improve type checking,
- Extract conversion of individual drivers into separate patches.
Changes compared to v3[3]:
- Update recently introduced FIELD_MODIFY() macro,
- Add Acked-by,
- Rebase on top of commit 7c68005a46108ffa ("crypto: qat - relocate power management debugfs helper APIs") in v6.17-rc1,
- Convert more recently introduced upstream copies:
- drivers/edac/ie31200_edac.c
- drivers/iio/dac/ad3530r.c
Changes compared to v2[4]:
- New patch "[PATCH v3 1/4] bitfield: Drop underscores from macro parameters",
- Add Acked-by,
- Drop underscores from macro parameters,
- Use __auto_type where possible,
- Correctly cast reg to the mask type,
- Introduces __val and __reg intermediates to simplify the actual operation,
- Drop unneeded parentheses,
- Clarify having both FIELD_{GET,PREP}() and field_{get,prep}(),
Changes compared to v1[5]:
- Cast val resp. reg to the mask type,
- Fix 64-bit use on 32-bit architectures,
- Convert new upstream users:
- drivers/crypto/intel/qat/qat_common/adf_gen4_pm_debugfs.c
- drivers/gpio/gpio-aspeed.c
- drivers/iio/temperature/mlx90614.c
- drivers/pinctrl/nuvoton/pinctrl-ma35.c
- sound/usb/mixer_quirks.c
- Convert new user queued in renesas-devel for v6.15:
- drivers/soc/renesas/rz-sysc.c
- Drop the last 14 RFC patches.
They can be updated/resubmitted/applied later.
In the meantime, one more copy ended up in the IIO tree and in linux-next (commit 89cba586b8b4cde0 ("iio: imu: smi330: Add driver" in next-20251021 and later). As this commit is not yet upstream, I cannot apply any updates (patches 10 and 21) for this driver yet.
I plan to take all patches (except 10 and 21) through the Renesas tree, and provide an immutable branch + tag with all patches (except 10, 21, 22, and 23), so subsystem maintainers that want to queue patches that depend on the new helpers can easily do so. Once that tag has been merged in subsystem trees or upstream, I plan to update and resend actual conversions (see patches 4-17 in v1[5]).
To avoid build issues in linux-next, the IIO maintainer should:
1. Apply patch 10 now, and
2. Apply patch 21 later, either after
a. merging my immutable branch/tag, or
b. the new helpers in <linux/bitfield.h> are upstream,
Note that there is also a minor conflict with linux-next due to the removal of an include file from drivers/gpio/gpio-aspeed.c.
Thanks for your comments!
[1] Work-in-progress new copies posted during the last few months (there
may be more):
- "[PATCH 10/24] mtd: rawnand: sunxi: cosmetic: move ECC_PAT_FOUND register in SoC caps"
https://lore.kernel.org/[email protected]
- "[PATCH 12/24] mtd: rawnand: sunxi: cosmetic: move NFC_ECC_MODE offset in SoC caps"
https://lore.kernel.org/[email protected]
- "[PATCH v2 05/15] mtd: rawnand: sunxi: rework pattern found registers"
https://lore.kernel.org/[email protected]
- "[PATCH v2 07/15] mtd: rawnand: sunxi: introduce ecc_mode_mask in sunxi_nfc_caps"
https://lore.kernel.org/[email protected]
- "[PATCH v5 2/2] iio: imu: smi330: Add driver"
https://lore.kernel.org/[email protected]
Now in iio/togreg and linux-next (next-20251021 and later)
- "[PATCH v3 2/8] pwm: rzg2l-gpt: Add info variable to struct rzg2l_gpt_chip"
https://lore.kernel.org/[email protected]
- "[PATCH v2 3/3] gpio: gpio-ltc4283: Add support for the LTC4283 Swap Controller"
https://lore.kernel.org/[email protected]
- "[PATCH v7 15/24] media: i2c: add Maxim GMSL2/3 serializer and deserializer framework"
https://lore.kernel.org/[email protected]
[2] "[PATCH v4 0/4] Non-const bitfield helpers"
https://lore.kernel.org/[email protected] [3] "[PATCH v3 0/4] Non-const bitfield helpers" https://lore.kernel.org/all/[email protected]/ [4] "[PATCH v2 0/3] Non-const bitfield helpers" https://lore.kernel.org/all/[email protected] [5] "[PATCH 00/17] Non-const bitfield helper conversions" https://lore.kernel.org/all/[email protected]
Geert Uytterhoeven (23):
clk: at91: pmc: #undef field_{get,prep}() before definition
crypto: qat - #undef field_get() before local definition EDAC/ie31200: #undef field_get() before local definition
gpio: aspeed: #undef field_{get,prep}() before local definition
iio: dac: ad3530r: #undef field_prep() before local definition
iio: mlx90614: #undef field_{get,prep}() before local definition
pinctrl: ma35: #undef field_{get,prep}() before local definition
soc: renesas: rz-sysc: #undef field_get() before local definition
ALSA: usb-audio: #undef field_{get,prep}() before local definition [next] iio: imu: smi330: #undef field_{get,prep}() before definition
bitfield: Add non-constant field_{prep,get}() helpers
clk: at91: Convert to common field_{get,prep}() helpers
crypto: qat - convert to common field_get() helper EDAC/ie31200: Convert to common field_get() helper
gpio: aspeed: Convert to common field_{get,prep}() helpers
iio: dac: Convert to common field_prep() helper
iio: mlx90614: Convert to common field_{get,prep}() helpers
pinctrl: ma35: Convert to common field_{get,prep}() helpers
soc: renesas: rz-sysc: Convert to common field_get() helper
ALSA: usb-audio: Convert to common field_{get,prep}() helpers [next] iio: imu: smi330: Convert to common field_{get,prep}() helpers
clk: renesas: Use bitfield helpers
soc: renesas: Use bitfield helpers
drivers/clk/at91/clk-peripheral.c | 1 + drivers/clk/at91/pmc.h | 3 -- drivers/clk/renesas/clk-div6.c | 6 +-- drivers/clk/renesas/rcar-gen3-cpg.c | 15 ++---- drivers/clk/renesas/rcar-gen4-cpg.c | 9 ++-- .../intel/qat/qat_common/adf_pm_dbgfs_utils.c | 8 +-- drivers/edac/ie31200_edac.c | 4 +- drivers/gpio/gpio-aspeed.c | 5 +- drivers/iio/dac/ad3530r.c | 3 -- drivers/iio/imu/smi330/smi330_core.c | 4 -- drivers/iio/temperature/mlx90614.c | 5 +- drivers/pinctrl/nuvoton/pinctrl-ma35.c | 4 -- drivers/soc/renesas/renesas-soc.c | 4 +- drivers/soc/renesas/rz-sysc.c | 3 +- include/linux/bitfield.h | 54 +++++++++++++++++++ sound/usb/mixer_quirks.c | 4 -- 16 files changed, 73 insertions(+), 59 deletions(-)
Signature · 12 lines
2.43.0
Gr{oetje,eeting}s,
Geert
--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]
In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
-- Linus TorvaldsGeert Uytterhoeven
maintainerPATCH v5 1/23 clk: at91: pmc: #undef field_{get,prep}() before definition
Prepare for the advent of globally available common field_get() and field_prep() macros by undefining the symbols before defining local variants. This prevents redefinition warnings from the C preprocessor when introducing the common macros later.
--
v5:
- New.
--- drivers/clk/at91/pmc.h | 2 ++ 1 file changed, 2 insertions(+)
drivers/clk/at91/pmc.h +2 -0
@@ -117,7 +117,9 @@ struct at91_clk_pms {unsigned int parent; }; +#undef field_get#define field_get (_mask, _reg) (((_reg) & (_mask)) >> (ffs(_mask) - 1)) +#undef field_prep#define field_prep (_mask, _val) (((_val) << (ffs(_mask) - 1)) & (_mask))#define ndck (a, s) (a[s - 1].id + 1)
Signature · 1 line
2.43.0
Re: [PATCH v5 01/23] clk: at91: pmc: #undef field_{get,prep}() before definition
Quoted 7 lines · Geert Uytterhoeven
Prepare for the advent of globally available common
field_get()andfield_prep()macros by undefining the symbols before defining local variants. This prevents redefinition warnings from the C preprocessor when introducing the common macros later.Suggested-by Yury Norov <[email protected]>Signed-off-by Geert Uytterhoeven <[email protected]>
Quoted 24 lines
--
v5:
- New.--- drivers/clk/at91/pmc.h | 2 ++ 1 file changed, 2 insertions(+)drivers/clk/at91/pmc.h +2
-0@@ -117,7 +117,9 @@ struct at91_clk_pms {unsigned int parent; }; +#undef field_get#define field_get (_mask, _reg) (((_reg) & (_mask)) >> (ffs(_mask) - 1)) +#undef field_prep#define field_prep (_mask, _val) (((_val) << (ffs(_mask) - 1)) & (_mask))#define ndck (a, s) (a[s - 1].id + 1)Signature · 1 line
2.43.0
Signature · 3 lines
Alexandre Belloni, co-owner and COO, Bootlin Embedded Linux and Kernel engineering https://bootlin.com
Geert Uytterhoeven
maintainerPATCH v5 2/23 crypto: qat - #undef field_get() before local definition
In reply to Geert UytterhoevenPrepare for the advent of a globally available common field_get() macro by undefining the symbol before defining a local variant. This prevents redefinition warnings from the C preprocessor when introducing the common macro later.
--
v5:
- New.
--- drivers/crypto/intel/qat/qat_common/adf_pm_dbgfs_utils.c | 1 + 1 file changed, 1 insertion(+)
drivers/crypto/intel/qat/qat_common/adf_pm_dbgfs_utils.c +1 -0
@@ -11,6 +11,7 @@* pm_scnprint_table(), making it not compile time constant, so the compile * asserts from FIELD_GET() or u32_get_bits() won't be fulfilled. */ +#undef field_get#define field_get (_mask, _reg) (((_reg) & (_mask)) >> (ffs(_mask) - 1))#define PM_INFO_MAX_KEY_LEN 21
Signature · 1 line
2.43.0
Re: [PATCH v5 02/23] crypto: qat - #undef field_get() before local definition
Quoted 7 lines · Geert Uytterhoeven
Prepare for the advent of a globally available common
field_get()macro by undefining the symbol before defining a local variant. This prevents redefinition warnings from the C preprocessor when introducing the common macro later.Suggested-by Yury Norov <[email protected]>Signed-off-by Geert Uytterhoeven <[email protected]>
Quoted 22 lines
--
v5:
- New.--- drivers/crypto/intel/qat/qat_common/adf_pm_dbgfs_utils.c | 1 + 1 file changed, 1 insertion(+)drivers/crypto/intel/qat/qat_common/adf_pm_dbgfs_utils.c +1
-0@@ -11,6 +11,7 @@* pm_scnprint_table(), making it not compile time constant, so the compile * asserts from FIELD_GET() or u32_get_bits() won't be fulfilled. */ +#undef field_get#define field_get (_mask, _reg) (((_reg) & (_mask)) >> (ffs(_mask) - 1))#define PM_INFO_MAX_KEY_LEN 21Signature · 1 line
2.43.0
Geert Uytterhoeven
maintainerPATCH v5 3/23 EDAC/ie31200: #undef field_get() before local definition
In reply to Geert UytterhoevenPrepare for the advent of a globally available common field_get() macro by undefining the symbol before defining a local variant. This prevents redefinition warnings from the C preprocessor when introducing the common macro later.
--
v5:
- New.
--- drivers/edac/ie31200_edac.c | 1 + 1 file changed, 1 insertion(+)
drivers/edac/ie31200_edac.c +1 -0
@@ -140,6 +140,7 @@#define IE31200_CAPID0_ECC BIT(1)/* Non-constant mask variant of FIELD_GET() */ +#undef field_get#define field_get (_mask, _reg) (((_reg) & (_mask)) >> (ffs(_mask) - 1))static int nr_channels;
Signature · 1 line
2.43.0
Geert Uytterhoeven
maintainerPATCH v5 4/23 gpio: aspeed: #undef field_{get,prep}() before local definition
In reply to Geert UytterhoevenPrepare for the advent of globally available common field_get() and field_prep() macros by undefining the symbols before defining local variants. This prevents redefinition warnings from the C preprocessor when introducing the common macros later.
--
v5:
- New.
--- drivers/gpio/gpio-aspeed.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/gpio/gpio-aspeed.c +2 -0
@@ -32,7 +32,9 @@#include "gpiolib.h" /* Non-constant mask variant of FIELD_GET() and FIELD_PREP() */ +#undef field_get#define field_get (_mask, _reg) (((_reg) & (_mask)) >> (ffs(_mask) - 1)) +#undef field_prep#define field_prep (_mask, _val) (((_val) << (ffs(_mask) - 1)) & (_mask))#define GPIO_G7_IRQ_STS_BASE 0x100
Signature · 1 line
2.43.0
Re: [PATCH v5 04/23] gpio: aspeed: #undef field_{get,prep}() before local definition
Quoted 30 lines · Geert Uytterhoeven
Prepare for the advent of globally available common
field_get()andfield_prep()macros by undefining the symbols before defining local variants. This prevents redefinition warnings from the C preprocessor when introducing the common macros later.Suggested-by Yury Norov <[email protected]>Signed-off-by Geert Uytterhoeven <[email protected]>--
v5:
- New.--- drivers/gpio/gpio-aspeed.c | 2 ++ 1 file changed, 2 insertions(+)drivers/gpio/gpio-aspeed.c +2
-1@@ -32,7 +32,9 @@#include "gpiolib.h" /* Non-constant mask variant of FIELD_GET() and FIELD_PREP() */ +#undef field_get#define field_get (_mask, _reg) (((_reg) & (_mask)) >> (ffs(_mask) - 1)) +#undef field_prep#define field_prep (_mask, _val) (((_val) << (ffs(_mask) - 1)) & (_mask))#define GPIO_G7_IRQ_STS_BASE 0x100 --
Quoted 2 lines
2.43.0
Geert Uytterhoeven
maintainerPATCH v5 5/23 iio: dac: ad3530r: #undef field_prep() before local definition
In reply to Geert UytterhoevenPrepare for the advent of a globally available common field_prep() macro by undefining the symbol before defining a local variant. This prevents redefinition warnings from the C preprocessor when introducing the common macro later.
--
v5:
- New.
--- drivers/iio/dac/ad3530r.c | 1 + 1 file changed, 1 insertion(+)
drivers/iio/dac/ad3530r.c +1 -0
@@ -54,6 +54,7 @@#define AD3531R_MAX_CHANNELS 4/* Non-constant mask variant of FIELD_PREP() */ +#undef field_prep#define field_prep (_mask, _val) (((_val) << (ffs(_mask) - 1)) & (_mask))enum ad3530r_mode {
Signature · 1 line
2.43.0
Geert Uytterhoeven
maintainerPATCH v5 6/23 iio: mlx90614: #undef field_{get,prep}() before local definition
In reply to Geert UytterhoevenPrepare for the advent of globally available common field_get() and field_prep() macros by undefining the symbols before defining local variants. This prevents redefinition warnings from the C preprocessor when introducing the common macros later.
--
v5:
- New.
--- drivers/iio/temperature/mlx90614.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/iio/temperature/mlx90614.c +2 -0
@@ -69,7 +69,9 @@#define MLX90614_CONST_FIR 0x7/* Fixed value for FIR part of low pass filter */ /* Non-constant mask variant of FIELD_GET() and FIELD_PREP() */ +#undef field_get#define field_get (_mask, _reg) (((_reg) & (_mask)) >> (ffs(_mask) - 1)) +#undef field_prep#define field_prep (_mask, _val) (((_val) << (ffs(_mask) - 1)) & (_mask))struct mlx_chip_info {
Signature · 1 line
2.43.0
Geert Uytterhoeven
maintainerPATCH v5 7/23 pinctrl: ma35: #undef field_{get,prep}() before local definition
In reply to Geert UytterhoevenPrepare for the advent of globally available common field_get() and field_prep() macros by undefining the symbols before defining local variants. This prevents redefinition warnings from the C preprocessor when introducing the common macros later.
--
v5:
- New.
--- drivers/pinctrl/nuvoton/pinctrl-ma35.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/pinctrl/nuvoton/pinctrl-ma35.c +2 -0
@@ -82,7 +82,9 @@#define MVOLT_3300 1/* Non-constant mask variant of FIELD_GET() and FIELD_PREP() */ +#undef field_get#define field_get (_mask, _reg) (((_reg) & (_mask)) >> (ffs(_mask) - 1)) +#undef field_prep#define field_prep (_mask, _val) (((_val) << (ffs(_mask) - 1)) & (_mask))static const char *const gpio_group_name[] = {
Signature · 1 line
2.43.0
Re: [PATCH v5 07/23] pinctrl: ma35: #undef field_{get,prep}() before local definition
Hi Geert,
thanks for your patch!
Quoted 7 lines · Geert Uytterhoeven
Prepare for the advent of globally available common
field_get()andfield_prep()macros by undefining the symbols before defining local variants. This prevents redefinition warnings from the C preprocessor when introducing the common macros later.Suggested-by Yury Norov <[email protected]>Signed-off-by Geert Uytterhoeven <[email protected]>
Do you want me to just merge this patch to the pinctrl tree or do you have other plans?
Yours,
Linus Walleij
Yury Norov
maintainerRe: [PATCH v5 07/23] pinctrl: ma35: #undef field_{get,prep}() before local definition
Quoted 12 lines · Linus Walleij
Hi Geert,
thanks for your patch!
Quoted 5 lines · Geert Uytterhoeven
Prepare for the advent of globally available common
field_get()andfield_prep()macros by undefining the symbols before defining local variants. This prevents redefinition warnings from the C preprocessor when introducing the common macros later.
Quoted 5 lines
Quoted 2 lines
Suggested-by Yury Norov <[email protected]>Signed-off-by Geert Uytterhoeven <[email protected]>Do you want me to just merge this patch to the pinctrl tree or do you have other plans?
There's a couple nits from Andy, and also a clang W=1 warning to address. So I think, v6 is needed.
But overlall, the series is OK, and I'd like to take it in bitmaps branch as it's more related to bits rather than a particular subsystem.
Thanks,
Yury
Re: [PATCH v5 07/23] pinctrl: ma35: #undef field_{get,prep}() before local definition
Hi Yury,
Quoted 8 lines · Yury Norov
Quoted 7 lines · Linus Walleij
Quoted 5 lines · Geert Uytterhoeven
Prepare for the advent of globally available common
field_get()andfield_prep()macros by undefining the symbols before defining local variants. This prevents redefinition warnings from the C preprocessor when introducing the common macros later.
Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
Suggested-by Yury Norov <[email protected]>Signed-off-by Geert Uytterhoeven <[email protected]>Do you want me to just merge this patch to the pinctrl tree or do you have other plans?
There's a couple nits from Andy, and also a clang W=1 warning to address. So I think, v6 is needed.
Indeed....
Quoted 3 lines
But overlall, the series is OK, and I'd like to take it in bitmaps branch as it's more related to bits rather than a particular subsystem.
OK, fine for me (if I can still get an immutable branch ;-)
Note that as of today there are two more to fix in next:
commit d21b4338159ff7d7 ("mtd: rawnand: sunxi: introduce ecc_mode_mask in sunxi_nfc_caps") in next-20251029
commit 6fc2619af1eb6f59 ("mtd: rawnand: sunxi: rework pattern found registers") in next-20251029
Thanks!
Gr{oetje,eeting}s,
Geert
Signature · 5 lines
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected] In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that. -- Linus Torvalds
Yury Norov
maintainerRe: [PATCH v5 07/23] pinctrl: ma35: #undef field_{get,prep}() before local definition
Quoted 26 lines · Geert Uytterhoeven
Hi Yury,
Quoted 8 lines · Yury Norov
Quoted 7 lines · Linus Walleij
Quoted 5 lines · Geert Uytterhoeven
Prepare for the advent of globally available common
field_get()andfield_prep()macros by undefining the symbols before defining local variants. This prevents redefinition warnings from the C preprocessor when introducing the common macros later.Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
Suggested-by Yury Norov <[email protected]>Signed-off-by Geert Uytterhoeven <[email protected]>Do you want me to just merge this patch to the pinctrl tree or do you have other plans?
There's a couple nits from Andy, and also a clang W=1 warning to address. So I think, v6 is needed.
Indeed....
Quoted 3 lines
But overlall, the series is OK, and I'd like to take it in bitmaps branch as it's more related to bits rather than a particular subsystem.
Quoted 7 lines
OK, fine for me (if I can still get an immutable branch ;-)
Note that as of today there are two more to fix in next:
commitd21b4338159ff7d7("mtd: rawnand: sunxi: introduceecc_mode_maskinsunxi_nfc_caps") in next-20251029
commit6fc2619af1eb6f59("mtd: rawnand: sunxi: rework pattern found registers") in next-20251029
Oh, OK. Didn't actually want to undercut you. :) So, at your discretion. Just let me know what you'd prefer.
Thanks,
Yury
Re: [PATCH v5 07/23] pinctrl: ma35: #undef field_{get,prep}() before local definition
In reply to Linus WalleijHi Linus,
Quoted 8 lines · Linus Walleij
Quoted 5 lines · Geert Uytterhoeven
Prepare for the advent of globally available common
field_get()andfield_prep()macros by undefining the symbols before defining local variants. This prevents redefinition warnings from the C preprocessor when introducing the common macros later.
Quoted 5 lines
Quoted 2 lines
Suggested-by Yury Norov <[email protected]>Signed-off-by Geert Uytterhoeven <[email protected]>Do you want me to just merge this patch to the pinctrl tree or do you have other plans?
My plan (cfr. cover letter) was to take it myself, as this is a hard dependency for 11/23.
Thanks!
Gr{oetje,eeting}s,
Geert
Signature · 5 lines
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected] In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that. -- Linus Torvalds
Linus Walleij
Acked-byRe: [PATCH v5 07/23] pinctrl: ma35: #undef field_{get,prep}() before local definition
Quoted 9 lines · Geert Uytterhoeven
Quoted 8 lines · Linus Walleij
Quoted 5 lines · Geert Uytterhoeven
Prepare for the advent of globally available common
field_get()andfield_prep()macros by undefining the symbols before defining local variants. This prevents redefinition warnings from the C preprocessor when introducing the common macros later.
Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
Suggested-by Yury Norov <[email protected]>Signed-off-by Geert Uytterhoeven <[email protected]>Do you want me to just merge this patch to the pinctrl tree or do you have other plans?
My plan (cfr. cover letter) was to take it myself, as this is a hard dependency for 11/23.
OK go ahead:
I see there are other review comments, I trust you will fix them up and merge the result nicely.
Yours,
Linus Walleij
Geert Uytterhoeven
maintainerPATCH v5 8/23 soc: renesas: rz-sysc: #undef field_get() before local definition
In reply to Geert UytterhoevenPrepare for the advent of a globally available common field_get() macro by undefining the symbol before defining a local variant. This prevents redefinition warnings from the C preprocessor when introducing the common macro later.
--
v5:
- New.
--- drivers/soc/renesas/rz-sysc.c | 1 + 1 file changed, 1 insertion(+)
drivers/soc/renesas/rz-sysc.c +1 -0
@@ -16,6 +16,7 @@#include "rz-sysc.h" +#undef field_get#define field_get (_mask, _reg) (((_reg) & (_mask)) >> (ffs(_mask) - 1))/**
Signature · 1 line
2.43.0
Geert Uytterhoeven
maintainerPATCH v5 9/23 ALSA: usb-audio: #undef field_{get,prep}() before local definition
In reply to Geert UytterhoevenPrepare for the advent of globally available common field_get() and field_prep() macros by undefining the symbols before defining local variants. This prevents redefinition warnings from the C preprocessor when introducing the common macros later.
--
v5:
- New.
--- sound/usb/mixer_quirks.c | 2 ++ 1 file changed, 2 insertions(+)
sound/usb/mixer_quirks.c +2 -0
@@ -3312,7 +3312,9 @@ static int snd_bbfpro_controls_create(struct usb_mixer_interface *mixer)#define RME_DIGIFACE_INVERT BIT(31)/* Nonconst helpers */ +#undef field_get#define field_get (_mask, _reg) (((_reg) & (_mask)) >> (ffs(_mask) - 1)) +#undef field_prep#define field_prep (_mask, _val) (((_val) << (ffs(_mask) - 1)) & (_mask))static int snd_rme_digiface_write_reg (struct snd_kcontrol *kcontrol,int item,u16 mask,u16 val)
Signature · 1 line
2.43.0
Re: [PATCH v5 09/23] ALSA: usb-audio: #undef field_{get,prep}() before local definition
Quoted 20 lines · Geert Uytterhoeven
Prepare for the advent of globally available common
field_get()andfield_prep()macros by undefining the symbols before defining local variants. This prevents redefinition warnings from the C preprocessor when introducing the common macros later.Suggested-by Yury Norov <[email protected]>Signed-off-by Geert Uytterhoeven <[email protected]>--
v5:
- New.--- sound/usb/mixer_quirks.c | 2 ++ 1 file changed, 2 insertions(+)sound/usb/mixer_quirks.c +0
-0
sound/usb/mixer_quirks.c static int snd_bbfpro_controls_create(struct usb_mixer_interface *mixer) · line 3320
Quoted 9 lines
sound/usb/mixer_quirks.c +2
-0@@ -3312,7 +3312,9 @@ static int snd_bbfpro_controls_create(struct usb_mixer_interface *mixer)#define RME_DIGIFACE_INVERT BIT(31)/* Nonconst helpers */ +#undef field_get#define field_get (_mask, _reg) (((_reg) & (_mask)) >> (ffs(_mask) - 1)) +#undef field_prep#define field_prep (_mask, _val) (((_val) << (ffs(_mask) - 1)) & (_mask))static int snd_rme_digiface_write_reg (struct snd_kcontrol *kcontrol,int item,u16 mask,u16 val)
thanks,
Takashi
Geert Uytterhoeven
maintainerPATCH v5 10/23 iio: imu: smi330: #undef field_{get,prep}() before definition
In reply to Geert UytterhoevenPrepare for the advent of globally available common field_get() and field_prep() macros by undefining the symbols before defining local variants. This prevents redefinition warnings from the C preprocessor when introducing the common macros later.
--
v5:
- New.
--- drivers/iio/imu/smi330/smi330_core.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/iio/imu/smi330/smi330_core.c +2 -0
@@ -68,7 +68,9 @@#define SMI330_SOFT_RESET_DELAY 2000/* Non-constant mask variant of FIELD_GET() and FIELD_PREP() */ +#undef field_get#define field_get (_mask, _reg) (((_reg) & (_mask)) >> (ffs(_mask) - 1)) +#undef field_prep#define field_prep (_mask, _val) (((_val) << (ffs(_mask) - 1)) & (_mask))#define SMI330_ACCEL_CHANNEL (_axis) { \
Signature · 1 line
2.43.0
Jonathan Cameron
maintainerRe: [PATCH -next v5 10/23] iio: imu: smi330: #undef field_{get,prep}() before definition
Quoted 7 lines · On Mon, 27 Oct 2025 19:41:44 +0100 Geert Uytterhoeven…
Prepare for the advent of globally available common
field_get()andfield_prep()macros by undefining the symbols before defining local variants. This prevents redefinition warnings from the C preprocessor when introducing the common macros later.Suggested-by Yury Norov <[email protected]>Signed-off-by Geert Uytterhoeven <[email protected]>
So this is going to make a mess of merging your series given this is queued up for next merge window.
I can pick this one up perhaps and we loop back to the replacement of these in a future patch? Or perhaps go instead with a rename of these two which is probably nicer in the intermediate state than undefs.
Quoted 21 lines
--
v5:
- New.--- drivers/iio/imu/smi330/smi330_core.c | 2 ++ 1 file changed, 2 insertions(+)drivers/iio/imu/smi330/smi330_core.c +2
-0@@ -68,7 +68,9 @@#define SMI330_SOFT_RESET_DELAY 2000/* Non-constant mask variant of FIELD_GET() and FIELD_PREP() */ +#undef field_get#define field_get (_mask, _reg) (((_reg) & (_mask)) >> (ffs(_mask) - 1)) +#undef field_prep#define field_prep (_mask, _val) (((_val) << (ffs(_mask) - 1)) & (_mask))#define SMI330_ACCEL_CHANNEL (_axis) { \
Re: [PATCH -next v5 10/23] iio: imu: smi330: #undef field_{get,prep}() before definition
Hi Jonathan,
Quoted 11 lines · Jonathan Cameron
Quoted 7 lines · On Mon, 27 Oct 2025 19:41:44 +0100 Geert Uytterhoeven…
Prepare for the advent of globally available common
field_get()andfield_prep()macros by undefining the symbols before defining local variants. This prevents redefinition warnings from the C preprocessor when introducing the common macros later.Suggested-by Yury Norov <[email protected]>Signed-off-by Geert Uytterhoeven <[email protected]>
Quoted 7 lines
So this is going to make a mess of merging your series given this is queued up for next merge window.
I can pick this one up perhaps and we loop back to the replacement of these in a future patch? Or perhaps go instead with a rename of these two which is probably nicer in the intermediate state than undefs.
Renaming would mean a lot of churn.
Just picking up the #undef patch should be simple and safe? The removal of the underf and redef can be done in the next cycle. Thanks!
Quoted 5 lines
Quoted 5 lines
drivers/iio/imu/smi330/smi330_core.c +0
-0@@ -68,7 +68,9 @@#define SMI330_SOFT_RESET_DELAY 2000
Quoted 7 lines
drivers/iio/imu/smi330/smi330_core.c line 76
Quoted 7 lines
drivers/iio/imu/smi330/smi330_core.c +2
-0/* Non-constant mask variant of FIELD_GET() and FIELD_PREP() */ +#undef field_get#define field_get (_mask, _reg) (((_reg) & (_mask)) >> (ffs(_mask) - 1)) +#undef field_prep#define field_prep (_mask, _val) (((_val) << (ffs(_mask) - 1)) & (_mask))#define SMI330_ACCEL_CHANNEL (_axis) { \
Gr{oetje,eeting}s,
Geert
Signature · 5 lines
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected] In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that. -- Linus Torvalds
Jonathan Cameron
maintainerRe: [PATCH -next v5 10/23] iio: imu: smi330: #undef field_{get,prep}() before definition
Quoted 22 lines · On Mon, 3 Nov 2025 11:09:36 +0100 Geert Uytterhoeven <[email protected]>…
Hi Jonathan,
Quoted 11 lines · Jonathan Cameron
Quoted 7 lines · On Mon, 27 Oct 2025 19:41:44 +0100 Geert Uytterhoeven…
Prepare for the advent of globally available common
field_get()andfield_prep()macros by undefining the symbols before defining local variants. This prevents redefinition warnings from the C preprocessor when introducing the common macros later.Suggested-by Yury Norov <[email protected]>Signed-off-by Geert Uytterhoeven <[email protected]>Quoted 7 lines
So this is going to make a mess of merging your series given this is queued up for next merge window.
I can pick this one up perhaps and we loop back to the replacement of these in a future patch? Or perhaps go instead with a rename of these two which is probably nicer in the intermediate state than undefs.
Quoted 4 lines
Renaming would mean a lot of churn.
Just picking up the #undef patch should be simple and safe? The removal of the underf and redef can be done in the next cycle. Thanks!
Only 1 call of each of these in the driver, so churn is small either way.
To avoid a bisection problem if your tree merges first I need to modify this stuff in the original patch or leave it for Linus to deal with as a merge conflict resolution which is mess I'd rather do without.
So I'll rebase now and rename these functions to have an smi330_ prefix. Better to potentially cause people problems when I have 23 patches on top of this (and hopefully no one is based on those yet) than when I have many more.
So tweaked and pushed out a new version where this patch isn't needed. We can move to your new code next cycle.
Jonathan
Quoted 18 lines
Quoted 6 lines
Quoted 6 lines
drivers/iio/imu/smi330/smi330_core.c +0
-0@@ -68,7 +68,9 @@#define SMI330_SOFT_RESET_DELAY 2000Quoted 7 lines
drivers/iio/imu/smi330/smi330_core.c line 76
Quoted 7 lines
drivers/iio/imu/smi330/smi330_core.c +2
-0/* Non-constant mask variant of FIELD_GET() and FIELD_PREP() */ +#undef field_get#define field_get (_mask, _reg) (((_reg) & (_mask)) >> (ffs(_mask) - 1)) +#undef field_prep#define field_prep (_mask, _val) (((_val) << (ffs(_mask) - 1)) & (_mask))#define SMI330_ACCEL_CHANNEL (_axis) { \Gr{oetje,eeting}s,
Geert
Re: [PATCH -next v5 10/23] iio: imu: smi330: #undef field_{get,prep}() before definition
Hi Jonathan,
Quoted 27 lines · Jonathan Cameron
Quoted 20 lines · On Mon, 3 Nov 2025 11:09:36 +0100 Geert Uytterhoeven <[email protected]>…
Quoted 11 lines · Jonathan Cameron
Quoted 7 lines · On Mon, 27 Oct 2025 19:41:44 +0100 Geert Uytterhoeven…
Prepare for the advent of globally available common
field_get()andfield_prep()macros by undefining the symbols before defining local variants. This prevents redefinition warnings from the C preprocessor when introducing the common macros later.Suggested-by Yury Norov <[email protected]>Signed-off-by Geert Uytterhoeven <[email protected]>Quoted 7 lines
So this is going to make a mess of merging your series given this is queued up for next merge window.
I can pick this one up perhaps and we loop back to the replacement of these in a future patch? Or perhaps go instead with a rename of these two which is probably nicer in the intermediate state than undefs.
Quoted 4 lines
Renaming would mean a lot of churn.
Just picking up the #undef patch should be simple and safe? The removal of the underf and redef can be done in the next cycle. Thanks!
Quoted 5 lines
Only 1 call of each of these in the driver, so churn is small either way.
To avoid a bisection problem if your tree merges first I need to modify this stuff in the original patch or leave it for Linus to deal with as a merge conflict resolution which is mess I'd rather do without.
If you add the #undef, there won't be any bisection problem?
Gr{oetje,eeting}s,
Geert
Signature · 5 lines
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected] In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that. -- Linus Torvalds
Jonathan Cameron
maintainerRe: [PATCH -next v5 10/23] iio: imu: smi330: #undef field_{get,prep}() before definition
Quoted 1 line · On Mon, 10 Nov 2025 09:59:34 +0100 Geert Uytterhoeven <[email protected]>…
Hi Jonathan,
Hi Geert,
Quoted 29 lines · Jonathan Cameron
Quoted 27 lines
Quoted 24 lines · On Mon, 3 Nov 2025 11:09:36 +0100 Geert Uytterhoeven <[email protected]>…
Quoted 11 lines · Jonathan Cameron
Quoted 7 lines · On Mon, 27 Oct 2025 19:41:44 +0100 Geert Uytterhoeven…
Prepare for the advent of globally available common
field_get()andfield_prep()macros by undefining the symbols before defining local variants. This prevents redefinition warnings from the C preprocessor when introducing the common macros later.Suggested-by Yury Norov <[email protected]>Signed-off-by Geert Uytterhoeven <[email protected]>Quoted 7 lines
So this is going to make a mess of merging your series given this is queued up for next merge window.
I can pick this one up perhaps and we loop back to the replacement of these in a future patch? Or perhaps go instead with a rename of these two which is probably nicer in the intermediate state than undefs.
Renaming would mean a lot of churn.
Just picking up the #undef patch should be simple and safe? The removal of the underf and redef can be done in the next cycle. Thanks!
Quoted 7 lines
Quoted 5 lines
Only 1 call of each of these in the driver, so churn is small either way.
To avoid a bisection problem if your tree merges first I need to modify this stuff in the original patch or leave it for Linus to deal with as a merge conflict resolution which is mess I'd rather do without.
If you add the #undef, there won't be any bisection problem?
Two different things. The bisection comment was about squashing into the original driver patch - not what was squashed. Your tree may well merge before mine does and a bisection could therefore land in between the driver introduction and a patch I merge today.
The rename is a preference only because I don't want an undef that smells like a hack / bug work around kicking around in the tree for significant time (probably a whole kernel cycle). In this case the churn is very similar with that or a rename of the macros - so rename it is.
Jonathan
Quoted 4 lines
Gr{oetje,eeting}s,
Geert
Geert Uytterhoeven
maintainerPATCH v5 11/23 bitfield: Add non-constant field_{prep,get}() helpers
In reply to Geert UytterhoevenThe existing FIELD_{GET,PREP}() macros are limited to compile-time constants. However, it is very common to prepare or extract bitfield elements where the bitfield mask is not a compile-time constant.
To avoid this limitation, the AT91 clock driver and several other drivers already have their own non-const field_{prep,get}() macros. Make them available for general use by adding them to <linux/bitfield.h>, and improve them slightly:
1. Avoid evaluating macro parameters more than once,
2. Replace "ffs() - 1" by "__ffs()",
3. Support 64-bit use on 32-bit architectures,
4. Wire field_{get,prep}() to FIELD_{GET,PREP}() when mask is actually constant.
This is deliberately not merged into the existing FIELD_{GET,PREP}() macros, as people expressed the desire to keep stricter variants for increased safety, or for performance critical paths.
---
v5:
- Add Acked-by,
- Split off changes outside <linux/bitfield.h>,
- Document that mask must be non-zero,
- Document typical usage pattern,
- Recommend using FIELD_{PREP,GET}() directly to ensure compile-time constant masks,
- Check BITS_PER_TYPE(mask) instead of sizeof(mask),
- Wire field_{get,prep}() to FIELD_{GET,PREP}() when mask is constant, to improve type checking.
v4:
- Add Acked-by,
- Rebase on top of commit 7c68005a46108ffa ("crypto: qat - relocate power management debugfs helper APIs") in v6.17-rc1,
- Convert more recently introduced upstream copies:
- drivers/edac/ie31200_edac.c
- drivers/iio/dac/ad3530r.c
v3:
- Add Acked-by,
- Drop underscores from macro parameters,
- Use __auto_type where possible,
- Correctly cast reg to the mask type,
- Introduces __val and __reg intermediates to simplify the actual operation,
- Drop unneeded parentheses,
- Clarify having both FIELD_{GET,PREP}() and field_{get,prep}(),
v2:
- Cast val resp. reg to the mask type,
- Fix 64-bit use on 32-bit architectures,
- Convert new upstream users:
- drivers/crypto/intel/qat/qat_common/adf_gen4_pm_debugfs.c
- drivers/gpio/gpio-aspeed.c
- drivers/iio/temperature/mlx90614.c
- drivers/pinctrl/nuvoton/pinctrl-ma35.c
- sound/usb/mixer_quirks.c
- Convert new user queued in renesas-devel for v6.15:
- drivers/soc/renesas/rz-sysc.c
--- include/linux/bitfield.h | 54 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+)
include/linux/bitfield.h +54 -0
@@ -220,4 +220,58 @@ __MAKE_OP(64)#undef __MAKE_OP#undef ____MAKE_OP +#define __field_prep (mask, val) \ + ({ \ + __auto_type __mask = (mask); \ + typeof(mask) __val = (val); \ + unsigned int __shift = BITS_PER_TYPE(mask) <= 32 ? \ + __ffs(__mask) : __ffs64(__mask); \ + (__val << __shift) & __mask; \ + }) + +#define __field_get (mask, reg) \ + ({ \ + __auto_type __mask = (mask); \ + typeof(mask) __reg = (reg); \ + unsigned int __shift = BITS_PER_TYPE(mask) <= 32 ? \ + __ffs(__mask) : __ffs64(__mask); \ + (__reg & __mask) >> __shift; \ + }) + +/** +* field_prep() - prepare a bitfield element +* @mask: shifted mask defining the field's length and position, must be +* non-zero +* @val: value to put in the field +* +* field_prep() masks and shifts up the value. The result should be +* combined with other fields of the bitfield using logical OR. +* Unlike FIELD_PREP(), @mask is not limited to a compile-time constant. +* Typical usage patterns are a value stored in a table, or calculated by +* shifting a constant by a variable number of bits. +* If you want to ensure that @mask is a compile-time constant, please use +* FIELD_PREP() directly instead. +*/ +#define field_prep (mask, val) \ + (__builtin_constant_p(mask) ? FIELD_PREP(mask, val) \ + : __field_prep(mask, val)) + +/** +* field_get() - extract a bitfield element +* @mask: shifted mask defining the field's length and position, must be +* non-zero +* @reg: value of entire bitfield +* +* field_get() extracts the field specified by @mask from the +* bitfield passed in as @reg by masking and shifting it down. +* Unlike FIELD_GET(), @mask is not limited to a compile-time constant. +* Typical usage patterns are a value stored in a table, or calculated by +* shifting a constant by a variable number of bits. +* If you want to ensure that @mask is a compile-time constant, please use +* FIELD_GET() directly instead. +*/ +#define field_get (mask, reg) \ + (__builtin_constant_p(mask) ? FIELD_GET(mask, reg) \ + : __field_get(mask, reg)) +#endif
Signature · 1 line
2.43.0
Re: [PATCH v5 11/23] bitfield: Add non-constant field_{prep,get}() helpers
Quoted 14 lines · Geert Uytterhoeven
The existing FIELD_{GET,PREP}() macros are limited to compile-time constants. However, it is very common to prepare or extract bitfield elements where the bitfield mask is not a compile-time constant.
To avoid this limitation, the AT91 clock driver and several other drivers already have their own non-const field_{prep,get}() macros. Make them available for general use by adding them to <
linux/bitfield.h>, and improve them slightly:
1. Avoid evaluating macro parameters more than once,
2. Replace "ffs()- 1" by "__ffs()",
3. Support 64-bit use on 32-bit architectures,
4. Wire field_{get,prep}() to FIELD_{GET,PREP}() when mask is actually constant.
Quoted 3 lines
This is deliberately not merged into the existing FIELD_{GET,PREP}() macros, as people expressed the desire to keep stricter variants for increased safety, or for performance critical paths.
Some comments below, but FWIW,
after addressing them.
...
include/linux/bitfield.h __MAKE_OP(64) · line 229
Quoted 7 lines
include/linux/bitfield.h +7
-0+#define __field_prep (mask, val) \ + ({ \ + __auto_type __mask = (mask); \ + typeof(mask) __val = (val); \ + unsigned int __shift = BITS_PER_TYPE(mask) <= 32 ? \ + __ffs(__mask) : __ffs64(__mask); \ + (__val << __shift) & __mask; \
Unaligned \
include/linux/bitfield.h __MAKE_OP(64) · line 238
Quoted 9 lines
include/linux/bitfield.h +9
-0+ }) + +#define __field_get (mask, reg) \ + ({ \ + __auto_type __mask = (mask); \ + typeof(mask) __reg = (reg); \ + unsigned int __shift = BITS_PER_TYPE(mask) <= 32 ? \ + __ffs(__mask) : __ffs64(__mask); \ + (__reg & __mask) >> __shift; \
Ditto.
Quoted 5 lines
include/linux/bitfield.h +4
-0+ }) +/** +* field_prep() - prepare a bitfield element +* @mask: shifted mask defining the field's length and position, must be
include/linux/bitfield.h __MAKE_OP(64) · line 253
Quoted 10 lines
include/linux/bitfield.h +10
-0+* non-zero +* @val: value to put in the field +* +* field_prep() masks and shifts up the value. The result should be +* combined with other fields of the bitfield using logical OR. +* Unlike FIELD_PREP(), @mask is not limited to a compile-time constant. +* Typical usage patterns are a value stored in a table, or calculated by +* shifting a constant by a variable number of bits. +* If you want to ensure that @mask is a compile-time constant, please use +* FIELD_PREP() directly instead.
Shouldn't it have Return section as well?
include/linux/bitfield.h __MAKE_OP(64) · line 257
Quoted 4 lines
+ */
include/linux/bitfield.h +3
-0+#define field_prep (mask, val) \ + (__builtin_constant_p(mask) ? FIELD_PREP(mask, val) \ + : __field_prep(mask, val))
Personally I would give it a single line (but it's up to you, folks).
Quoted 4 lines
include/linux/bitfield.h +4
-0+ +/** +* field_get() - extract a bitfield element +* @mask: shifted mask defining the field's length and position, must be
include/linux/bitfield.h __MAKE_OP(64) · line 271
Quoted 10 lines
include/linux/bitfield.h +10
-0+* non-zero +* @reg: value of entire bitfield +* +* field_get() extracts the field specified by @mask from the +* bitfield passed in as @reg by masking and shifting it down. +* Unlike FIELD_GET(), @mask is not limited to a compile-time constant. +* Typical usage patterns are a value stored in a table, or calculated by +* shifting a constant by a variable number of bits. +* If you want to ensure that @mask is a compile-time constant, please use +* FIELD_GET() directly instead.
Ditto.
include/linux/bitfield.h __MAKE_OP(64) · line 275
Quoted 4 lines
+ */
include/linux/bitfield.h +3
-0+#define field_get (mask, reg) \ + (__builtin_constant_p(mask) ? FIELD_GET(mask, reg) \ + : __field_get(mask, reg))
As per above.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Geert Uytterhoeven
maintainerPATCH v5 12/23 clk: at91: Convert to common field_{get,prep}() helpers
In reply to Geert UytterhoevenDrop the driver-specific field_get() and field_prep() macros, in favor of the globally available variants from <linux/bitfield.h>.
---
v5:
- Extracted from "bitfield: Add non-constant field_{prep,get}() helpers".
--- drivers/clk/at91/clk-peripheral.c | 1 + drivers/clk/at91/pmc.h | 5 ----- 2 files changed, 1 insertion(+), 5 deletions(-)
drivers/clk/at91/clk-peripheral.c +1 -0
@@ -3,6 +3,7 @@* Copyright (C) 2013 Boris BREZILLON <[email protected]> */ +#include <linux/bitfield.h> #include <linux/bitops.h> #include <linux/clk-provider.h> #include <linux/clkdev.h>
drivers/clk/at91/pmc.h +0 -5
@@ -117,11 +117,6 @@ struct at91_clk_pms {unsigned int parent; }; -#undef field_get -#define field_get (_mask, _reg) (((_reg) & (_mask)) >> (ffs(_mask) - 1)) -#undef field_prep -#define field_prep (_mask, _val) (((_val) << (ffs(_mask) - 1)) & (_mask)) -#define ndck (a, s) (a[s - 1].id + 1)#define nck (a) (a[ARRAY_SIZE(a) - 1].id + 1)
Signature · 1 line
2.43.0
kernel test robot
build botRe: [PATCH v5 12/23] clk: at91: Convert to common field_{get,prep}() helpers
kernel test robot noticed the following build warnings:
Hi Geert,
kernel test robot noticed the following build warnings:
[auto build test WARNING on jic23-iio/togreg]
[also build test WARNING on next-20251027]
[cannot apply to clk/clk-next geert-renesas-devel/next geert-renesas-drivers/renesas-clk linus/master v6.18-rc3] [If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Geert-Uytterhoeven/clk-at91-pmc-undef-field_-get-prep-before-definition/20251028-025423 base: https://git.kernel.org/pub/scm/linux/kernel/git/jic23/iio.git togreg patch link: https://lore.kernel.org/r/b9e9b7d94ba51c7bc028321a85e91adecb23f925.1761588465.git.geert%2Brenesas%40glider.be patch subject: [PATCH v5 12/23] clk: at91: Convert to common field_{get,prep}() helpers config: arm-randconfig-001-20251028 (https://download.01.org/0day-ci/archive/20251028/[email protected]/config) compiler: clang version 22.0.0git (https://github.com/llvm/llvm-project e1ae12640102fd2b05bc567243580f90acb1135f) reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20251028/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All warnings (new ones prefixed by >>):
>> drivers/clk/at91/clk-peripheral.c:179:7: warning: result of comparison of constant 18446744073709551615 with expression of type 'typeof (_Generic((periph->layout->div_mask), char: (unsigned char)0, unsigned char: (unsigned char)0, signed char: (unsigned char)0, unsigned short: (unsigned short)0, short: (unsigned short)0, unsigned int: (unsigned int)0, int: (unsigned int)0, unsigned long: (unsigned long)0, long: (unsigned long)0, unsigned long long: (unsigned long long)0, long long: (unsigned long long)0, default: (periph->layout->div_mask)))' (aka 'unsigned int') is always false [-Wtautological-constant-out-of-range-compare]
179 | field_prep(periph->layout->div_mask, periph->div) |
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
include/linux/bitfield.h:256:32: note: expanded from macro 'field_prep'
256 | (__builtin_constant_p(mask) ? FIELD_PREP(mask, val) \
| ^~~~~~~~~~~~~~~~~~~~~
include/linux/bitfield.h:115:3: note: expanded from macro 'FIELD_PREP'
115 | __BF_FIELD_CHECK(_mask, 0ULL, _val, "FIELD_PREP: "); \
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
include/linux/bitfield.h:72:53: note: expanded from macro '__BF_FIELD_CHECK'
72 | BUILD_BUG_ON_MSG(__bf_cast_unsigned(_mask, _mask) > \
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~
73 | __bf_cast_unsigned(_reg, ~0ull), \
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
74 | _pfx "type of reg too small for mask"); \
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
note: (skipping 1 expansions in backtrace; use -fmacro-backtrace-limit=0 to see all)
include/linux/compiler_types.h:597:22: note: expanded from macro 'compiletime_assert'
597 | _compiletime_assert(condition, msg, __compiletime_assert_, __COUNTER__)
| ~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
include/linux/compiler_types.h:585:23: note: expanded from macro '_compiletime_assert'
585 | __compiletime_assert(condition, msg, prefix, suffix)
| ~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
include/linux/compiler_types.h:577:9: note: expanded from macro '__compiletime_assert'
577 | if (!(condition)) \
| ^~~~~~~~~1 warning generated.
vim +179 drivers/clk/at91/clk-peripheral.c
6114067e437eb8 Boris Brezillon 2013-10-11 163
36971566ea7a51 Claudiu Beznea 2021-10-11 164 static int clk_sam9x5_peripheral_set(struct clk_sam9x5_peripheral *periph,
36971566ea7a51 Claudiu Beznea 2021-10-11 165 unsigned int status)
6114067e437eb8 Boris Brezillon 2013-10-11 166 {
1bdf02326b71ea Boris Brezillon 2014-09-07 167 unsigned long flags;
36971566ea7a51 Claudiu Beznea 2021-10-11 168 unsigned int enable = status ? AT91_PMC_PCR_EN : 0;
6114067e437eb8 Boris Brezillon 2013-10-11 169
6114067e437eb8 Boris Brezillon 2013-10-11 170 if (periph->id < PERIPHERAL_ID_MIN)
6114067e437eb8 Boris Brezillon 2013-10-11 171 return 0;
6114067e437eb8 Boris Brezillon 2013-10-11 172
1bdf02326b71ea Boris Brezillon 2014-09-07 173 spin_lock_irqsave(periph->lock, flags);
cb4f4949b1c76f Alexandre Belloni 2019-04-02 174 regmap_write(periph->regmap, periph->layout->offset,
cb4f4949b1c76f Alexandre Belloni 2019-04-02 175 (periph->id & periph->layout->pid_mask));
cb4f4949b1c76f Alexandre Belloni 2019-04-02 176 regmap_update_bits(periph->regmap, periph->layout->offset,
cb4f4949b1c76f Alexandre Belloni 2019-04-02 177 periph->layout->div_mask | periph->layout->cmd |
36971566ea7a51 Claudiu Beznea 2021-10-11 178 enable,
cb4f4949b1c76f Alexandre Belloni 2019-04-02 @179 field_prep(periph->layout->div_mask, periph->div) |
36971566ea7a51 Claudiu Beznea 2021-10-11 180 periph->layout->cmd | enable);
1bdf02326b71ea Boris Brezillon 2014-09-07 181 spin_unlock_irqrestore(periph->lock, flags);
1bdf02326b71ea Boris Brezillon 2014-09-07 182
6114067e437eb8 Boris Brezillon 2013-10-11 183 return 0;
6114067e437eb8 Boris Brezillon 2013-10-11 184 }
6114067e437eb8 Boris Brezillon 2013-10-11 185 Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
Geert Uytterhoeven
maintainerPATCH v5 13/23 crypto: qat - convert to common field_get() helper
In reply to Geert UytterhoevenDrop the driver-specific field_get() macro, in favor of the globally available variant from <linux/bitfield.h>.
---
v5:
- Extracted from "bitfield: Add non-constant field_{prep,get}() helpers".
--- drivers/crypto/intel/qat/qat_common/adf_pm_dbgfs_utils.c | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-)
drivers/crypto/intel/qat/qat_common/adf_pm_dbgfs_utils.c +1 -8
@@ -1,19 +1,12 @@// SPDX-License-Identifier: GPL-2.0-only /* Copyright(c) 2025 Intel Corporation */ +#include <linux/bitfield.h> #include <linux/bitops.h> #include <linux/sprintf.h> #include <linux/string_helpers.h> #include "adf_pm_dbgfs_utils.h" -/* -* This is needed because a variable is used to index the mask at -* pm_scnprint_table(), making it not compile time constant, so the compile -* asserts from FIELD_GET() or u32_get_bits() won't be fulfilled. -*/ -#undef field_get -#define field_get (_mask, _reg) (((_reg) & (_mask)) >> (ffs(_mask) - 1)) -#define PM_INFO_MAX_KEY_LEN 21 static int pm_scnprint_table(char *buff, const struct pm_status_row *table,
Signature · 1 line
2.43.0
Re: [PATCH v5 13/23] crypto: qat - convert to common field_get() helper
Quoted 4 lines · Geert Uytterhoeven
Drop the driver-specific
field_get()macro, in favor of the globally available variant from <linux/bitfield.h>.Signed-off-by Geert Uytterhoeven <[email protected]>
Quoted 36 lines
---
v5:
- Extracted from "bitfield: Add non-constant field_{prep,get}() helpers".--- drivers/crypto/intel/qat/qat_common/adf_pm_dbgfs_utils.c | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-)drivers/crypto/intel/qat/qat_common/adf_pm_dbgfs_utils.c +1
-8@@ -1,19 +1,12 @@// SPDX-License-Identifier: GPL-2.0-only /* Copyright(c) 2025 Intel Corporation */ +#include <linux/bitfield.h> #include <linux/bitops.h> #include <linux/sprintf.h> #include <linux/string_helpers.h> #include "adf_pm_dbgfs_utils.h" -/* -* This is needed because a variable is used to index the mask at -* pm_scnprint_table(), making it not compile time constant, so the compile -* asserts from FIELD_GET() or u32_get_bits() won't be fulfilled. -*/ -#undef field_get -#define field_get (_mask, _reg) (((_reg) & (_mask)) >> (ffs(_mask) - 1)) -#define PM_INFO_MAX_KEY_LEN 21 static int pm_scnprint_table(char *buff, const struct pm_status_row *table,Signature · 1 line
2.43.0
Geert Uytterhoeven
maintainerPATCH v5 14/23 EDAC/ie31200: Convert to common field_get() helper
In reply to Geert UytterhoevenDrop the driver-specific field_get() macro, in favor of the globally available variant from <linux/bitfield.h>.
---
v5:
- Extracted from "bitfield: Add non-constant field_{prep,get}() helpers".
--- drivers/edac/ie31200_edac.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-)
drivers/edac/ie31200_edac.c +1 -4
@@ -44,6 +44,7 @@* but lo_hi_readq() ensures that we are safe across all e3-1200 processors. */ +#include <linux/bitfield.h> #include <linux/module.h> #include <linux/init.h> #include <linux/pci.h>
@@ -139,10 +140,6 @@#define IE31200_CAPID0_DDPCD BIT(6)#define IE31200_CAPID0_ECC BIT(1) -/* Non-constant mask variant of FIELD_GET() */ -#undef field_get -#define field_get (_mask, _reg) (((_reg) & (_mask)) >> (ffs(_mask) - 1)) -static int nr_channels;static struct pci_dev *mci_pdev;static int ie31200_registered =1 ;
Signature · 1 line
2.43.0
Geert Uytterhoeven
maintainerPATCH v5 15/23 gpio: aspeed: Convert to common field_{get,prep}() helpers
In reply to Geert UytterhoevenDrop the driver-specific field_get() and field_prep() macros, in favor of the globally available variants from <linux/bitfield.h>.
---
v5:
- Extracted from "bitfield: Add non-constant field_{prep,get}() helpers".
--- drivers/gpio/gpio-aspeed.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-)
drivers/gpio/gpio-aspeed.c +1 -6
@@ -5,6 +5,7 @@* Joel Stanley <[email protected]> */ +#include <linux/bitfield.h> #include <linux/cleanup.h> #include <linux/clk.h> #include <linux/gpio/aspeed.h>
@@ -31,12 +32,6 @@#include <linux/gpio/consumer.h> #include "gpiolib.h" -/* Non-constant mask variant of FIELD_GET() and FIELD_PREP() */ -#undef field_get -#define field_get (_mask, _reg) (((_reg) & (_mask)) >> (ffs(_mask) - 1)) -#undef field_prep -#define field_prep (_mask, _val) (((_val) << (ffs(_mask) - 1)) & (_mask)) -#define GPIO_G7_IRQ_STS_BASE 0x100#define GPIO_G7_IRQ_STS_OFFSET (x) (GPIO_G7_IRQ_STS_BASE + (x) * 0x4)#define GPIO_G7_CTRL_REG_BASE 0x180
Signature · 1 line
2.43.0
kernel test robot
build botRe: [PATCH v5 15/23] gpio: aspeed: Convert to common field_{get,prep}() helpers
kernel test robot noticed the following build warnings:
Hi Geert,
kernel test robot noticed the following build warnings:
[auto build test WARNING on jic23-iio/togreg]
[also build test WARNING on next-20251027]
[cannot apply to clk/clk-next geert-renesas-devel/next geert-renesas-drivers/renesas-clk linus/master v6.18-rc3] [If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Geert-Uytterhoeven/clk-at91-pmc-undef-field_-get-prep-before-definition/20251028-025423 base: https://git.kernel.org/pub/scm/linux/kernel/git/jic23/iio.git togreg patch link: https://lore.kernel.org/r/fbefa056d1e2cd13c52a0489b955c2b9442f0c9a.1761588465.git.geert%2Brenesas%40glider.be patch subject: [PATCH v5 15/23] gpio: aspeed: Convert to common field_{get,prep}() helpers config: x86_64-buildonly-randconfig-003-20251028 (https://download.01.org/0day-ci/archive/20251028/[email protected]/config) compiler: clang version 20.1.8 (https://github.com/llvm/llvm-project 87f0227cb60147a26a1eeb4fb06e3b505e9c7261) reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20251028/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All warnings (new ones prefixed by >>):
>> drivers/gpio/gpio-aspeed.c:1161:44: warning: result of comparison of constant 18446744073709551615 with expression of type 'typeof (_Generic((mask), char: (unsigned char)0, unsigned char: (unsigned char)0, signed char: (unsigned char)0, unsigned short: (unsigned short)0, short: (unsigned short)0, unsigned int: (unsigned int)0, int: (unsigned int)0, unsigned long: (unsigned long)0, long: (unsigned long)0, unsigned long long: (unsigned long long)0, long long: (unsigned long long)0, default: (mask)))' (aka 'unsigned int') is always false [-Wtautological-constant-out-of-range-compare]
1161 | write_val = (ioread32(addr) & ~(mask)) | field_prep(mask, val);
| ^~~~~~~~~~~~~~~~~~~~~
include/linux/bitfield.h:256:32: note: expanded from macro 'field_prep'
256 | (__builtin_constant_p(mask) ? FIELD_PREP(mask, val) \
| ^~~~~~~~~~~~~~~~~~~~~
include/linux/bitfield.h:115:3: note: expanded from macro 'FIELD_PREP'
115 | __BF_FIELD_CHECK(_mask, 0ULL, _val, "FIELD_PREP: "); \
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
include/linux/bitfield.h:72:53: note: expanded from macro '__BF_FIELD_CHECK'
72 | BUILD_BUG_ON_MSG(__bf_cast_unsigned(_mask, _mask) > \
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~
73 | __bf_cast_unsigned(_reg, ~0ull), \
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
74 | _pfx "type of reg too small for mask"); \
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
note: (skipping 1 expansions in backtrace; use -fmacro-backtrace-limit=0 to see all)
include/linux/compiler_types.h:597:22: note: expanded from macro 'compiletime_assert'
597 | _compiletime_assert(condition, msg, __compiletime_assert_, __COUNTER__)
| ~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
include/linux/compiler_types.h:585:23: note: expanded from macro '_compiletime_assert'
585 | __compiletime_assert(condition, msg, prefix, suffix)
| ~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
include/linux/compiler_types.h:577:9: note: expanded from macro '__compiletime_assert'
577 | if (!(condition)) \
| ^~~~~~~~~1 warning generated.
vim +1161 drivers/gpio/gpio-aspeed.c
b2e861bd1eaf4c Billy Tsai 2024-10-08 1152
b2e861bd1eaf4c Billy Tsai 2024-10-08 1153 static void aspeed_g7_reg_bit_set(struct aspeed_gpio *gpio, unsigned int offset,
b2e861bd1eaf4c Billy Tsai 2024-10-08 1154 const enum aspeed_gpio_reg reg, bool val)
b2e861bd1eaf4c Billy Tsai 2024-10-08 1155 {
b2e861bd1eaf4c Billy Tsai 2024-10-08 1156 u32 mask = aspeed_gpio_g7_reg_mask(reg);
b2e861bd1eaf4c Billy Tsai 2024-10-08 1157 void __iomem *addr = gpio->base + GPIO_G7_CTRL_REG_OFFSET(offset);
b2e861bd1eaf4c Billy Tsai 2024-10-08 1158 u32 write_val;
b2e861bd1eaf4c Billy Tsai 2024-10-08 1159
b2e861bd1eaf4c Billy Tsai 2024-10-08 1160 if (mask) {
b2e861bd1eaf4c Billy Tsai 2024-10-08 @1161 write_val = (ioread32(addr) & ~(mask)) | field_prep(mask, val);
b2e861bd1eaf4c Billy Tsai 2024-10-08 1162 iowrite32(write_val, addr);
b2e861bd1eaf4c Billy Tsai 2024-10-08 1163 }
b2e861bd1eaf4c Billy Tsai 2024-10-08 1164 }b2e861bd1eaf4c Billy Tsai 2024-10-08 1165
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
Geert Uytterhoeven
maintainerPATCH v5 16/23 iio: dac: Convert to common field_prep() helper
In reply to Geert UytterhoevenDrop the driver-specific field_prep() macro, in favor of the globally available variant from <linux/bitfield.h>.
---
v5:
- Extracted from "bitfield: Add non-constant field_{prep,get}() helpers".
--- drivers/iio/dac/ad3530r.c | 4 ---- 1 file changed, 4 deletions(-)
drivers/iio/dac/ad3530r.c +0 -4
@@ -53,10 +53,6 @@#define AD3530R_MAX_CHANNELS 8#define AD3531R_MAX_CHANNELS 4 -/* Non-constant mask variant of FIELD_PREP() */ -#undef field_prep -#define field_prep (_mask, _val) (((_val) << (ffs(_mask) - 1)) & (_mask)) -enum ad3530r_mode {AD3530R_NORMAL_OP ,AD3530R_POWERDOWN_1K ,
Signature · 1 line
2.43.0
Geert Uytterhoeven
maintainerPATCH v5 17/23 iio: mlx90614: Convert to common field_{get,prep}() helpers
In reply to Geert UytterhoevenDrop the driver-specific field_get() and field_prep() macros, in favor of the globally available variants from <linux/bitfield.h>.
---
v5:
- Extracted from "bitfield: Add non-constant field_{prep,get}() helpers".
--- drivers/iio/temperature/mlx90614.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-)
drivers/iio/temperature/mlx90614.c +1 -6
@@ -22,6 +22,7 @@* the "wakeup" GPIO is not given, power management will be disabled. */ +#include <linux/bitfield.h> #include <linux/delay.h> #include <linux/err.h> #include <linux/gpio/consumer.h>
@@ -68,12 +69,6 @@#define MLX90614_CONST_SCALE 20/* Scale in milliKelvin (0.02 * 1000) */ #define MLX90614_CONST_FIR 0x7/* Fixed value for FIR part of low pass filter */ -/* Non-constant mask variant of FIELD_GET() and FIELD_PREP() */ -#undef field_get -#define field_get (_mask, _reg) (((_reg) & (_mask)) >> (ffs(_mask) - 1)) -#undef field_prep -#define field_prep (_mask, _val) (((_val) << (ffs(_mask) - 1)) & (_mask)) -struct mlx_chip_info {/* EEPROM offsets with 16-bit data, MSB first */ /* emissivity correction coefficient */
Signature · 1 line
2.43.0
kernel test robot
build botRe: [PATCH v5 17/23] iio: mlx90614: Convert to common field_{get,prep}() helpers
kernel test robot noticed the following build warnings:
Hi Geert,
kernel test robot noticed the following build warnings:
[auto build test WARNING on jic23-iio/togreg]
[also build test WARNING on next-20251027]
[cannot apply to clk/clk-next geert-renesas-devel/next geert-renesas-drivers/renesas-clk linus/master v6.18-rc3] [If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Geert-Uytterhoeven/clk-at91-pmc-undef-field_-get-prep-before-definition/20251028-025423 base: https://git.kernel.org/pub/scm/linux/kernel/git/jic23/iio.git togreg patch link: https://lore.kernel.org/r/8ea8d9d6c33d9589e8761f6000639546f1bd5148.1761588465.git.geert%2Brenesas%40glider.be patch subject: [PATCH v5 17/23] iio: mlx90614: Convert to common field_{get,prep}() helpers config: hexagon-randconfig-001-20251028 (https://download.01.org/0day-ci/archive/20251028/[email protected]/config) compiler: clang version 22.0.0git (https://github.com/llvm/llvm-project e1ae12640102fd2b05bc567243580f90acb1135f) reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20251028/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All warnings (new ones prefixed by >>):
>> drivers/iio/temperature/mlx90614.c:177:10: warning: result of comparison of constant 18446744073709551615 with expression of type 'typeof (_Generic((chip_info->fir_config_mask), char: (unsigned char)0, unsigned char: (unsigned char)0, signed char: (unsigned char)0, unsigned short: (unsigned short)0, short: (unsigned short)0, unsigned int: (unsigned int)0, int: (unsigned int)0, unsigned long: (unsigned long)0, long: (unsigned long)0, unsigned long long: (unsigned long long)0, long long: (unsigned long long)0, default: (chip_info->fir_config_mask)))' (aka 'unsigned short') is always false [-Wtautological-constant-out-of-range-compare]
177 | ret |= field_prep(chip_info->fir_config_mask, MLX90614_CONST_FIR);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
include/linux/bitfield.h:256:32: note: expanded from macro 'field_prep'
256 | (__builtin_constant_p(mask) ? FIELD_PREP(mask, val) \
| ^~~~~~~~~~~~~~~~~~~~~
include/linux/bitfield.h:115:3: note: expanded from macro 'FIELD_PREP'
115 | __BF_FIELD_CHECK(_mask, 0ULL, _val, "FIELD_PREP: "); \
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
include/linux/bitfield.h:72:53: note: expanded from macro '__BF_FIELD_CHECK'
72 | BUILD_BUG_ON_MSG(__bf_cast_unsigned(_mask, _mask) > \
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~
73 | __bf_cast_unsigned(_reg, ~0ull), \
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
74 | _pfx "type of reg too small for mask"); \
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
note: (skipping 1 expansions in backtrace; use -fmacro-backtrace-limit=0 to see all)
include/linux/compiler_types.h:597:22: note: expanded from macro 'compiletime_assert'
597 | _compiletime_assert(condition, msg, __compiletime_assert_, __COUNTER__)
| ~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
include/linux/compiler_types.h:585:23: note: expanded from macro '_compiletime_assert'
585 | __compiletime_assert(condition, msg, prefix, suffix)
| ~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
include/linux/compiler_types.h:577:9: note: expanded from macro '__compiletime_assert'
577 | if (!(condition)) \
| ^~~~~~~~~
>> drivers/iio/temperature/mlx90614.c:181:9: warning: result of comparison of constant 18446744073709551615 with expression of type 'typeof (_Generic((chip_info->iir_config_mask), char: (unsigned char)0, unsigned char: (unsigned char)0, signed char: (unsigned char)0, unsigned short: (unsigned short)0, short: (unsigned short)0, unsigned int: (unsigned int)0, int: (unsigned int)0, unsigned long: (unsigned long)0, long: (unsigned long)0, unsigned long long: (unsigned long long)0, long long: (unsigned long long)0, default: (chip_info->iir_config_mask)))' (aka 'unsigned short') is always false [-Wtautological-constant-out-of-range-compare]
181 | ret |= field_prep(chip_info->iir_config_mask, i);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
include/linux/bitfield.h:256:32: note: expanded from macro 'field_prep'
256 | (__builtin_constant_p(mask) ? FIELD_PREP(mask, val) \
| ^~~~~~~~~~~~~~~~~~~~~
include/linux/bitfield.h:115:3: note: expanded from macro 'FIELD_PREP'
115 | __BF_FIELD_CHECK(_mask, 0ULL, _val, "FIELD_PREP: "); \
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
include/linux/bitfield.h:72:53: note: expanded from macro '__BF_FIELD_CHECK'
72 | BUILD_BUG_ON_MSG(__bf_cast_unsigned(_mask, _mask) > \
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~
73 | __bf_cast_unsigned(_reg, ~0ull), \
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
74 | _pfx "type of reg too small for mask"); \
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
note: (skipping 1 expansions in backtrace; use -fmacro-backtrace-limit=0 to see all)
include/linux/compiler_types.h:597:22: note: expanded from macro 'compiletime_assert'
597 | _compiletime_assert(condition, msg, __compiletime_assert_, __COUNTER__)
| ~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
include/linux/compiler_types.h:585:23: note: expanded from macro '_compiletime_assert'
585 | __compiletime_assert(condition, msg, prefix, suffix)
| ~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
include/linux/compiler_types.h:577:9: note: expanded from macro '__compiletime_assert'
577 | if (!(condition)) \
| ^~~~~~~~~
drivers/iio/temperature/mlx90614.c:331:9: warning: result of comparison of constant 4294967295 with expression of type 'typeof (_Generic((chip_info->iir_config_mask), char: (unsigned char)0, unsigned char: (unsigned char)0, signed char: (unsigned char)0, unsigned short: (unsigned short)0, short: (unsigned short)0, unsigned int: (unsigned int)0, int: (unsigned int)0, unsigned long: (unsigned long)0, long: (unsigned long)0, unsigned long long: (unsigned long long)0, long long: (unsigned long long)0, default: (chip_info->iir_config_mask)))' (aka 'unsigned short') is always false [-Wtautological-constant-out-of-range-compare]
331 | idx = field_get(chip_info->iir_config_mask, ret) -
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
include/linux/bitfield.h:274:32: note: expanded from macro 'field_get'
274 | (__builtin_constant_p(mask) ? FIELD_GET(mask, reg) \
| ^~~~~~~~~~~~~~~~~~~~
include/linux/bitfield.h:155:3: note: expanded from macro 'FIELD_GET'
155 | __BF_FIELD_CHECK(_mask, _reg, 0U, "FIELD_GET: "); \
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
include/linux/bitfield.h:72:53: note: expanded from macro '__BF_FIELD_CHECK'
72 | BUILD_BUG_ON_MSG(__bf_cast_unsigned(_mask, _mask) > \
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~
73 | __bf_cast_unsigned(_reg, ~0ull), \
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
74 | _pfx "type of reg too small for mask"); \
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
note: (skipping 1 expansions in backtrace; use -fmacro-backtrace-limit=0 to see all)
include/linux/compiler_types.h:597:22: note: expanded from macro 'compiletime_assert'
597 | _compiletime_assert(condition, msg, __compiletime_assert_, __COUNTER__)
| ~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
include/linux/compiler_types.h:585:23: note: expanded from macro '_compiletime_assert'
585 | __compiletime_assert(condition, msg, prefix, suffix)
| ~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
include/linux/compiler_types.h:577:9: note: expanded from macro '__compiletime_assert'
577 | if (!(condition)) \
| ^~~~~~~~~3 warnings generated.
vim +177 drivers/iio/temperature/mlx90614.c
fad65a8fe5b85b Vianney le Clément de Saint-Marcq 2015-03-30 141
764589b688a1b0 Crt Mori 2015-08-17 142 /*
3d5ead238bc85e Marek Vasut 2023-05-10 143 * Find the IIR value inside iir_values array and return its position
764589b688a1b0 Crt Mori 2015-08-17 144 * which is equivalent to the bit value in sensor register
764589b688a1b0 Crt Mori 2015-08-17 145 */
764589b688a1b0 Crt Mori 2015-08-17 146 static inline s32 mlx90614_iir_search(const struct i2c_client *client,
764589b688a1b0 Crt Mori 2015-08-17 147 int value)
764589b688a1b0 Crt Mori 2015-08-17 148 {
3d5ead238bc85e Marek Vasut 2023-05-10 149 struct iio_dev *indio_dev = i2c_get_clientdata(client);
3d5ead238bc85e Marek Vasut 2023-05-10 150 struct mlx90614_data *data = iio_priv(indio_dev);
3d5ead238bc85e Marek Vasut 2023-05-10 151 const struct mlx_chip_info *chip_info = data->chip_info;
764589b688a1b0 Crt Mori 2015-08-17 152 int i;
764589b688a1b0 Crt Mori 2015-08-17 153 s32 ret;
764589b688a1b0 Crt Mori 2015-08-17 154
3d5ead238bc85e Marek Vasut 2023-05-10 155 for (i = chip_info->iir_valid_offset;
3d5ead238bc85e Marek Vasut 2023-05-10 156 i < ARRAY_SIZE(chip_info->iir_values);
3d5ead238bc85e Marek Vasut 2023-05-10 157 i++) {
3d5ead238bc85e Marek Vasut 2023-05-10 158 if (value == chip_info->iir_values[i])
764589b688a1b0 Crt Mori 2015-08-17 159 break;
764589b688a1b0 Crt Mori 2015-08-17 160 }
764589b688a1b0 Crt Mori 2015-08-17 161
3d5ead238bc85e Marek Vasut 2023-05-10 162 if (i == ARRAY_SIZE(chip_info->iir_values))
764589b688a1b0 Crt Mori 2015-08-17 163 return -EINVAL;
764589b688a1b0 Crt Mori 2015-08-17 164
764589b688a1b0 Crt Mori 2015-08-17 165 /*
764589b688a1b0 Crt Mori 2015-08-17 166 * CONFIG register values must not be changed so
764589b688a1b0 Crt Mori 2015-08-17 167 * we must read them before we actually write
764589b688a1b0 Crt Mori 2015-08-17 168 * changes
764589b688a1b0 Crt Mori 2015-08-17 169 */
3d5ead238bc85e Marek Vasut 2023-05-10 170 ret = i2c_smbus_read_word_data(client, chip_info->op_eeprom_config1);
1de953e77b8c8b Crt Mori 2015-10-02 171 if (ret < 0)
764589b688a1b0 Crt Mori 2015-08-17 172 return ret;
764589b688a1b0 Crt Mori 2015-08-17 173
3d5ead238bc85e Marek Vasut 2023-05-10 174 /* Modify FIR on parts which have configurable FIR filter */
3d5ead238bc85e Marek Vasut 2023-05-10 175 if (chip_info->fir_config_mask) {
3d5ead238bc85e Marek Vasut 2023-05-10 176 ret &= ~chip_info->fir_config_mask;
3d5ead238bc85e Marek Vasut 2023-05-10 @177 ret |= field_prep(chip_info->fir_config_mask, MLX90614_CONST_FIR);
3d5ead238bc85e Marek Vasut 2023-05-10 178 }
3d5ead238bc85e Marek Vasut 2023-05-10 179
3d5ead238bc85e Marek Vasut 2023-05-10 180 ret &= ~chip_info->iir_config_mask;
3d5ead238bc85e Marek Vasut 2023-05-10 @181 ret |= field_prep(chip_info->iir_config_mask, i);
1de953e77b8c8b Crt Mori 2015-10-02 182
764589b688a1b0 Crt Mori 2015-08-17 183 /* Write changed values */
3d5ead238bc85e Marek Vasut 2023-05-10 184 ret = mlx90614_write_word(client, chip_info->op_eeprom_config1, ret);
764589b688a1b0 Crt Mori 2015-08-17 185 return ret;
764589b688a1b0 Crt Mori 2015-08-17 186 }
764589b688a1b0 Crt Mori 2015-08-17 187 Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
Geert Uytterhoeven
maintainerPATCH v5 18/23 pinctrl: ma35: Convert to common field_{get,prep}() helpers
In reply to Geert UytterhoevenDrop the driver-specific field_get() and field_prep() macros, in favor of the globally available variants from <linux/bitfield.h>.
---
v5:
- Extracted from "bitfield: Add non-constant field_{prep,get}() helpers".
--- drivers/pinctrl/nuvoton/pinctrl-ma35.c | 6 ------ 1 file changed, 6 deletions(-)
drivers/pinctrl/nuvoton/pinctrl-ma35.c +0 -6
@@ -81,12 +81,6 @@#define MVOLT_1800 0#define MVOLT_3300 1 -/* Non-constant mask variant of FIELD_GET() and FIELD_PREP() */ -#undef field_get -#define field_get (_mask, _reg) (((_reg) & (_mask)) >> (ffs(_mask) - 1)) -#undef field_prep -#define field_prep (_mask, _val) (((_val) << (ffs(_mask) - 1)) & (_mask)) -static const char *const gpio_group_name[] = {"gpioa" ,"gpiob" ,"gpioc" ,"gpiod" ,"gpioe" ,"gpiof" ,"gpiog" ,"gpioh" ,"gpioi" ,"gpioj" ,"gpiok" ,"gpiol" ,"gpiom" ,"gpion" ,
Signature · 1 line
2.43.0
Re: [PATCH v5 18/23] pinctrl: ma35: Convert to common field_{get,prep}() helpers
Quoted 8 lines · Geert Uytterhoeven
Drop the driver-specific
field_get()andfield_prep()macros, in favor of the globally available variants from <linux/bitfield.h>.Signed-off-by Geert Uytterhoeven <[email protected]>---
v5:
- Extracted from "bitfield: Add non-constant field_{prep,get}() helpers".
I guess this needs to go with the rest of the patches?
Yours,
Linus Walleij
Re: [PATCH v5 18/23] pinctrl: ma35: Convert to common field_{get,prep}() helpers
Hi Linus,
Quoted 6 lines · Linus Walleij
Quoted 3 lines · Geert Uytterhoeven
Drop the driver-specific
field_get()andfield_prep()macros, in favor of the globally available variants from <linux/bitfield.h>.
Quoted 7 lines
Quoted 5 lines
Signed-off-by Geert Uytterhoeven <[email protected]>---
v5:
- Extracted from "bitfield: Add non-constant field_{prep,get}() helpers".Reviewed-by Linus Walleij <[email protected]>
Thanks!
Quoted 1 line
I guess this needs to go with the rest of the patches?
There is no hard requirement for that, but if 07/23 goes in, why not include this one, too?
Gr{oetje,eeting}s,
Geert
--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]
In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds
Geert Uytterhoeven
maintainerPATCH v5 19/23 soc: renesas: rz-sysc: Convert to common field_get() helper
In reply to Geert UytterhoevenDrop the driver-specific field_get() macro, in favor of the globally available variant from <linux/bitfield.h>.
---
v5:
- Extracted from "bitfield: Add non-constant field_{prep,get}() helpers".
--- drivers/soc/renesas/rz-sysc.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
drivers/soc/renesas/rz-sysc.c +1 -3
@@ -5,6 +5,7 @@* Copyright (C) 2024 Renesas Electronics Corp. */ +#include <linux/bitfield.h> #include <linux/cleanup.h> #include <linux/io.h> #include <linux/mfd/syscon.h>
@@ -16,9 +17,6 @@#include "rz-sysc.h" -#undef field_get -#define field_get (_mask, _reg) (((_reg) & (_mask)) >> (ffs(_mask) - 1)) -/** * struct rz_sysc - RZ SYSC private data structure * @base: SYSC base address
Signature · 1 line
2.43.0
Geert Uytterhoeven
maintainerPATCH v5 20/23 ALSA: usb-audio: Convert to common field_{get,prep}() helpers
In reply to Geert UytterhoevenDrop the driver-specific field_get() and field_prep() macros, in favor of the globally available variants from <linux/bitfield.h>.
---
v5:
- Extracted from "bitfield: Add non-constant field_{prep,get}() helpers".
--- sound/usb/mixer_quirks.c | 6 ------ 1 file changed, 6 deletions(-)
sound/usb/mixer_quirks.c +0 -6
@@ -3311,12 +3311,6 @@ static int snd_bbfpro_controls_create(struct usb_mixer_interface *mixer)#define RME_DIGIFACE_REGISTER (reg, mask) (((reg) << 16) | (mask))#define RME_DIGIFACE_INVERT BIT(31) -/* Nonconst helpers */ -#undef field_get -#define field_get (_mask, _reg) (((_reg) & (_mask)) >> (ffs(_mask) - 1)) -#undef field_prep -#define field_prep (_mask, _val) (((_val) << (ffs(_mask) - 1)) & (_mask)) -static int snd_rme_digiface_write_reg (struct snd_kcontrol *kcontrol,int item,u16 mask,u16 val) {struct usb_mixer_elem_list *list =snd_kcontrol_chip (kcontrol);
Signature · 1 line
2.43.0
Re: [PATCH v5 20/23] ALSA: usb-audio: Convert to common field_{get,prep}() helpers
Quoted 20 lines · Geert Uytterhoeven
Drop the driver-specific
field_get()andfield_prep()macros, in favor of the globally available variants from <linux/bitfield.h>.Signed-off-by Geert Uytterhoeven <[email protected]>---
v5:
- Extracted from "bitfield: Add non-constant field_{prep,get}() helpers".--- sound/usb/mixer_quirks.c | 6 ------ 1 file changed, 6 deletions(-)sound/usb/mixer_quirks.c +0
-0@@ -3311,12 +3311,6 @@ static int snd_bbfpro_controls_create(struct usb_mixer_interface *mixer)#define RME_DIGIFACE_REGISTER (reg, mask) (((reg) << 16) | (mask))#define RME_DIGIFACE_INVERT BIT(31)
sound/usb/mixer_quirks.c static int snd_bbfpro_controls_create(struct usb_mixer_interface *mixer) · line 3316
Quoted 10 lines
sound/usb/mixer_quirks.c +0
-6-/* Nonconst helpers */ -#undef field_get -#define field_get (_mask, _reg) (((_reg) & (_mask)) >> (ffs(_mask) - 1)) -#undef field_prep -#define field_prep (_mask, _val) (((_val) << (ffs(_mask) - 1)) & (_mask)) -static int snd_rme_digiface_write_reg (struct snd_kcontrol *kcontrol,int item,u16 mask,u16 val) {struct usb_mixer_elem_list *list =snd_kcontrol_chip (kcontrol);
thanks,
Takashi
Geert Uytterhoeven
maintainerPATCH v5 21/23 iio: imu: smi330: Convert to common field_{get,prep}() helpers
In reply to Geert UytterhoevenDrop the driver-specific field_get() and field_prep() macros, in favor of the globally available variants from <linux/bitfield.h>.
---
v5:
- New.
--- drivers/iio/imu/smi330/smi330_core.c | 6 ------ 1 file changed, 6 deletions(-)
drivers/iio/imu/smi330/smi330_core.c +0 -6
@@ -67,12 +67,6 @@#define SMI330_CHIP_ID 0x42#define SMI330_SOFT_RESET_DELAY 2000 -/* Non-constant mask variant of FIELD_GET() and FIELD_PREP() */ -#undef field_get -#define field_get (_mask, _reg) (((_reg) & (_mask)) >> (ffs(_mask) - 1)) -#undef field_prep -#define field_prep (_mask, _val) (((_val) << (ffs(_mask) - 1)) & (_mask)) -#define SMI330_ACCEL_CHANNEL (_axis) { \ .type = IIO_ACCEL, \ .modified = 1, \
Signature · 1 line
2.43.0
Geert Uytterhoeven
maintainerPATCH v5 22/23 clk: renesas: Use bitfield helpers
In reply to Geert UytterhoevenUse the FIELD_{GET,PREP}() and field_{get,prep}() helpers for const respective non-const bitfields, instead of open-coding the same operations.
---
v5:
- No changes,
v4:
- No changes,
v3:
- No changes,
v2:
- Rebase on top of commit 470e3f0d0b1529ab ("clk: renesas: rcar-gen4:
Introduce R-Car Gen4 CPG driver").
--- drivers/clk/renesas/clk-div6.c | 6 +++--- drivers/clk/renesas/rcar-gen3-cpg.c | 15 +++++---------- drivers/clk/renesas/rcar-gen4-cpg.c | 9 +++------ 3 files changed, 11 insertions(+), 19 deletions(-)
drivers/clk/renesas/clk-div6.c +3 -3
@@ -7,6 +7,7 @@* Contact: Laurent Pinchart <[email protected]> */ +#include <linux/bitfield.h> #include <linux/clk-provider.h> #include <linux/init.h> #include <linux/io.h>
@@ -171,8 +172,7 @@ static u8 cpg_div6_clock_get_parent(struct clk_hw *hw)if (clock->src_mask ==0 )return 0 ; - hw_index = (readl (clock->reg) & clock->src_mask) >> -__ffs (clock->src_mask); + hw_index =field_get (clock->src_mask,readl (clock->reg));for (i =0 ; i <clk_hw_get_num_parents (hw); i++) {if (clock->parents[i] == hw_index)return i;
@@ -191,7 +191,7 @@ static int cpg_div6_clock_set_parent(struct clk_hw *hw, u8 index)if (index >=clk_hw_get_num_parents (hw))return -EINVAL ; - src = clock->parents[index] <<__ffs (clock->src_mask); + src =field_prep (clock->src_mask, clock->parents[index]);writel ((readl (clock->reg) & ~clock->src_mask) | src, clock->reg);return 0 ; }
drivers/clk/renesas/rcar-gen3-cpg.c +5 -10
@@ -54,10 +54,8 @@ static unsigned long cpg_pll_clk_recalc_rate(struct clk_hw *hw, {struct cpg_pll_clk *pll_clk =to_pll_clk (hw);unsigned int mult; -u32 val; - val =readl (pll_clk->pllcr_reg) & CPG_PLLnCR_STC_MASK; - mult = (val >>__ffs (CPG_PLLnCR_STC_MASK)) +1 ; + mult =FIELD_GET (CPG_PLLnCR_STC_MASK,readl (pll_clk->pllcr_reg)) +1 ;return parent_rate * mult * pll_clk->fixed_mult; }
@@ -94,7 +92,7 @@ static int cpg_pll_clk_set_rate(struct clk_hw *hw, unsigned long rate, val =readl (pll_clk->pllcr_reg); val &= ~CPG_PLLnCR_STC_MASK; - val |= (mult -1 ) <<__ffs (CPG_PLLnCR_STC_MASK); + val |=FIELD_PREP (CPG_PLLnCR_STC_MASK, mult -1 );writel (val, pll_clk->pllcr_reg);for (i =1000 ; i; i--) {
@@ -176,11 +174,7 @@ static unsigned long cpg_z_clk_recalc_rate(struct clk_hw *hw, unsigned long parent_rate) {struct cpg_z_clk *zclk =to_z_clk (hw); -unsigned int mult; -u32 val; - - val =readl (zclk->reg) & zclk->mask; - mult =32 - (val >>__ffs (zclk->mask)); +unsigned int mult =32 -field_get (zclk->mask,readl (zclk->reg));return DIV_ROUND_CLOSEST_ULL ((u64 )parent_rate * mult,32 * zclk->fixed_div);
@@ -231,7 +225,8 @@ static int cpg_z_clk_set_rate(struct clk_hw *hw, unsigned long rate,if (readl (zclk->kick_reg) &CPG_FRQCRB_KICK )return -EBUSY ; -cpg_reg_modify (zclk->reg, zclk->mask, (32 - mult) <<__ffs (zclk->mask)); +cpg_reg_modify (zclk->reg, zclk->mask, +field_prep (zclk->mask,32 - mult));/* * Set KICK bit in FRQCRB to update hardware setting and wait for
drivers/clk/renesas/rcar-gen4-cpg.c +3 -6
@@ -279,11 +279,7 @@ static unsigned long cpg_z_clk_recalc_rate(struct clk_hw *hw, unsigned long parent_rate) {struct cpg_z_clk *zclk =to_z_clk (hw); -unsigned int mult; -u32 val; - - val =readl (zclk->reg) & zclk->mask; - mult =32 - (val >>__ffs (zclk->mask)); +unsigned int mult =32 -field_get (zclk->mask,readl (zclk->reg));return DIV_ROUND_CLOSEST_ULL ((u64 )parent_rate * mult,32 * zclk->fixed_div);
@@ -334,7 +330,8 @@ static int cpg_z_clk_set_rate(struct clk_hw *hw, unsigned long rate,if (readl (zclk->kick_reg) &CPG_FRQCRB_KICK )return -EBUSY ; -cpg_reg_modify (zclk->reg, zclk->mask, (32 - mult) <<__ffs (zclk->mask)); +cpg_reg_modify (zclk->reg, zclk->mask, +field_prep (zclk->mask,32 - mult));/* * Set KICK bit in FRQCRB to update hardware setting and wait for
Signature · 1 line
2.43.0
Geert Uytterhoeven
maintainerPATCH v5 23/23 soc: renesas: Use bitfield helpers
In reply to Geert UytterhoevenUse the field_get() helper, instead of open-coding the same operation.
---
v5:
- No changes,
v4:
- No changes,
v3:
- No changes,
v2:
- Drop RFC, as a dependency was applied.
--- drivers/soc/renesas/renesas-soc.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/soc/renesas/renesas-soc.c +2 -2
@@ -5,6 +5,7 @@* Copyright (C) 2014-2016 Glider bvba */ +#include <linux/bitfield.h> #include <linux/io.h> #include <linux/of.h> #include <linux/of_address.h>
@@ -524,8 +525,7 @@ static int __init renesas_soc_init(void) eshi, eslo); } -if (soc->id && - ((product & id->mask) >>__ffs (id->mask)) != soc->id) { +if (soc->id &&field_get (id->mask, product) != soc->id) {pr_warn ("SoC mismatch (product = 0x%x)\n" , product); ret = -ENODEV ; goto free_soc_dev_attr;
Signature · 1 line
2.43.0