* [PATCH v5 00/23] Non-const bitfield helpers
@ 2025-10-27 18:41 Geert Uytterhoeven
2025-10-27 18:41 ` [PATCH v5 01/23] clk: at91: pmc: #undef field_{get,prep}() before definition Geert Uytterhoeven
` (22 more replies)
0 siblings, 23 replies; 38+ messages in thread
From: Geert Uytterhoeven @ 2025-10-27 18:41 UTC (permalink / raw)
To: Michael Turquette, Stephen Boyd, Nicolas Ferre, Alexandre Belloni,
Claudiu Beznea, Giovanni Cabiddu, Herbert Xu, David Miller,
Linus Walleij, Bartosz Golaszewski, Joel Stanley, Andrew Jeffery,
Crt Mori, Jonathan Cameron, Lars-Peter Clausen, Jacky Huang,
Shan-Chun Hung, Yury Norov, Rasmus Villemoes, Jaroslav Kysela,
Takashi Iwai, Johannes Berg, Jakub Kicinski, Alex Elder,
David Laight, Vincent Mailhol, Jason Baron, Borislav Petkov,
Tony Luck, Michael Hennerich, Kim Seer Paller, David Lechner,
Nuno Sá, Andy Shevchenko, Richard Genoud, Cosmin Tanislav,
Biju Das, Jianping Shen
Cc: linux-clk, linux-arm-kernel, linux-renesas-soc, linux-crypto,
linux-edac, qat-linux, linux-gpio, linux-aspeed, linux-iio,
linux-sound, linux-kernel, Geert Uytterhoeven
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/20251016142752.2627710-11-richard.genoud@bootlin.com
- "[PATCH 12/24] mtd: rawnand: sunxi: cosmetic: move NFC_ECC_MODE offset in SoC caps"
https://lore.kernel.org/20251016142752.2627710-13-richard.genoud@bootlin.com
- "[PATCH v2 05/15] mtd: rawnand: sunxi: rework pattern found registers"
https://lore.kernel.org/20251013152645.1119308-6-richard.genoud@bootlin.com
- "[PATCH v2 07/15] mtd: rawnand: sunxi: introduce ecc_mode_mask in sunxi_nfc_caps"
https://lore.kernel.org/20251013152645.1119308-8-richard.genoud@bootlin.com
- "[PATCH v5 2/2] iio: imu: smi330: Add driver"
https://lore.kernel.org/20251009153149.5162-3-Jianping.Shen@de.bosch.com
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/20250923144524.191892-3-biju.das.jz@bp.renesas.com
- "[PATCH v2 3/3] gpio: gpio-ltc4283: Add support for the LTC4283 Swap Controller"
https://lore.kernel.org/20250903-ltc4283-support-v2-3-6bce091510bf@analog.com
- "[PATCH v7 15/24] media: i2c: add Maxim GMSL2/3 serializer and deserializer framework"
https://lore.kernel.org/20250718152500.2656391-16-demonsingur@gmail.com
[2] "[PATCH v4 0/4] Non-const bitfield helpers"
https://lore.kernel.org/cover.1760696560.git.geert+renesas@glider.be
[3] "[PATCH v3 0/4] Non-const bitfield helpers"
https://lore.kernel.org/all/cover.1739540679.git.geert+renesas@glider.be/
[4] "[PATCH v2 0/3] Non-const bitfield helpers"
https://lore.kernel.org/all/cover.1738329458.git.geert+renesas@glider.be
[5] "[PATCH 00/17] Non-const bitfield helper conversions"
https://lore.kernel.org/all/cover.1637592133.git.geert+renesas@glider.be
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(-)
--
2.43.0
Gr{oetje,eeting}s,
Geert
--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org
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
^ permalink raw reply [flat|nested] 38+ messages in thread
* [PATCH v5 01/23] clk: at91: pmc: #undef field_{get,prep}() before definition
2025-10-27 18:41 [PATCH v5 00/23] Non-const bitfield helpers Geert Uytterhoeven
@ 2025-10-27 18:41 ` Geert Uytterhoeven
2025-10-27 20:36 ` Alexandre Belloni
2025-10-27 18:41 ` [PATCH v5 02/23] crypto: qat - #undef field_get() before local definition Geert Uytterhoeven
` (21 subsequent siblings)
22 siblings, 1 reply; 38+ messages in thread
From: Geert Uytterhoeven @ 2025-10-27 18:41 UTC (permalink / raw)
To: Michael Turquette, Stephen Boyd, Nicolas Ferre, Alexandre Belloni,
Claudiu Beznea, Giovanni Cabiddu, Herbert Xu, David Miller,
Linus Walleij, Bartosz Golaszewski, Joel Stanley, Andrew Jeffery,
Crt Mori, Jonathan Cameron, Lars-Peter Clausen, Jacky Huang,
Shan-Chun Hung, Yury Norov, Rasmus Villemoes, Jaroslav Kysela,
Takashi Iwai, Johannes Berg, Jakub Kicinski, Alex Elder,
David Laight, Vincent Mailhol, Jason Baron, Borislav Petkov,
Tony Luck, Michael Hennerich, Kim Seer Paller, David Lechner,
Nuno Sá, Andy Shevchenko, Richard Genoud, Cosmin Tanislav,
Biju Das, Jianping Shen
Cc: linux-clk, linux-arm-kernel, linux-renesas-soc, linux-crypto,
linux-edac, qat-linux, linux-gpio, linux-aspeed, linux-iio,
linux-sound, linux-kernel, Geert Uytterhoeven
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.
Suggested-by: Yury Norov <yury.norov@gmail.com>
Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
--
v5:
- New.
---
drivers/clk/at91/pmc.h | 2 ++
1 file changed, 2 insertions(+)
diff --git a/drivers/clk/at91/pmc.h b/drivers/clk/at91/pmc.h
index 5daa32c4cf2540d7..78a87d31463e98b0 100644
--- a/drivers/clk/at91/pmc.h
+++ b/drivers/clk/at91/pmc.h
@@ -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)
--
2.43.0
^ permalink raw reply related [flat|nested] 38+ messages in thread
* [PATCH v5 02/23] crypto: qat - #undef field_get() before local definition
2025-10-27 18:41 [PATCH v5 00/23] Non-const bitfield helpers Geert Uytterhoeven
2025-10-27 18:41 ` [PATCH v5 01/23] clk: at91: pmc: #undef field_{get,prep}() before definition Geert Uytterhoeven
@ 2025-10-27 18:41 ` Geert Uytterhoeven
2025-10-30 10:30 ` Giovanni Cabiddu
2025-10-27 18:41 ` [PATCH v5 03/23] EDAC/ie31200: " Geert Uytterhoeven
` (20 subsequent siblings)
22 siblings, 1 reply; 38+ messages in thread
From: Geert Uytterhoeven @ 2025-10-27 18:41 UTC (permalink / raw)
To: Michael Turquette, Stephen Boyd, Nicolas Ferre, Alexandre Belloni,
Claudiu Beznea, Giovanni Cabiddu, Herbert Xu, David Miller,
Linus Walleij, Bartosz Golaszewski, Joel Stanley, Andrew Jeffery,
Crt Mori, Jonathan Cameron, Lars-Peter Clausen, Jacky Huang,
Shan-Chun Hung, Yury Norov, Rasmus Villemoes, Jaroslav Kysela,
Takashi Iwai, Johannes Berg, Jakub Kicinski, Alex Elder,
David Laight, Vincent Mailhol, Jason Baron, Borislav Petkov,
Tony Luck, Michael Hennerich, Kim Seer Paller, David Lechner,
Nuno Sá, Andy Shevchenko, Richard Genoud, Cosmin Tanislav,
Biju Das, Jianping Shen
Cc: linux-clk, linux-arm-kernel, linux-renesas-soc, linux-crypto,
linux-edac, qat-linux, linux-gpio, linux-aspeed, linux-iio,
linux-sound, linux-kernel, 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 <yury.norov@gmail.com>
Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
--
v5:
- New.
---
drivers/crypto/intel/qat/qat_common/adf_pm_dbgfs_utils.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/drivers/crypto/intel/qat/qat_common/adf_pm_dbgfs_utils.c b/drivers/crypto/intel/qat/qat_common/adf_pm_dbgfs_utils.c
index 69295a9ddf0ac92f..6186fafb4a7b0dab 100644
--- a/drivers/crypto/intel/qat/qat_common/adf_pm_dbgfs_utils.c
+++ b/drivers/crypto/intel/qat/qat_common/adf_pm_dbgfs_utils.c
@@ -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
--
2.43.0
^ permalink raw reply related [flat|nested] 38+ messages in thread
* [PATCH v5 03/23] EDAC/ie31200: #undef field_get() before local definition
2025-10-27 18:41 [PATCH v5 00/23] Non-const bitfield helpers Geert Uytterhoeven
2025-10-27 18:41 ` [PATCH v5 01/23] clk: at91: pmc: #undef field_{get,prep}() before definition Geert Uytterhoeven
2025-10-27 18:41 ` [PATCH v5 02/23] crypto: qat - #undef field_get() before local definition Geert Uytterhoeven
@ 2025-10-27 18:41 ` Geert Uytterhoeven
2025-10-27 18:41 ` [PATCH v5 04/23] gpio: aspeed: #undef field_{get,prep}() " Geert Uytterhoeven
` (19 subsequent siblings)
22 siblings, 0 replies; 38+ messages in thread
From: Geert Uytterhoeven @ 2025-10-27 18:41 UTC (permalink / raw)
To: Michael Turquette, Stephen Boyd, Nicolas Ferre, Alexandre Belloni,
Claudiu Beznea, Giovanni Cabiddu, Herbert Xu, David Miller,
Linus Walleij, Bartosz Golaszewski, Joel Stanley, Andrew Jeffery,
Crt Mori, Jonathan Cameron, Lars-Peter Clausen, Jacky Huang,
Shan-Chun Hung, Yury Norov, Rasmus Villemoes, Jaroslav Kysela,
Takashi Iwai, Johannes Berg, Jakub Kicinski, Alex Elder,
David Laight, Vincent Mailhol, Jason Baron, Borislav Petkov,
Tony Luck, Michael Hennerich, Kim Seer Paller, David Lechner,
Nuno Sá, Andy Shevchenko, Richard Genoud, Cosmin Tanislav,
Biju Das, Jianping Shen
Cc: linux-clk, linux-arm-kernel, linux-renesas-soc, linux-crypto,
linux-edac, qat-linux, linux-gpio, linux-aspeed, linux-iio,
linux-sound, linux-kernel, 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 <yury.norov@gmail.com>
Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
--
v5:
- New.
---
drivers/edac/ie31200_edac.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/drivers/edac/ie31200_edac.c b/drivers/edac/ie31200_edac.c
index 5a080ab65476dacf..72290f430126c631 100644
--- a/drivers/edac/ie31200_edac.c
+++ b/drivers/edac/ie31200_edac.c
@@ -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;
--
2.43.0
^ permalink raw reply related [flat|nested] 38+ messages in thread
* [PATCH v5 04/23] gpio: aspeed: #undef field_{get,prep}() before local definition
2025-10-27 18:41 [PATCH v5 00/23] Non-const bitfield helpers Geert Uytterhoeven
` (2 preceding siblings ...)
2025-10-27 18:41 ` [PATCH v5 03/23] EDAC/ie31200: " Geert Uytterhoeven
@ 2025-10-27 18:41 ` Geert Uytterhoeven
2025-10-28 14:20 ` Bartosz Golaszewski
2025-10-27 18:41 ` [PATCH v5 05/23] iio: dac: ad3530r: #undef field_prep() " Geert Uytterhoeven
` (18 subsequent siblings)
22 siblings, 1 reply; 38+ messages in thread
From: Geert Uytterhoeven @ 2025-10-27 18:41 UTC (permalink / raw)
To: Michael Turquette, Stephen Boyd, Nicolas Ferre, Alexandre Belloni,
Claudiu Beznea, Giovanni Cabiddu, Herbert Xu, David Miller,
Linus Walleij, Bartosz Golaszewski, Joel Stanley, Andrew Jeffery,
Crt Mori, Jonathan Cameron, Lars-Peter Clausen, Jacky Huang,
Shan-Chun Hung, Yury Norov, Rasmus Villemoes, Jaroslav Kysela,
Takashi Iwai, Johannes Berg, Jakub Kicinski, Alex Elder,
David Laight, Vincent Mailhol, Jason Baron, Borislav Petkov,
Tony Luck, Michael Hennerich, Kim Seer Paller, David Lechner,
Nuno Sá, Andy Shevchenko, Richard Genoud, Cosmin Tanislav,
Biju Das, Jianping Shen
Cc: linux-clk, linux-arm-kernel, linux-renesas-soc, linux-crypto,
linux-edac, qat-linux, linux-gpio, linux-aspeed, linux-iio,
linux-sound, linux-kernel, Geert Uytterhoeven
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.
Suggested-by: Yury Norov <yury.norov@gmail.com>
Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
--
v5:
- New.
---
drivers/gpio/gpio-aspeed.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/drivers/gpio/gpio-aspeed.c b/drivers/gpio/gpio-aspeed.c
index 7953a9c4e36d7550..ef4ccaf74a5b379e 100644
--- a/drivers/gpio/gpio-aspeed.c
+++ b/drivers/gpio/gpio-aspeed.c
@@ -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
--
2.43.0
^ permalink raw reply related [flat|nested] 38+ messages in thread
* [PATCH v5 05/23] iio: dac: ad3530r: #undef field_prep() before local definition
2025-10-27 18:41 [PATCH v5 00/23] Non-const bitfield helpers Geert Uytterhoeven
` (3 preceding siblings ...)
2025-10-27 18:41 ` [PATCH v5 04/23] gpio: aspeed: #undef field_{get,prep}() " Geert Uytterhoeven
@ 2025-10-27 18:41 ` Geert Uytterhoeven
2025-10-27 18:41 ` [PATCH v5 06/23] iio: mlx90614: #undef field_{get,prep}() " Geert Uytterhoeven
` (17 subsequent siblings)
22 siblings, 0 replies; 38+ messages in thread
From: Geert Uytterhoeven @ 2025-10-27 18:41 UTC (permalink / raw)
To: Michael Turquette, Stephen Boyd, Nicolas Ferre, Alexandre Belloni,
Claudiu Beznea, Giovanni Cabiddu, Herbert Xu, David Miller,
Linus Walleij, Bartosz Golaszewski, Joel Stanley, Andrew Jeffery,
Crt Mori, Jonathan Cameron, Lars-Peter Clausen, Jacky Huang,
Shan-Chun Hung, Yury Norov, Rasmus Villemoes, Jaroslav Kysela,
Takashi Iwai, Johannes Berg, Jakub Kicinski, Alex Elder,
David Laight, Vincent Mailhol, Jason Baron, Borislav Petkov,
Tony Luck, Michael Hennerich, Kim Seer Paller, David Lechner,
Nuno Sá, Andy Shevchenko, Richard Genoud, Cosmin Tanislav,
Biju Das, Jianping Shen
Cc: linux-clk, linux-arm-kernel, linux-renesas-soc, linux-crypto,
linux-edac, qat-linux, linux-gpio, linux-aspeed, linux-iio,
linux-sound, linux-kernel, Geert Uytterhoeven
Prepare 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.
Suggested-by: Yury Norov <yury.norov@gmail.com>
Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
--
v5:
- New.
---
drivers/iio/dac/ad3530r.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/drivers/iio/dac/ad3530r.c b/drivers/iio/dac/ad3530r.c
index 6134613777b8e1d4..5684d11137f29948 100644
--- a/drivers/iio/dac/ad3530r.c
+++ b/drivers/iio/dac/ad3530r.c
@@ -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 {
--
2.43.0
^ permalink raw reply related [flat|nested] 38+ messages in thread
* [PATCH v5 06/23] iio: mlx90614: #undef field_{get,prep}() before local definition
2025-10-27 18:41 [PATCH v5 00/23] Non-const bitfield helpers Geert Uytterhoeven
` (4 preceding siblings ...)
2025-10-27 18:41 ` [PATCH v5 05/23] iio: dac: ad3530r: #undef field_prep() " Geert Uytterhoeven
@ 2025-10-27 18:41 ` Geert Uytterhoeven
2025-10-27 18:41 ` [PATCH v5 07/23] pinctrl: ma35: " Geert Uytterhoeven
` (16 subsequent siblings)
22 siblings, 0 replies; 38+ messages in thread
From: Geert Uytterhoeven @ 2025-10-27 18:41 UTC (permalink / raw)
To: Michael Turquette, Stephen Boyd, Nicolas Ferre, Alexandre Belloni,
Claudiu Beznea, Giovanni Cabiddu, Herbert Xu, David Miller,
Linus Walleij, Bartosz Golaszewski, Joel Stanley, Andrew Jeffery,
Crt Mori, Jonathan Cameron, Lars-Peter Clausen, Jacky Huang,
Shan-Chun Hung, Yury Norov, Rasmus Villemoes, Jaroslav Kysela,
Takashi Iwai, Johannes Berg, Jakub Kicinski, Alex Elder,
David Laight, Vincent Mailhol, Jason Baron, Borislav Petkov,
Tony Luck, Michael Hennerich, Kim Seer Paller, David Lechner,
Nuno Sá, Andy Shevchenko, Richard Genoud, Cosmin Tanislav,
Biju Das, Jianping Shen
Cc: linux-clk, linux-arm-kernel, linux-renesas-soc, linux-crypto,
linux-edac, qat-linux, linux-gpio, linux-aspeed, linux-iio,
linux-sound, linux-kernel, Geert Uytterhoeven
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.
Suggested-by: Yury Norov <yury.norov@gmail.com>
Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
--
v5:
- New.
---
drivers/iio/temperature/mlx90614.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/drivers/iio/temperature/mlx90614.c b/drivers/iio/temperature/mlx90614.c
index 8a44a00bfd5ece38..de5615fdb396aa3c 100644
--- a/drivers/iio/temperature/mlx90614.c
+++ b/drivers/iio/temperature/mlx90614.c
@@ -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 {
--
2.43.0
^ permalink raw reply related [flat|nested] 38+ messages in thread
* [PATCH v5 07/23] pinctrl: ma35: #undef field_{get,prep}() before local definition
2025-10-27 18:41 [PATCH v5 00/23] Non-const bitfield helpers Geert Uytterhoeven
` (5 preceding siblings ...)
2025-10-27 18:41 ` [PATCH v5 06/23] iio: mlx90614: #undef field_{get,prep}() " Geert Uytterhoeven
@ 2025-10-27 18:41 ` Geert Uytterhoeven
2025-10-29 14:19 ` Linus Walleij
2025-10-27 18:41 ` [PATCH v5 08/23] soc: renesas: rz-sysc: #undef field_get() " Geert Uytterhoeven
` (15 subsequent siblings)
22 siblings, 1 reply; 38+ messages in thread
From: Geert Uytterhoeven @ 2025-10-27 18:41 UTC (permalink / raw)
To: Michael Turquette, Stephen Boyd, Nicolas Ferre, Alexandre Belloni,
Claudiu Beznea, Giovanni Cabiddu, Herbert Xu, David Miller,
Linus Walleij, Bartosz Golaszewski, Joel Stanley, Andrew Jeffery,
Crt Mori, Jonathan Cameron, Lars-Peter Clausen, Jacky Huang,
Shan-Chun Hung, Yury Norov, Rasmus Villemoes, Jaroslav Kysela,
Takashi Iwai, Johannes Berg, Jakub Kicinski, Alex Elder,
David Laight, Vincent Mailhol, Jason Baron, Borislav Petkov,
Tony Luck, Michael Hennerich, Kim Seer Paller, David Lechner,
Nuno Sá, Andy Shevchenko, Richard Genoud, Cosmin Tanislav,
Biju Das, Jianping Shen
Cc: linux-clk, linux-arm-kernel, linux-renesas-soc, linux-crypto,
linux-edac, qat-linux, linux-gpio, linux-aspeed, linux-iio,
linux-sound, linux-kernel, Geert Uytterhoeven
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.
Suggested-by: Yury Norov <yury.norov@gmail.com>
Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
--
v5:
- New.
---
drivers/pinctrl/nuvoton/pinctrl-ma35.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/drivers/pinctrl/nuvoton/pinctrl-ma35.c b/drivers/pinctrl/nuvoton/pinctrl-ma35.c
index cdad01d68a37e365..925dd717c9deead5 100644
--- a/drivers/pinctrl/nuvoton/pinctrl-ma35.c
+++ b/drivers/pinctrl/nuvoton/pinctrl-ma35.c
@@ -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[] = {
--
2.43.0
^ permalink raw reply related [flat|nested] 38+ messages in thread
* [PATCH v5 08/23] soc: renesas: rz-sysc: #undef field_get() before local definition
2025-10-27 18:41 [PATCH v5 00/23] Non-const bitfield helpers Geert Uytterhoeven
` (6 preceding siblings ...)
2025-10-27 18:41 ` [PATCH v5 07/23] pinctrl: ma35: " Geert Uytterhoeven
@ 2025-10-27 18:41 ` Geert Uytterhoeven
2025-10-27 18:41 ` [PATCH v5 09/23] ALSA: usb-audio: #undef field_{get,prep}() " Geert Uytterhoeven
` (14 subsequent siblings)
22 siblings, 0 replies; 38+ messages in thread
From: Geert Uytterhoeven @ 2025-10-27 18:41 UTC (permalink / raw)
To: Michael Turquette, Stephen Boyd, Nicolas Ferre, Alexandre Belloni,
Claudiu Beznea, Giovanni Cabiddu, Herbert Xu, David Miller,
Linus Walleij, Bartosz Golaszewski, Joel Stanley, Andrew Jeffery,
Crt Mori, Jonathan Cameron, Lars-Peter Clausen, Jacky Huang,
Shan-Chun Hung, Yury Norov, Rasmus Villemoes, Jaroslav Kysela,
Takashi Iwai, Johannes Berg, Jakub Kicinski, Alex Elder,
David Laight, Vincent Mailhol, Jason Baron, Borislav Petkov,
Tony Luck, Michael Hennerich, Kim Seer Paller, David Lechner,
Nuno Sá, Andy Shevchenko, Richard Genoud, Cosmin Tanislav,
Biju Das, Jianping Shen
Cc: linux-clk, linux-arm-kernel, linux-renesas-soc, linux-crypto,
linux-edac, qat-linux, linux-gpio, linux-aspeed, linux-iio,
linux-sound, linux-kernel, 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 <yury.norov@gmail.com>
Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
--
v5:
- New.
---
drivers/soc/renesas/rz-sysc.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/drivers/soc/renesas/rz-sysc.c b/drivers/soc/renesas/rz-sysc.c
index 9f79e299e6f41641..b9880085d3634065 100644
--- a/drivers/soc/renesas/rz-sysc.c
+++ b/drivers/soc/renesas/rz-sysc.c
@@ -16,6 +16,7 @@
#include "rz-sysc.h"
+#undef field_get
#define field_get(_mask, _reg) (((_reg) & (_mask)) >> (ffs(_mask) - 1))
/**
--
2.43.0
^ permalink raw reply related [flat|nested] 38+ messages in thread
* [PATCH v5 09/23] ALSA: usb-audio: #undef field_{get,prep}() before local definition
2025-10-27 18:41 [PATCH v5 00/23] Non-const bitfield helpers Geert Uytterhoeven
` (7 preceding siblings ...)
2025-10-27 18:41 ` [PATCH v5 08/23] soc: renesas: rz-sysc: #undef field_get() " Geert Uytterhoeven
@ 2025-10-27 18:41 ` Geert Uytterhoeven
2025-10-28 16:13 ` Takashi Iwai
2025-10-27 18:41 ` [PATCH -next v5 10/23] iio: imu: smi330: #undef field_{get,prep}() before definition Geert Uytterhoeven
` (13 subsequent siblings)
22 siblings, 1 reply; 38+ messages in thread
From: Geert Uytterhoeven @ 2025-10-27 18:41 UTC (permalink / raw)
To: Michael Turquette, Stephen Boyd, Nicolas Ferre, Alexandre Belloni,
Claudiu Beznea, Giovanni Cabiddu, Herbert Xu, David Miller,
Linus Walleij, Bartosz Golaszewski, Joel Stanley, Andrew Jeffery,
Crt Mori, Jonathan Cameron, Lars-Peter Clausen, Jacky Huang,
Shan-Chun Hung, Yury Norov, Rasmus Villemoes, Jaroslav Kysela,
Takashi Iwai, Johannes Berg, Jakub Kicinski, Alex Elder,
David Laight, Vincent Mailhol, Jason Baron, Borislav Petkov,
Tony Luck, Michael Hennerich, Kim Seer Paller, David Lechner,
Nuno Sá, Andy Shevchenko, Richard Genoud, Cosmin Tanislav,
Biju Das, Jianping Shen
Cc: linux-clk, linux-arm-kernel, linux-renesas-soc, linux-crypto,
linux-edac, qat-linux, linux-gpio, linux-aspeed, linux-iio,
linux-sound, linux-kernel, Geert Uytterhoeven
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.
Suggested-by: Yury Norov <yury.norov@gmail.com>
Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
--
v5:
- New.
---
sound/usb/mixer_quirks.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/sound/usb/mixer_quirks.c b/sound/usb/mixer_quirks.c
index 828af3095b86ee0a..713a8498b975e1ac 100644
--- a/sound/usb/mixer_quirks.c
+++ b/sound/usb/mixer_quirks.c
@@ -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)
--
2.43.0
^ permalink raw reply related [flat|nested] 38+ messages in thread
* [PATCH -next v5 10/23] iio: imu: smi330: #undef field_{get,prep}() before definition
2025-10-27 18:41 [PATCH v5 00/23] Non-const bitfield helpers Geert Uytterhoeven
` (8 preceding siblings ...)
2025-10-27 18:41 ` [PATCH v5 09/23] ALSA: usb-audio: #undef field_{get,prep}() " Geert Uytterhoeven
@ 2025-10-27 18:41 ` Geert Uytterhoeven
2025-10-27 18:41 ` [PATCH v5 11/23] bitfield: Add non-constant field_{prep,get}() helpers Geert Uytterhoeven
` (12 subsequent siblings)
22 siblings, 0 replies; 38+ messages in thread
From: Geert Uytterhoeven @ 2025-10-27 18:41 UTC (permalink / raw)
To: Michael Turquette, Stephen Boyd, Nicolas Ferre, Alexandre Belloni,
Claudiu Beznea, Giovanni Cabiddu, Herbert Xu, David Miller,
Linus Walleij, Bartosz Golaszewski, Joel Stanley, Andrew Jeffery,
Crt Mori, Jonathan Cameron, Lars-Peter Clausen, Jacky Huang,
Shan-Chun Hung, Yury Norov, Rasmus Villemoes, Jaroslav Kysela,
Takashi Iwai, Johannes Berg, Jakub Kicinski, Alex Elder,
David Laight, Vincent Mailhol, Jason Baron, Borislav Petkov,
Tony Luck, Michael Hennerich, Kim Seer Paller, David Lechner,
Nuno Sá, Andy Shevchenko, Richard Genoud, Cosmin Tanislav,
Biju Das, Jianping Shen
Cc: linux-clk, linux-arm-kernel, linux-renesas-soc, linux-crypto,
linux-edac, qat-linux, linux-gpio, linux-aspeed, linux-iio,
linux-sound, linux-kernel, Geert Uytterhoeven
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.
Suggested-by: Yury Norov <yury.norov@gmail.com>
Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
--
v5:
- New.
---
drivers/iio/imu/smi330/smi330_core.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/drivers/iio/imu/smi330/smi330_core.c b/drivers/iio/imu/smi330/smi330_core.c
index d9178725ade3da83..a79964fe68fadf47 100644
--- a/drivers/iio/imu/smi330/smi330_core.c
+++ b/drivers/iio/imu/smi330/smi330_core.c
@@ -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) { \
--
2.43.0
^ permalink raw reply related [flat|nested] 38+ messages in thread
* [PATCH v5 11/23] bitfield: Add non-constant field_{prep,get}() helpers
2025-10-27 18:41 [PATCH v5 00/23] Non-const bitfield helpers Geert Uytterhoeven
` (9 preceding siblings ...)
2025-10-27 18:41 ` [PATCH -next v5 10/23] iio: imu: smi330: #undef field_{get,prep}() before definition Geert Uytterhoeven
@ 2025-10-27 18:41 ` Geert Uytterhoeven
2025-10-28 9:15 ` Andy Shevchenko
2025-10-27 18:41 ` [PATCH v5 12/23] clk: at91: Convert to common field_{get,prep}() helpers Geert Uytterhoeven
` (11 subsequent siblings)
22 siblings, 1 reply; 38+ messages in thread
From: Geert Uytterhoeven @ 2025-10-27 18:41 UTC (permalink / raw)
To: Michael Turquette, Stephen Boyd, Nicolas Ferre, Alexandre Belloni,
Claudiu Beznea, Giovanni Cabiddu, Herbert Xu, David Miller,
Linus Walleij, Bartosz Golaszewski, Joel Stanley, Andrew Jeffery,
Crt Mori, Jonathan Cameron, Lars-Peter Clausen, Jacky Huang,
Shan-Chun Hung, Yury Norov, Rasmus Villemoes, Jaroslav Kysela,
Takashi Iwai, Johannes Berg, Jakub Kicinski, Alex Elder,
David Laight, Vincent Mailhol, Jason Baron, Borislav Petkov,
Tony Luck, Michael Hennerich, Kim Seer Paller, David Lechner,
Nuno Sá, Andy Shevchenko, Richard Genoud, Cosmin Tanislav,
Biju Das, Jianping Shen
Cc: linux-clk, linux-arm-kernel, linux-renesas-soc, linux-crypto,
linux-edac, qat-linux, linux-gpio, linux-aspeed, linux-iio,
linux-sound, linux-kernel, Geert Uytterhoeven, Jonathan Cameron
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.
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.
Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
Acked-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
Acked-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Acked-by: Crt Mori <cmo@melexis.com>
Acked-by: Nuno Sá <nuno.sa@analog.com>
Acked-by: Richard Genoud <richard.genoud@bootlin.com>
---
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(+)
diff --git a/include/linux/bitfield.h b/include/linux/bitfield.h
index 5355f8f806a97974..d220790fd068305c 100644
--- a/include/linux/bitfield.h
+++ b/include/linux/bitfield.h
@@ -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
--
2.43.0
^ permalink raw reply related [flat|nested] 38+ messages in thread
* [PATCH v5 12/23] clk: at91: Convert to common field_{get,prep}() helpers
2025-10-27 18:41 [PATCH v5 00/23] Non-const bitfield helpers Geert Uytterhoeven
` (10 preceding siblings ...)
2025-10-27 18:41 ` [PATCH v5 11/23] bitfield: Add non-constant field_{prep,get}() helpers Geert Uytterhoeven
@ 2025-10-27 18:41 ` Geert Uytterhoeven
2025-10-27 18:41 ` [PATCH v5 13/23] crypto: qat - convert to common field_get() helper Geert Uytterhoeven
` (10 subsequent siblings)
22 siblings, 0 replies; 38+ messages in thread
From: Geert Uytterhoeven @ 2025-10-27 18:41 UTC (permalink / raw)
To: Michael Turquette, Stephen Boyd, Nicolas Ferre, Alexandre Belloni,
Claudiu Beznea, Giovanni Cabiddu, Herbert Xu, David Miller,
Linus Walleij, Bartosz Golaszewski, Joel Stanley, Andrew Jeffery,
Crt Mori, Jonathan Cameron, Lars-Peter Clausen, Jacky Huang,
Shan-Chun Hung, Yury Norov, Rasmus Villemoes, Jaroslav Kysela,
Takashi Iwai, Johannes Berg, Jakub Kicinski, Alex Elder,
David Laight, Vincent Mailhol, Jason Baron, Borislav Petkov,
Tony Luck, Michael Hennerich, Kim Seer Paller, David Lechner,
Nuno Sá, Andy Shevchenko, Richard Genoud, Cosmin Tanislav,
Biju Das, Jianping Shen
Cc: linux-clk, linux-arm-kernel, linux-renesas-soc, linux-crypto,
linux-edac, qat-linux, linux-gpio, linux-aspeed, linux-iio,
linux-sound, linux-kernel, Geert Uytterhoeven
Drop the driver-specific field_get() and field_prep() macros, in favor
of the globally available variants from <linux/bitfield.h>.
Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
Acked-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
---
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(-)
diff --git a/drivers/clk/at91/clk-peripheral.c b/drivers/clk/at91/clk-peripheral.c
index e700f40fd87f9327..e7208c47268b6397 100644
--- a/drivers/clk/at91/clk-peripheral.c
+++ b/drivers/clk/at91/clk-peripheral.c
@@ -3,6 +3,7 @@
* Copyright (C) 2013 Boris BREZILLON <b.brezillon@overkiz.com>
*/
+#include <linux/bitfield.h>
#include <linux/bitops.h>
#include <linux/clk-provider.h>
#include <linux/clkdev.h>
diff --git a/drivers/clk/at91/pmc.h b/drivers/clk/at91/pmc.h
index 78a87d31463e98b0..543d7aee8d248cdb 100644
--- a/drivers/clk/at91/pmc.h
+++ b/drivers/clk/at91/pmc.h
@@ -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)
--
2.43.0
^ permalink raw reply related [flat|nested] 38+ messages in thread
* [PATCH v5 13/23] crypto: qat - convert to common field_get() helper
2025-10-27 18:41 [PATCH v5 00/23] Non-const bitfield helpers Geert Uytterhoeven
` (11 preceding siblings ...)
2025-10-27 18:41 ` [PATCH v5 12/23] clk: at91: Convert to common field_{get,prep}() helpers Geert Uytterhoeven
@ 2025-10-27 18:41 ` Geert Uytterhoeven
2025-10-30 10:31 ` Giovanni Cabiddu
2025-10-27 18:41 ` [PATCH v5 14/23] EDAC/ie31200: Convert " Geert Uytterhoeven
` (9 subsequent siblings)
22 siblings, 1 reply; 38+ messages in thread
From: Geert Uytterhoeven @ 2025-10-27 18:41 UTC (permalink / raw)
To: Michael Turquette, Stephen Boyd, Nicolas Ferre, Alexandre Belloni,
Claudiu Beznea, Giovanni Cabiddu, Herbert Xu, David Miller,
Linus Walleij, Bartosz Golaszewski, Joel Stanley, Andrew Jeffery,
Crt Mori, Jonathan Cameron, Lars-Peter Clausen, Jacky Huang,
Shan-Chun Hung, Yury Norov, Rasmus Villemoes, Jaroslav Kysela,
Takashi Iwai, Johannes Berg, Jakub Kicinski, Alex Elder,
David Laight, Vincent Mailhol, Jason Baron, Borislav Petkov,
Tony Luck, Michael Hennerich, Kim Seer Paller, David Lechner,
Nuno Sá, Andy Shevchenko, Richard Genoud, Cosmin Tanislav,
Biju Das, Jianping Shen
Cc: linux-clk, linux-arm-kernel, linux-renesas-soc, linux-crypto,
linux-edac, qat-linux, linux-gpio, linux-aspeed, linux-iio,
linux-sound, linux-kernel, 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 <geert+renesas@glider.be>
---
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(-)
diff --git a/drivers/crypto/intel/qat/qat_common/adf_pm_dbgfs_utils.c b/drivers/crypto/intel/qat/qat_common/adf_pm_dbgfs_utils.c
index 6186fafb4a7b0dab..4ccc94ed9493a64c 100644
--- a/drivers/crypto/intel/qat/qat_common/adf_pm_dbgfs_utils.c
+++ b/drivers/crypto/intel/qat/qat_common/adf_pm_dbgfs_utils.c
@@ -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,
--
2.43.0
^ permalink raw reply related [flat|nested] 38+ messages in thread
* [PATCH v5 14/23] EDAC/ie31200: Convert to common field_get() helper
2025-10-27 18:41 [PATCH v5 00/23] Non-const bitfield helpers Geert Uytterhoeven
` (12 preceding siblings ...)
2025-10-27 18:41 ` [PATCH v5 13/23] crypto: qat - convert to common field_get() helper Geert Uytterhoeven
@ 2025-10-27 18:41 ` Geert Uytterhoeven
2025-10-27 18:41 ` [PATCH v5 15/23] gpio: aspeed: Convert to common field_{get,prep}() helpers Geert Uytterhoeven
` (8 subsequent siblings)
22 siblings, 0 replies; 38+ messages in thread
From: Geert Uytterhoeven @ 2025-10-27 18:41 UTC (permalink / raw)
To: Michael Turquette, Stephen Boyd, Nicolas Ferre, Alexandre Belloni,
Claudiu Beznea, Giovanni Cabiddu, Herbert Xu, David Miller,
Linus Walleij, Bartosz Golaszewski, Joel Stanley, Andrew Jeffery,
Crt Mori, Jonathan Cameron, Lars-Peter Clausen, Jacky Huang,
Shan-Chun Hung, Yury Norov, Rasmus Villemoes, Jaroslav Kysela,
Takashi Iwai, Johannes Berg, Jakub Kicinski, Alex Elder,
David Laight, Vincent Mailhol, Jason Baron, Borislav Petkov,
Tony Luck, Michael Hennerich, Kim Seer Paller, David Lechner,
Nuno Sá, Andy Shevchenko, Richard Genoud, Cosmin Tanislav,
Biju Das, Jianping Shen
Cc: linux-clk, linux-arm-kernel, linux-renesas-soc, linux-crypto,
linux-edac, qat-linux, linux-gpio, linux-aspeed, linux-iio,
linux-sound, linux-kernel, 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 <geert+renesas@glider.be>
---
v5:
- Extracted from "bitfield: Add non-constant field_{prep,get}()
helpers".
---
drivers/edac/ie31200_edac.c | 5 +----
1 file changed, 1 insertion(+), 4 deletions(-)
diff --git a/drivers/edac/ie31200_edac.c b/drivers/edac/ie31200_edac.c
index 72290f430126c631..dfc9a9cecd74207d 100644
--- a/drivers/edac/ie31200_edac.c
+++ b/drivers/edac/ie31200_edac.c
@@ -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;
--
2.43.0
^ permalink raw reply related [flat|nested] 38+ messages in thread
* [PATCH v5 15/23] gpio: aspeed: Convert to common field_{get,prep}() helpers
2025-10-27 18:41 [PATCH v5 00/23] Non-const bitfield helpers Geert Uytterhoeven
` (13 preceding siblings ...)
2025-10-27 18:41 ` [PATCH v5 14/23] EDAC/ie31200: Convert " Geert Uytterhoeven
@ 2025-10-27 18:41 ` Geert Uytterhoeven
2025-10-27 18:41 ` [PATCH v5 16/23] iio: dac: Convert to common field_prep() helper Geert Uytterhoeven
` (7 subsequent siblings)
22 siblings, 0 replies; 38+ messages in thread
From: Geert Uytterhoeven @ 2025-10-27 18:41 UTC (permalink / raw)
To: Michael Turquette, Stephen Boyd, Nicolas Ferre, Alexandre Belloni,
Claudiu Beznea, Giovanni Cabiddu, Herbert Xu, David Miller,
Linus Walleij, Bartosz Golaszewski, Joel Stanley, Andrew Jeffery,
Crt Mori, Jonathan Cameron, Lars-Peter Clausen, Jacky Huang,
Shan-Chun Hung, Yury Norov, Rasmus Villemoes, Jaroslav Kysela,
Takashi Iwai, Johannes Berg, Jakub Kicinski, Alex Elder,
David Laight, Vincent Mailhol, Jason Baron, Borislav Petkov,
Tony Luck, Michael Hennerich, Kim Seer Paller, David Lechner,
Nuno Sá, Andy Shevchenko, Richard Genoud, Cosmin Tanislav,
Biju Das, Jianping Shen
Cc: linux-clk, linux-arm-kernel, linux-renesas-soc, linux-crypto,
linux-edac, qat-linux, linux-gpio, linux-aspeed, linux-iio,
linux-sound, linux-kernel, Geert Uytterhoeven
Drop the driver-specific field_get() and field_prep() macros, in favor
of the globally available variants from <linux/bitfield.h>.
Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
---
v5:
- Extracted from "bitfield: Add non-constant field_{prep,get}()
helpers".
---
drivers/gpio/gpio-aspeed.c | 7 +------
1 file changed, 1 insertion(+), 6 deletions(-)
diff --git a/drivers/gpio/gpio-aspeed.c b/drivers/gpio/gpio-aspeed.c
index ef4ccaf74a5b379e..3da999334971d501 100644
--- a/drivers/gpio/gpio-aspeed.c
+++ b/drivers/gpio/gpio-aspeed.c
@@ -5,6 +5,7 @@
* Joel Stanley <joel@jms.id.au>
*/
+#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
--
2.43.0
^ permalink raw reply related [flat|nested] 38+ messages in thread
* [PATCH v5 16/23] iio: dac: Convert to common field_prep() helper
2025-10-27 18:41 [PATCH v5 00/23] Non-const bitfield helpers Geert Uytterhoeven
` (14 preceding siblings ...)
2025-10-27 18:41 ` [PATCH v5 15/23] gpio: aspeed: Convert to common field_{get,prep}() helpers Geert Uytterhoeven
@ 2025-10-27 18:41 ` Geert Uytterhoeven
2025-10-27 18:41 ` [PATCH v5 17/23] iio: mlx90614: Convert to common field_{get,prep}() helpers Geert Uytterhoeven
` (6 subsequent siblings)
22 siblings, 0 replies; 38+ messages in thread
From: Geert Uytterhoeven @ 2025-10-27 18:41 UTC (permalink / raw)
To: Michael Turquette, Stephen Boyd, Nicolas Ferre, Alexandre Belloni,
Claudiu Beznea, Giovanni Cabiddu, Herbert Xu, David Miller,
Linus Walleij, Bartosz Golaszewski, Joel Stanley, Andrew Jeffery,
Crt Mori, Jonathan Cameron, Lars-Peter Clausen, Jacky Huang,
Shan-Chun Hung, Yury Norov, Rasmus Villemoes, Jaroslav Kysela,
Takashi Iwai, Johannes Berg, Jakub Kicinski, Alex Elder,
David Laight, Vincent Mailhol, Jason Baron, Borislav Petkov,
Tony Luck, Michael Hennerich, Kim Seer Paller, David Lechner,
Nuno Sá, Andy Shevchenko, Richard Genoud, Cosmin Tanislav,
Biju Das, Jianping Shen
Cc: linux-clk, linux-arm-kernel, linux-renesas-soc, linux-crypto,
linux-edac, qat-linux, linux-gpio, linux-aspeed, linux-iio,
linux-sound, linux-kernel, Geert Uytterhoeven, Jonathan Cameron
Drop the driver-specific field_prep() macro, in favor of the globally
available variant from <linux/bitfield.h>.
Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
Acked-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
---
v5:
- Extracted from "bitfield: Add non-constant field_{prep,get}()
helpers".
---
drivers/iio/dac/ad3530r.c | 4 ----
1 file changed, 4 deletions(-)
diff --git a/drivers/iio/dac/ad3530r.c b/drivers/iio/dac/ad3530r.c
index 5684d11137f29948..b97b46090d808ee7 100644
--- a/drivers/iio/dac/ad3530r.c
+++ b/drivers/iio/dac/ad3530r.c
@@ -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,
--
2.43.0
^ permalink raw reply related [flat|nested] 38+ messages in thread
* [PATCH v5 17/23] iio: mlx90614: Convert to common field_{get,prep}() helpers
2025-10-27 18:41 [PATCH v5 00/23] Non-const bitfield helpers Geert Uytterhoeven
` (15 preceding siblings ...)
2025-10-27 18:41 ` [PATCH v5 16/23] iio: dac: Convert to common field_prep() helper Geert Uytterhoeven
@ 2025-10-27 18:41 ` Geert Uytterhoeven
2025-10-27 18:41 ` [PATCH v5 18/23] pinctrl: ma35: " Geert Uytterhoeven
` (5 subsequent siblings)
22 siblings, 0 replies; 38+ messages in thread
From: Geert Uytterhoeven @ 2025-10-27 18:41 UTC (permalink / raw)
To: Michael Turquette, Stephen Boyd, Nicolas Ferre, Alexandre Belloni,
Claudiu Beznea, Giovanni Cabiddu, Herbert Xu, David Miller,
Linus Walleij, Bartosz Golaszewski, Joel Stanley, Andrew Jeffery,
Crt Mori, Jonathan Cameron, Lars-Peter Clausen, Jacky Huang,
Shan-Chun Hung, Yury Norov, Rasmus Villemoes, Jaroslav Kysela,
Takashi Iwai, Johannes Berg, Jakub Kicinski, Alex Elder,
David Laight, Vincent Mailhol, Jason Baron, Borislav Petkov,
Tony Luck, Michael Hennerich, Kim Seer Paller, David Lechner,
Nuno Sá, Andy Shevchenko, Richard Genoud, Cosmin Tanislav,
Biju Das, Jianping Shen
Cc: linux-clk, linux-arm-kernel, linux-renesas-soc, linux-crypto,
linux-edac, qat-linux, linux-gpio, linux-aspeed, linux-iio,
linux-sound, linux-kernel, Geert Uytterhoeven, Jonathan Cameron
Drop the driver-specific field_get() and field_prep() macros, in favor
of the globally available variants from <linux/bitfield.h>.
Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
Acked-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Acked-by: Crt Mori <cmo@melexis.com>
---
v5:
- Extracted from "bitfield: Add non-constant field_{prep,get}()
helpers".
---
drivers/iio/temperature/mlx90614.c | 7 +------
1 file changed, 1 insertion(+), 6 deletions(-)
diff --git a/drivers/iio/temperature/mlx90614.c b/drivers/iio/temperature/mlx90614.c
index de5615fdb396aa3c..1ad21b73e1b44cb0 100644
--- a/drivers/iio/temperature/mlx90614.c
+++ b/drivers/iio/temperature/mlx90614.c
@@ -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 */
--
2.43.0
^ permalink raw reply related [flat|nested] 38+ messages in thread
* [PATCH v5 18/23] pinctrl: ma35: Convert to common field_{get,prep}() helpers
2025-10-27 18:41 [PATCH v5 00/23] Non-const bitfield helpers Geert Uytterhoeven
` (16 preceding siblings ...)
2025-10-27 18:41 ` [PATCH v5 17/23] iio: mlx90614: Convert to common field_{get,prep}() helpers Geert Uytterhoeven
@ 2025-10-27 18:41 ` Geert Uytterhoeven
2025-10-29 14:21 ` Linus Walleij
2025-10-27 18:41 ` [PATCH v5 19/23] soc: renesas: rz-sysc: Convert to common field_get() helper Geert Uytterhoeven
` (4 subsequent siblings)
22 siblings, 1 reply; 38+ messages in thread
From: Geert Uytterhoeven @ 2025-10-27 18:41 UTC (permalink / raw)
To: Michael Turquette, Stephen Boyd, Nicolas Ferre, Alexandre Belloni,
Claudiu Beznea, Giovanni Cabiddu, Herbert Xu, David Miller,
Linus Walleij, Bartosz Golaszewski, Joel Stanley, Andrew Jeffery,
Crt Mori, Jonathan Cameron, Lars-Peter Clausen, Jacky Huang,
Shan-Chun Hung, Yury Norov, Rasmus Villemoes, Jaroslav Kysela,
Takashi Iwai, Johannes Berg, Jakub Kicinski, Alex Elder,
David Laight, Vincent Mailhol, Jason Baron, Borislav Petkov,
Tony Luck, Michael Hennerich, Kim Seer Paller, David Lechner,
Nuno Sá, Andy Shevchenko, Richard Genoud, Cosmin Tanislav,
Biju Das, Jianping Shen
Cc: linux-clk, linux-arm-kernel, linux-renesas-soc, linux-crypto,
linux-edac, qat-linux, linux-gpio, linux-aspeed, linux-iio,
linux-sound, linux-kernel, Geert Uytterhoeven
Drop the driver-specific field_get() and field_prep() macros, in favor
of the globally available variants from <linux/bitfield.h>.
Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
---
v5:
- Extracted from "bitfield: Add non-constant field_{prep,get}()
helpers".
---
drivers/pinctrl/nuvoton/pinctrl-ma35.c | 6 ------
1 file changed, 6 deletions(-)
diff --git a/drivers/pinctrl/nuvoton/pinctrl-ma35.c b/drivers/pinctrl/nuvoton/pinctrl-ma35.c
index 925dd717c9deead5..8d71dc53cc1de1f8 100644
--- a/drivers/pinctrl/nuvoton/pinctrl-ma35.c
+++ b/drivers/pinctrl/nuvoton/pinctrl-ma35.c
@@ -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",
--
2.43.0
^ permalink raw reply related [flat|nested] 38+ messages in thread
* [PATCH v5 19/23] soc: renesas: rz-sysc: Convert to common field_get() helper
2025-10-27 18:41 [PATCH v5 00/23] Non-const bitfield helpers Geert Uytterhoeven
` (17 preceding siblings ...)
2025-10-27 18:41 ` [PATCH v5 18/23] pinctrl: ma35: " Geert Uytterhoeven
@ 2025-10-27 18:41 ` Geert Uytterhoeven
2025-10-27 18:41 ` [PATCH v5 20/23] ALSA: usb-audio: Convert to common field_{get,prep}() helpers Geert Uytterhoeven
` (3 subsequent siblings)
22 siblings, 0 replies; 38+ messages in thread
From: Geert Uytterhoeven @ 2025-10-27 18:41 UTC (permalink / raw)
To: Michael Turquette, Stephen Boyd, Nicolas Ferre, Alexandre Belloni,
Claudiu Beznea, Giovanni Cabiddu, Herbert Xu, David Miller,
Linus Walleij, Bartosz Golaszewski, Joel Stanley, Andrew Jeffery,
Crt Mori, Jonathan Cameron, Lars-Peter Clausen, Jacky Huang,
Shan-Chun Hung, Yury Norov, Rasmus Villemoes, Jaroslav Kysela,
Takashi Iwai, Johannes Berg, Jakub Kicinski, Alex Elder,
David Laight, Vincent Mailhol, Jason Baron, Borislav Petkov,
Tony Luck, Michael Hennerich, Kim Seer Paller, David Lechner,
Nuno Sá, Andy Shevchenko, Richard Genoud, Cosmin Tanislav,
Biju Das, Jianping Shen
Cc: linux-clk, linux-arm-kernel, linux-renesas-soc, linux-crypto,
linux-edac, qat-linux, linux-gpio, linux-aspeed, linux-iio,
linux-sound, linux-kernel, 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 <geert+renesas@glider.be>
---
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(-)
diff --git a/drivers/soc/renesas/rz-sysc.c b/drivers/soc/renesas/rz-sysc.c
index b9880085d3634065..73eaf8b9d69f7208 100644
--- a/drivers/soc/renesas/rz-sysc.c
+++ b/drivers/soc/renesas/rz-sysc.c
@@ -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
--
2.43.0
^ permalink raw reply related [flat|nested] 38+ messages in thread
* [PATCH v5 20/23] ALSA: usb-audio: Convert to common field_{get,prep}() helpers
2025-10-27 18:41 [PATCH v5 00/23] Non-const bitfield helpers Geert Uytterhoeven
` (18 preceding siblings ...)
2025-10-27 18:41 ` [PATCH v5 19/23] soc: renesas: rz-sysc: Convert to common field_get() helper Geert Uytterhoeven
@ 2025-10-27 18:41 ` Geert Uytterhoeven
2025-10-28 16:13 ` Takashi Iwai
2025-10-27 18:41 ` [PATCH -next v5 21/23] iio: imu: smi330: " Geert Uytterhoeven
` (2 subsequent siblings)
22 siblings, 1 reply; 38+ messages in thread
From: Geert Uytterhoeven @ 2025-10-27 18:41 UTC (permalink / raw)
To: Michael Turquette, Stephen Boyd, Nicolas Ferre, Alexandre Belloni,
Claudiu Beznea, Giovanni Cabiddu, Herbert Xu, David Miller,
Linus Walleij, Bartosz Golaszewski, Joel Stanley, Andrew Jeffery,
Crt Mori, Jonathan Cameron, Lars-Peter Clausen, Jacky Huang,
Shan-Chun Hung, Yury Norov, Rasmus Villemoes, Jaroslav Kysela,
Takashi Iwai, Johannes Berg, Jakub Kicinski, Alex Elder,
David Laight, Vincent Mailhol, Jason Baron, Borislav Petkov,
Tony Luck, Michael Hennerich, Kim Seer Paller, David Lechner,
Nuno Sá, Andy Shevchenko, Richard Genoud, Cosmin Tanislav,
Biju Das, Jianping Shen
Cc: linux-clk, linux-arm-kernel, linux-renesas-soc, linux-crypto,
linux-edac, qat-linux, linux-gpio, linux-aspeed, linux-iio,
linux-sound, linux-kernel, Geert Uytterhoeven
Drop the driver-specific field_get() and field_prep() macros, in favor
of the globally available variants from <linux/bitfield.h>.
Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
---
v5:
- Extracted from "bitfield: Add non-constant field_{prep,get}()
helpers".
---
sound/usb/mixer_quirks.c | 6 ------
1 file changed, 6 deletions(-)
diff --git a/sound/usb/mixer_quirks.c b/sound/usb/mixer_quirks.c
index 713a8498b975e1ac..6eee89cbc0867f2b 100644
--- a/sound/usb/mixer_quirks.c
+++ b/sound/usb/mixer_quirks.c
@@ -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);
--
2.43.0
^ permalink raw reply related [flat|nested] 38+ messages in thread
* [PATCH -next v5 21/23] iio: imu: smi330: Convert to common field_{get,prep}() helpers
2025-10-27 18:41 [PATCH v5 00/23] Non-const bitfield helpers Geert Uytterhoeven
` (19 preceding siblings ...)
2025-10-27 18:41 ` [PATCH v5 20/23] ALSA: usb-audio: Convert to common field_{get,prep}() helpers Geert Uytterhoeven
@ 2025-10-27 18:41 ` Geert Uytterhoeven
2025-10-27 18:41 ` [PATCH v5 22/23] clk: renesas: Use bitfield helpers Geert Uytterhoeven
2025-10-27 18:41 ` [PATCH v5 23/23] soc: " Geert Uytterhoeven
22 siblings, 0 replies; 38+ messages in thread
From: Geert Uytterhoeven @ 2025-10-27 18:41 UTC (permalink / raw)
To: Michael Turquette, Stephen Boyd, Nicolas Ferre, Alexandre Belloni,
Claudiu Beznea, Giovanni Cabiddu, Herbert Xu, David Miller,
Linus Walleij, Bartosz Golaszewski, Joel Stanley, Andrew Jeffery,
Crt Mori, Jonathan Cameron, Lars-Peter Clausen, Jacky Huang,
Shan-Chun Hung, Yury Norov, Rasmus Villemoes, Jaroslav Kysela,
Takashi Iwai, Johannes Berg, Jakub Kicinski, Alex Elder,
David Laight, Vincent Mailhol, Jason Baron, Borislav Petkov,
Tony Luck, Michael Hennerich, Kim Seer Paller, David Lechner,
Nuno Sá, Andy Shevchenko, Richard Genoud, Cosmin Tanislav,
Biju Das, Jianping Shen
Cc: linux-clk, linux-arm-kernel, linux-renesas-soc, linux-crypto,
linux-edac, qat-linux, linux-gpio, linux-aspeed, linux-iio,
linux-sound, linux-kernel, Geert Uytterhoeven
Drop the driver-specific field_get() and field_prep() macros, in favor
of the globally available variants from <linux/bitfield.h>.
Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
---
v5:
- New.
---
drivers/iio/imu/smi330/smi330_core.c | 6 ------
1 file changed, 6 deletions(-)
diff --git a/drivers/iio/imu/smi330/smi330_core.c b/drivers/iio/imu/smi330/smi330_core.c
index a79964fe68fadf47..83e0dff5d973d046 100644
--- a/drivers/iio/imu/smi330/smi330_core.c
+++ b/drivers/iio/imu/smi330/smi330_core.c
@@ -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, \
--
2.43.0
^ permalink raw reply related [flat|nested] 38+ messages in thread
* [PATCH v5 22/23] clk: renesas: Use bitfield helpers
2025-10-27 18:41 [PATCH v5 00/23] Non-const bitfield helpers Geert Uytterhoeven
` (20 preceding siblings ...)
2025-10-27 18:41 ` [PATCH -next v5 21/23] iio: imu: smi330: " Geert Uytterhoeven
@ 2025-10-27 18:41 ` Geert Uytterhoeven
2025-10-27 18:41 ` [PATCH v5 23/23] soc: " Geert Uytterhoeven
22 siblings, 0 replies; 38+ messages in thread
From: Geert Uytterhoeven @ 2025-10-27 18:41 UTC (permalink / raw)
To: Michael Turquette, Stephen Boyd, Nicolas Ferre, Alexandre Belloni,
Claudiu Beznea, Giovanni Cabiddu, Herbert Xu, David Miller,
Linus Walleij, Bartosz Golaszewski, Joel Stanley, Andrew Jeffery,
Crt Mori, Jonathan Cameron, Lars-Peter Clausen, Jacky Huang,
Shan-Chun Hung, Yury Norov, Rasmus Villemoes, Jaroslav Kysela,
Takashi Iwai, Johannes Berg, Jakub Kicinski, Alex Elder,
David Laight, Vincent Mailhol, Jason Baron, Borislav Petkov,
Tony Luck, Michael Hennerich, Kim Seer Paller, David Lechner,
Nuno Sá, Andy Shevchenko, Richard Genoud, Cosmin Tanislav,
Biju Das, Jianping Shen
Cc: linux-clk, linux-arm-kernel, linux-renesas-soc, linux-crypto,
linux-edac, qat-linux, linux-gpio, linux-aspeed, linux-iio,
linux-sound, linux-kernel, Geert Uytterhoeven
Use the FIELD_{GET,PREP}() and field_{get,prep}() helpers for const
respective non-const bitfields, instead of open-coding the same
operations.
Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
---
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(-)
diff --git a/drivers/clk/renesas/clk-div6.c b/drivers/clk/renesas/clk-div6.c
index 3abd6e5400aded6a..f7b827b5e9b2dd32 100644
--- a/drivers/clk/renesas/clk-div6.c
+++ b/drivers/clk/renesas/clk-div6.c
@@ -7,6 +7,7 @@
* Contact: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
*/
+#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;
}
diff --git a/drivers/clk/renesas/rcar-gen3-cpg.c b/drivers/clk/renesas/rcar-gen3-cpg.c
index 10ae20489df9abd8..b954278ddd9d8aa8 100644
--- a/drivers/clk/renesas/rcar-gen3-cpg.c
+++ b/drivers/clk/renesas/rcar-gen3-cpg.c
@@ -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
diff --git a/drivers/clk/renesas/rcar-gen4-cpg.c b/drivers/clk/renesas/rcar-gen4-cpg.c
index fb9a876aaba5cbcd..db3a0b8ef2b936bb 100644
--- a/drivers/clk/renesas/rcar-gen4-cpg.c
+++ b/drivers/clk/renesas/rcar-gen4-cpg.c
@@ -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
--
2.43.0
^ permalink raw reply related [flat|nested] 38+ messages in thread
* [PATCH v5 23/23] soc: renesas: Use bitfield helpers
2025-10-27 18:41 [PATCH v5 00/23] Non-const bitfield helpers Geert Uytterhoeven
` (21 preceding siblings ...)
2025-10-27 18:41 ` [PATCH v5 22/23] clk: renesas: Use bitfield helpers Geert Uytterhoeven
@ 2025-10-27 18:41 ` Geert Uytterhoeven
22 siblings, 0 replies; 38+ messages in thread
From: Geert Uytterhoeven @ 2025-10-27 18:41 UTC (permalink / raw)
To: Michael Turquette, Stephen Boyd, Nicolas Ferre, Alexandre Belloni,
Claudiu Beznea, Giovanni Cabiddu, Herbert Xu, David Miller,
Linus Walleij, Bartosz Golaszewski, Joel Stanley, Andrew Jeffery,
Crt Mori, Jonathan Cameron, Lars-Peter Clausen, Jacky Huang,
Shan-Chun Hung, Yury Norov, Rasmus Villemoes, Jaroslav Kysela,
Takashi Iwai, Johannes Berg, Jakub Kicinski, Alex Elder,
David Laight, Vincent Mailhol, Jason Baron, Borislav Petkov,
Tony Luck, Michael Hennerich, Kim Seer Paller, David Lechner,
Nuno Sá, Andy Shevchenko, Richard Genoud, Cosmin Tanislav,
Biju Das, Jianping Shen
Cc: linux-clk, linux-arm-kernel, linux-renesas-soc, linux-crypto,
linux-edac, qat-linux, linux-gpio, linux-aspeed, linux-iio,
linux-sound, linux-kernel, Geert Uytterhoeven
Use the field_get() helper, instead of open-coding the same operation.
Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
---
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(-)
diff --git a/drivers/soc/renesas/renesas-soc.c b/drivers/soc/renesas/renesas-soc.c
index 1eb52356b996bdd7..ee4f17bb4db45db7 100644
--- a/drivers/soc/renesas/renesas-soc.c
+++ b/drivers/soc/renesas/renesas-soc.c
@@ -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;
--
2.43.0
^ permalink raw reply related [flat|nested] 38+ messages in thread
* Re: [PATCH v5 01/23] clk: at91: pmc: #undef field_{get,prep}() before definition
2025-10-27 18:41 ` [PATCH v5 01/23] clk: at91: pmc: #undef field_{get,prep}() before definition Geert Uytterhoeven
@ 2025-10-27 20:36 ` Alexandre Belloni
0 siblings, 0 replies; 38+ messages in thread
From: Alexandre Belloni @ 2025-10-27 20:36 UTC (permalink / raw)
To: Geert Uytterhoeven
Cc: Michael Turquette, Stephen Boyd, Nicolas Ferre, Claudiu Beznea,
Giovanni Cabiddu, Herbert Xu, David Miller, Linus Walleij,
Bartosz Golaszewski, Joel Stanley, Andrew Jeffery, Crt Mori,
Jonathan Cameron, Lars-Peter Clausen, Jacky Huang, Shan-Chun Hung,
Yury Norov, Rasmus Villemoes, Jaroslav Kysela, Takashi Iwai,
Johannes Berg, Jakub Kicinski, Alex Elder, David Laight,
Vincent Mailhol, Jason Baron, Borislav Petkov, Tony Luck,
Michael Hennerich, Kim Seer Paller, David Lechner, Nuno Sá,
Andy Shevchenko, Richard Genoud, Cosmin Tanislav, Biju Das,
Jianping Shen, linux-clk, linux-arm-kernel, linux-renesas-soc,
linux-crypto, linux-edac, qat-linux, linux-gpio, linux-aspeed,
linux-iio, linux-sound, linux-kernel
On 27/10/2025 19:41:35+0100, Geert Uytterhoeven wrote:
> 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.
>
> Suggested-by: Yury Norov <yury.norov@gmail.com>
> Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
Acked-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
> --
> v5:
> - New.
> ---
> drivers/clk/at91/pmc.h | 2 ++
> 1 file changed, 2 insertions(+)
>
> diff --git a/drivers/clk/at91/pmc.h b/drivers/clk/at91/pmc.h
> index 5daa32c4cf2540d7..78a87d31463e98b0 100644
> --- a/drivers/clk/at91/pmc.h
> +++ b/drivers/clk/at91/pmc.h
> @@ -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)
> --
> 2.43.0
>
--
Alexandre Belloni, co-owner and COO, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
^ permalink raw reply [flat|nested] 38+ messages in thread
* Re: [PATCH v5 11/23] bitfield: Add non-constant field_{prep,get}() helpers
2025-10-27 18:41 ` [PATCH v5 11/23] bitfield: Add non-constant field_{prep,get}() helpers Geert Uytterhoeven
@ 2025-10-28 9:15 ` Andy Shevchenko
0 siblings, 0 replies; 38+ messages in thread
From: Andy Shevchenko @ 2025-10-28 9:15 UTC (permalink / raw)
To: Geert Uytterhoeven
Cc: Michael Turquette, Stephen Boyd, Nicolas Ferre, Alexandre Belloni,
Claudiu Beznea, Giovanni Cabiddu, Herbert Xu, David Miller,
Linus Walleij, Bartosz Golaszewski, Joel Stanley, Andrew Jeffery,
Crt Mori, Jonathan Cameron, Lars-Peter Clausen, Jacky Huang,
Shan-Chun Hung, Yury Norov, Rasmus Villemoes, Jaroslav Kysela,
Takashi Iwai, Johannes Berg, Jakub Kicinski, Alex Elder,
David Laight, Vincent Mailhol, Jason Baron, Borislav Petkov,
Tony Luck, Michael Hennerich, Kim Seer Paller, David Lechner,
Nuno Sá, Andy Shevchenko, Richard Genoud, Cosmin Tanislav,
Biju Das, Jianping Shen, linux-clk, linux-arm-kernel,
linux-renesas-soc, linux-crypto, linux-edac, qat-linux,
linux-gpio, linux-aspeed, linux-iio, linux-sound, linux-kernel,
Jonathan Cameron
On Mon, Oct 27, 2025 at 07:41:45PM +0100, Geert Uytterhoeven wrote:
> 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.
>
> 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,
Reviewed-by: Andy Shevchenko <andriy.shevchenko@intel.com>
after addressing them.
...
> +#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 \
> + })
> +
> +#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.
> + })
> +/**
> + * 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.
Shouldn't it have Return section as well?
> + */
> +#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).
> +
> +/**
> + * 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.
Ditto.
> + */
> +#define field_get(mask, reg) \
> + (__builtin_constant_p(mask) ? FIELD_GET(mask, reg) \
> + : __field_get(mask, reg))
As per above.
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 38+ messages in thread
* Re: [PATCH v5 04/23] gpio: aspeed: #undef field_{get,prep}() before local definition
2025-10-27 18:41 ` [PATCH v5 04/23] gpio: aspeed: #undef field_{get,prep}() " Geert Uytterhoeven
@ 2025-10-28 14:20 ` Bartosz Golaszewski
0 siblings, 0 replies; 38+ messages in thread
From: Bartosz Golaszewski @ 2025-10-28 14:20 UTC (permalink / raw)
To: Geert Uytterhoeven
Cc: Michael Turquette, Stephen Boyd, Nicolas Ferre, Alexandre Belloni,
Claudiu Beznea, Giovanni Cabiddu, Herbert Xu, David Miller,
Linus Walleij, Joel Stanley, Andrew Jeffery, Crt Mori,
Jonathan Cameron, Lars-Peter Clausen, Jacky Huang, Shan-Chun Hung,
Yury Norov, Rasmus Villemoes, Jaroslav Kysela, Takashi Iwai,
Johannes Berg, Jakub Kicinski, Alex Elder, David Laight,
Vincent Mailhol, Jason Baron, Borislav Petkov, Tony Luck,
Michael Hennerich, Kim Seer Paller, David Lechner, Nuno Sá,
Andy Shevchenko, Richard Genoud, Cosmin Tanislav, Biju Das,
Jianping Shen, linux-clk, linux-arm-kernel, linux-renesas-soc,
linux-crypto, linux-edac, qat-linux, linux-gpio, linux-aspeed,
linux-iio, linux-sound, linux-kernel
On Mon, Oct 27, 2025 at 7:42 PM Geert Uytterhoeven
<geert+renesas@glider.be> wrote:
>
> 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.
>
> Suggested-by: Yury Norov <yury.norov@gmail.com>
> Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
> --
> v5:
> - New.
> ---
> drivers/gpio/gpio-aspeed.c | 2 ++
> 1 file changed, 2 insertions(+)
>
> diff --git a/drivers/gpio/gpio-aspeed.c b/drivers/gpio/gpio-aspeed.c
> index 7953a9c4e36d7550..ef4ccaf74a5b379e 100644
> --- a/drivers/gpio/gpio-aspeed.c
> +++ b/drivers/gpio/gpio-aspeed.c
> @@ -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
> --
> 2.43.0
>
Acked-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
^ permalink raw reply [flat|nested] 38+ messages in thread
* Re: [PATCH v5 09/23] ALSA: usb-audio: #undef field_{get,prep}() before local definition
2025-10-27 18:41 ` [PATCH v5 09/23] ALSA: usb-audio: #undef field_{get,prep}() " Geert Uytterhoeven
@ 2025-10-28 16:13 ` Takashi Iwai
0 siblings, 0 replies; 38+ messages in thread
From: Takashi Iwai @ 2025-10-28 16:13 UTC (permalink / raw)
To: Geert Uytterhoeven
Cc: Michael Turquette, Stephen Boyd, Nicolas Ferre, Alexandre Belloni,
Claudiu Beznea, Giovanni Cabiddu, Herbert Xu, David Miller,
Linus Walleij, Bartosz Golaszewski, Joel Stanley, Andrew Jeffery,
Crt Mori, Jonathan Cameron, Lars-Peter Clausen, Jacky Huang,
Shan-Chun Hung, Yury Norov, Rasmus Villemoes, Jaroslav Kysela,
Takashi Iwai, Johannes Berg, Jakub Kicinski, Alex Elder,
David Laight, Vincent Mailhol, Jason Baron, Borislav Petkov,
Tony Luck, Michael Hennerich, Kim Seer Paller, David Lechner,
Nuno Sá, Andy Shevchenko, Richard Genoud, Cosmin Tanislav,
Biju Das, Jianping Shen, linux-clk, linux-arm-kernel,
linux-renesas-soc, linux-crypto, linux-edac, qat-linux,
linux-gpio, linux-aspeed, linux-iio, linux-sound, linux-kernel
On Mon, 27 Oct 2025 19:41:43 +0100,
Geert Uytterhoeven wrote:
>
> 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.
>
> Suggested-by: Yury Norov <yury.norov@gmail.com>
> Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
> --
> v5:
> - New.
> ---
> sound/usb/mixer_quirks.c | 2 ++
> 1 file changed, 2 insertions(+)
>
> diff --git a/sound/usb/mixer_quirks.c b/sound/usb/mixer_quirks.c
> index 828af3095b86ee0a..713a8498b975e1ac 100644
> --- a/sound/usb/mixer_quirks.c
> +++ b/sound/usb/mixer_quirks.c
> @@ -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)
Acked-by: Takashi Iwai <tiwai@suse.de>
thanks,
Takashi
^ permalink raw reply [flat|nested] 38+ messages in thread
* Re: [PATCH v5 20/23] ALSA: usb-audio: Convert to common field_{get,prep}() helpers
2025-10-27 18:41 ` [PATCH v5 20/23] ALSA: usb-audio: Convert to common field_{get,prep}() helpers Geert Uytterhoeven
@ 2025-10-28 16:13 ` Takashi Iwai
0 siblings, 0 replies; 38+ messages in thread
From: Takashi Iwai @ 2025-10-28 16:13 UTC (permalink / raw)
To: Geert Uytterhoeven
Cc: Michael Turquette, Stephen Boyd, Nicolas Ferre, Alexandre Belloni,
Claudiu Beznea, Giovanni Cabiddu, Herbert Xu, David Miller,
Linus Walleij, Bartosz Golaszewski, Joel Stanley, Andrew Jeffery,
Crt Mori, Jonathan Cameron, Lars-Peter Clausen, Jacky Huang,
Shan-Chun Hung, Yury Norov, Rasmus Villemoes, Jaroslav Kysela,
Takashi Iwai, Johannes Berg, Jakub Kicinski, Alex Elder,
David Laight, Vincent Mailhol, Jason Baron, Borislav Petkov,
Tony Luck, Michael Hennerich, Kim Seer Paller, David Lechner,
Nuno Sá, Andy Shevchenko, Richard Genoud, Cosmin Tanislav,
Biju Das, Jianping Shen, linux-clk, linux-arm-kernel,
linux-renesas-soc, linux-crypto, linux-edac, qat-linux,
linux-gpio, linux-aspeed, linux-iio, linux-sound, linux-kernel
On Mon, 27 Oct 2025 19:41:54 +0100,
Geert Uytterhoeven wrote:
>
> Drop the driver-specific field_get() and field_prep() macros, in favor
> of the globally available variants from <linux/bitfield.h>.
>
> Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
> ---
> v5:
> - Extracted from "bitfield: Add non-constant field_{prep,get}()
> helpers".
> ---
> sound/usb/mixer_quirks.c | 6 ------
> 1 file changed, 6 deletions(-)
>
> diff --git a/sound/usb/mixer_quirks.c b/sound/usb/mixer_quirks.c
> index 713a8498b975e1ac..6eee89cbc0867f2b 100644
> --- a/sound/usb/mixer_quirks.c
> +++ b/sound/usb/mixer_quirks.c
> @@ -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);
Acked-by: Takashi Iwai <tiwai@suse.de>
thanks,
Takashi
^ permalink raw reply [flat|nested] 38+ messages in thread
* Re: [PATCH v5 07/23] pinctrl: ma35: #undef field_{get,prep}() before local definition
2025-10-27 18:41 ` [PATCH v5 07/23] pinctrl: ma35: " Geert Uytterhoeven
@ 2025-10-29 14:19 ` Linus Walleij
2025-10-29 14:30 ` Geert Uytterhoeven
2025-10-29 14:30 ` Yury Norov
0 siblings, 2 replies; 38+ messages in thread
From: Linus Walleij @ 2025-10-29 14:19 UTC (permalink / raw)
To: Geert Uytterhoeven
Cc: Michael Turquette, Stephen Boyd, Nicolas Ferre, Alexandre Belloni,
Claudiu Beznea, Giovanni Cabiddu, Herbert Xu, David Miller,
Bartosz Golaszewski, Joel Stanley, Andrew Jeffery, Crt Mori,
Jonathan Cameron, Lars-Peter Clausen, Jacky Huang, Shan-Chun Hung,
Yury Norov, Rasmus Villemoes, Jaroslav Kysela, Takashi Iwai,
Johannes Berg, Jakub Kicinski, Alex Elder, David Laight,
Vincent Mailhol, Jason Baron, Borislav Petkov, Tony Luck,
Michael Hennerich, Kim Seer Paller, David Lechner, Nuno Sá,
Andy Shevchenko, Richard Genoud, Cosmin Tanislav, Biju Das,
Jianping Shen, linux-clk, linux-arm-kernel, linux-renesas-soc,
linux-crypto, linux-edac, qat-linux, linux-gpio, linux-aspeed,
linux-iio, linux-sound, linux-kernel
Hi Geert,
thanks for your patch!
On Mon, Oct 27, 2025 at 7:43 PM Geert Uytterhoeven
<geert+renesas@glider.be> wrote:
> 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.
>
> Suggested-by: Yury Norov <yury.norov@gmail.com>
> Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
Do you want me to just merge this patch to the pinctrl tree or do
you have other plans?
Yours,
Linus Walleij
^ permalink raw reply [flat|nested] 38+ messages in thread
* Re: [PATCH v5 18/23] pinctrl: ma35: Convert to common field_{get,prep}() helpers
2025-10-27 18:41 ` [PATCH v5 18/23] pinctrl: ma35: " Geert Uytterhoeven
@ 2025-10-29 14:21 ` Linus Walleij
2025-10-29 14:34 ` Geert Uytterhoeven
0 siblings, 1 reply; 38+ messages in thread
From: Linus Walleij @ 2025-10-29 14:21 UTC (permalink / raw)
To: Geert Uytterhoeven
Cc: Michael Turquette, Stephen Boyd, Nicolas Ferre, Alexandre Belloni,
Claudiu Beznea, Giovanni Cabiddu, Herbert Xu, David Miller,
Bartosz Golaszewski, Joel Stanley, Andrew Jeffery, Crt Mori,
Jonathan Cameron, Lars-Peter Clausen, Jacky Huang, Shan-Chun Hung,
Yury Norov, Rasmus Villemoes, Jaroslav Kysela, Takashi Iwai,
Johannes Berg, Jakub Kicinski, Alex Elder, David Laight,
Vincent Mailhol, Jason Baron, Borislav Petkov, Tony Luck,
Michael Hennerich, Kim Seer Paller, David Lechner, Nuno Sá,
Andy Shevchenko, Richard Genoud, Cosmin Tanislav, Biju Das,
Jianping Shen, linux-clk, linux-arm-kernel, linux-renesas-soc,
linux-crypto, linux-edac, qat-linux, linux-gpio, linux-aspeed,
linux-iio, linux-sound, linux-kernel
On Mon, Oct 27, 2025 at 7:44 PM Geert Uytterhoeven
<geert+renesas@glider.be> wrote:
> Drop the driver-specific field_get() and field_prep() macros, in favor
> of the globally available variants from <linux/bitfield.h>.
>
> Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
> ---
> v5:
> - Extracted from "bitfield: Add non-constant field_{prep,get}()
> helpers".
Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
I guess this needs to go with the rest of the patches?
Yours,
Linus Walleij
^ permalink raw reply [flat|nested] 38+ messages in thread
* Re: [PATCH v5 07/23] pinctrl: ma35: #undef field_{get,prep}() before local definition
2025-10-29 14:19 ` Linus Walleij
@ 2025-10-29 14:30 ` Geert Uytterhoeven
2025-10-29 14:30 ` Yury Norov
1 sibling, 0 replies; 38+ messages in thread
From: Geert Uytterhoeven @ 2025-10-29 14:30 UTC (permalink / raw)
To: Linus Walleij
Cc: Michael Turquette, Stephen Boyd, Nicolas Ferre, Alexandre Belloni,
Claudiu Beznea, Giovanni Cabiddu, Herbert Xu, David Miller,
Bartosz Golaszewski, Joel Stanley, Andrew Jeffery, Crt Mori,
Jonathan Cameron, Lars-Peter Clausen, Jacky Huang, Shan-Chun Hung,
Yury Norov, Rasmus Villemoes, Jaroslav Kysela, Takashi Iwai,
Johannes Berg, Jakub Kicinski, Alex Elder, David Laight,
Vincent Mailhol, Jason Baron, Borislav Petkov, Tony Luck,
Michael Hennerich, Kim Seer Paller, David Lechner, Nuno Sá,
Andy Shevchenko, Richard Genoud, Cosmin Tanislav, Biju Das,
Jianping Shen, linux-clk, linux-arm-kernel, linux-renesas-soc,
linux-crypto, linux-edac, qat-linux, linux-gpio, linux-aspeed,
linux-iio, linux-sound, linux-kernel
Hi Linus,
On Wed, 29 Oct 2025 at 15:20, Linus Walleij <linus.walleij@linaro.org> wrote:
> On Mon, Oct 27, 2025 at 7:43 PM Geert Uytterhoeven
> <geert+renesas@glider.be> wrote:
>
> > 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.
> >
> > Suggested-by: Yury Norov <yury.norov@gmail.com>
> > Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
>
> 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
--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org
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
^ permalink raw reply [flat|nested] 38+ messages in thread
* Re: [PATCH v5 07/23] pinctrl: ma35: #undef field_{get,prep}() before local definition
2025-10-29 14:19 ` Linus Walleij
2025-10-29 14:30 ` Geert Uytterhoeven
@ 2025-10-29 14:30 ` Yury Norov
2025-10-29 14:33 ` Geert Uytterhoeven
1 sibling, 1 reply; 38+ messages in thread
From: Yury Norov @ 2025-10-29 14:30 UTC (permalink / raw)
To: Linus Walleij
Cc: Geert Uytterhoeven, Michael Turquette, Stephen Boyd,
Nicolas Ferre, Alexandre Belloni, Claudiu Beznea,
Giovanni Cabiddu, Herbert Xu, David Miller, Bartosz Golaszewski,
Joel Stanley, Andrew Jeffery, Crt Mori, Jonathan Cameron,
Lars-Peter Clausen, Jacky Huang, Shan-Chun Hung, Rasmus Villemoes,
Jaroslav Kysela, Takashi Iwai, Johannes Berg, Jakub Kicinski,
Alex Elder, David Laight, Vincent Mailhol, Jason Baron,
Borislav Petkov, Tony Luck, Michael Hennerich, Kim Seer Paller,
David Lechner, Nuno Sá, Andy Shevchenko, Richard Genoud,
Cosmin Tanislav, Biju Das, Jianping Shen, linux-clk,
linux-arm-kernel, linux-renesas-soc, linux-crypto, linux-edac,
qat-linux, linux-gpio, linux-aspeed, linux-iio, linux-sound,
linux-kernel
On Wed, Oct 29, 2025 at 03:19:45PM +0100, Linus Walleij wrote:
> Hi Geert,
>
> thanks for your patch!
>
> On Mon, Oct 27, 2025 at 7:43 PM Geert Uytterhoeven
> <geert+renesas@glider.be> wrote:
>
> > 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.
> >
> > Suggested-by: Yury Norov <yury.norov@gmail.com>
> > Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
>
> 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
^ permalink raw reply [flat|nested] 38+ messages in thread
* Re: [PATCH v5 07/23] pinctrl: ma35: #undef field_{get,prep}() before local definition
2025-10-29 14:30 ` Yury Norov
@ 2025-10-29 14:33 ` Geert Uytterhoeven
2025-10-29 14:43 ` Yury Norov
0 siblings, 1 reply; 38+ messages in thread
From: Geert Uytterhoeven @ 2025-10-29 14:33 UTC (permalink / raw)
To: Yury Norov
Cc: Linus Walleij, Michael Turquette, Stephen Boyd, Nicolas Ferre,
Alexandre Belloni, Claudiu Beznea, Giovanni Cabiddu, Herbert Xu,
David Miller, Bartosz Golaszewski, Joel Stanley, Andrew Jeffery,
Crt Mori, Jonathan Cameron, Lars-Peter Clausen, Jacky Huang,
Shan-Chun Hung, Rasmus Villemoes, Jaroslav Kysela, Takashi Iwai,
Johannes Berg, Jakub Kicinski, Alex Elder, David Laight,
Vincent Mailhol, Jason Baron, Borislav Petkov, Tony Luck,
Michael Hennerich, Kim Seer Paller, David Lechner, Nuno Sá,
Andy Shevchenko, Richard Genoud, Cosmin Tanislav, Biju Das,
Jianping Shen, linux-clk, linux-arm-kernel, linux-renesas-soc,
linux-crypto, linux-edac, qat-linux, linux-gpio, linux-aspeed,
linux-iio, linux-sound, linux-kernel
Hi Yury,
On Wed, 29 Oct 2025 at 15:30, Yury Norov <yury.norov@gmail.com> wrote:
> On Wed, Oct 29, 2025 at 03:19:45PM +0100, Linus Walleij wrote:
> > On Mon, Oct 27, 2025 at 7:43 PM Geert Uytterhoeven
> > <geert+renesas@glider.be> wrote:
> > > 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.
> > >
> > > Suggested-by: Yury Norov <yury.norov@gmail.com>
> > > Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
> >
> > 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....
> 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
--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org
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
^ permalink raw reply [flat|nested] 38+ messages in thread
* Re: [PATCH v5 18/23] pinctrl: ma35: Convert to common field_{get,prep}() helpers
2025-10-29 14:21 ` Linus Walleij
@ 2025-10-29 14:34 ` Geert Uytterhoeven
0 siblings, 0 replies; 38+ messages in thread
From: Geert Uytterhoeven @ 2025-10-29 14:34 UTC (permalink / raw)
To: Linus Walleij
Cc: Michael Turquette, Stephen Boyd, Nicolas Ferre, Alexandre Belloni,
Claudiu Beznea, Giovanni Cabiddu, Herbert Xu, David Miller,
Bartosz Golaszewski, Joel Stanley, Andrew Jeffery, Crt Mori,
Jonathan Cameron, Lars-Peter Clausen, Jacky Huang, Shan-Chun Hung,
Yury Norov, Rasmus Villemoes, Jaroslav Kysela, Takashi Iwai,
Johannes Berg, Jakub Kicinski, Alex Elder, David Laight,
Vincent Mailhol, Jason Baron, Borislav Petkov, Tony Luck,
Michael Hennerich, Kim Seer Paller, David Lechner, Nuno Sá,
Andy Shevchenko, Richard Genoud, Cosmin Tanislav, Biju Das,
Jianping Shen, linux-clk, linux-arm-kernel, linux-renesas-soc,
linux-crypto, linux-edac, qat-linux, linux-gpio, linux-aspeed,
linux-iio, linux-sound, linux-kernel
Hi Linus,
On Wed, 29 Oct 2025 at 15:21, Linus Walleij <linus.walleij@linaro.org> wrote:
> On Mon, Oct 27, 2025 at 7:44 PM Geert Uytterhoeven
> <geert+renesas@glider.be> wrote:
>
> > Drop the driver-specific field_get() and field_prep() macros, in favor
> > of the globally available variants from <linux/bitfield.h>.
> >
> > Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
> > ---
> > v5:
> > - Extracted from "bitfield: Add non-constant field_{prep,get}()
> > helpers".
>
> Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
Thanks!
> 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 -- geert@linux-m68k.org
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
^ permalink raw reply [flat|nested] 38+ messages in thread
* Re: [PATCH v5 07/23] pinctrl: ma35: #undef field_{get,prep}() before local definition
2025-10-29 14:33 ` Geert Uytterhoeven
@ 2025-10-29 14:43 ` Yury Norov
0 siblings, 0 replies; 38+ messages in thread
From: Yury Norov @ 2025-10-29 14:43 UTC (permalink / raw)
To: Geert Uytterhoeven
Cc: Linus Walleij, Michael Turquette, Stephen Boyd, Nicolas Ferre,
Alexandre Belloni, Claudiu Beznea, Giovanni Cabiddu, Herbert Xu,
David Miller, Bartosz Golaszewski, Joel Stanley, Andrew Jeffery,
Crt Mori, Jonathan Cameron, Lars-Peter Clausen, Jacky Huang,
Shan-Chun Hung, Rasmus Villemoes, Jaroslav Kysela, Takashi Iwai,
Johannes Berg, Jakub Kicinski, Alex Elder, David Laight,
Vincent Mailhol, Jason Baron, Borislav Petkov, Tony Luck,
Michael Hennerich, Kim Seer Paller, David Lechner, Nuno Sá,
Andy Shevchenko, Richard Genoud, Cosmin Tanislav, Biju Das,
Jianping Shen, linux-clk, linux-arm-kernel, linux-renesas-soc,
linux-crypto, linux-edac, qat-linux, linux-gpio, linux-aspeed,
linux-iio, linux-sound, linux-kernel
On Wed, Oct 29, 2025 at 03:33:49PM +0100, Geert Uytterhoeven wrote:
> Hi Yury,
>
> On Wed, 29 Oct 2025 at 15:30, Yury Norov <yury.norov@gmail.com> wrote:
> > On Wed, Oct 29, 2025 at 03:19:45PM +0100, Linus Walleij wrote:
> > > On Mon, Oct 27, 2025 at 7:43 PM Geert Uytterhoeven
> > > <geert+renesas@glider.be> wrote:
> > > > 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.
> > > >
> > > > Suggested-by: Yury Norov <yury.norov@gmail.com>
> > > > Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
> > >
> > > 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....
>
> > 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
Oh, OK. Didn't actually want to undercut you. :) So, at your
discretion. Just let me know what you'd prefer.
Thanks,
Yury
^ permalink raw reply [flat|nested] 38+ messages in thread
* Re: [PATCH v5 02/23] crypto: qat - #undef field_get() before local definition
2025-10-27 18:41 ` [PATCH v5 02/23] crypto: qat - #undef field_get() before local definition Geert Uytterhoeven
@ 2025-10-30 10:30 ` Giovanni Cabiddu
0 siblings, 0 replies; 38+ messages in thread
From: Giovanni Cabiddu @ 2025-10-30 10:30 UTC (permalink / raw)
To: Geert Uytterhoeven
Cc: Michael Turquette, Stephen Boyd, Nicolas Ferre, Alexandre Belloni,
Claudiu Beznea, Herbert Xu, David Miller, Linus Walleij,
Bartosz Golaszewski, Joel Stanley, Andrew Jeffery, Crt Mori,
Jonathan Cameron, Lars-Peter Clausen, Jacky Huang, Shan-Chun Hung,
Yury Norov, Rasmus Villemoes, Jaroslav Kysela, Takashi Iwai,
Johannes Berg, Jakub Kicinski, Alex Elder, David Laight,
Vincent Mailhol, Jason Baron, Borislav Petkov, Tony Luck,
Michael Hennerich, Kim Seer Paller, David Lechner, Nuno Sá,
Andy Shevchenko, Richard Genoud, Cosmin Tanislav, Biju Das,
Jianping Shen, linux-clk, linux-arm-kernel, linux-renesas-soc,
linux-crypto, linux-edac, qat-linux, linux-gpio, linux-aspeed,
linux-iio, linux-sound, linux-kernel
On Mon, Oct 27, 2025 at 07:41:36PM +0100, Geert Uytterhoeven wrote:
> 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 <yury.norov@gmail.com>
> Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
Acked-by: Giovanni Cabiddu <giovanni.cabiddu@intel.com>
> --
> v5:
> - New.
> ---
> drivers/crypto/intel/qat/qat_common/adf_pm_dbgfs_utils.c | 1 +
> 1 file changed, 1 insertion(+)
>
> diff --git a/drivers/crypto/intel/qat/qat_common/adf_pm_dbgfs_utils.c b/drivers/crypto/intel/qat/qat_common/adf_pm_dbgfs_utils.c
> index 69295a9ddf0ac92f..6186fafb4a7b0dab 100644
> --- a/drivers/crypto/intel/qat/qat_common/adf_pm_dbgfs_utils.c
> +++ b/drivers/crypto/intel/qat/qat_common/adf_pm_dbgfs_utils.c
> @@ -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
> --
> 2.43.0
>
^ permalink raw reply [flat|nested] 38+ messages in thread
* Re: [PATCH v5 13/23] crypto: qat - convert to common field_get() helper
2025-10-27 18:41 ` [PATCH v5 13/23] crypto: qat - convert to common field_get() helper Geert Uytterhoeven
@ 2025-10-30 10:31 ` Giovanni Cabiddu
0 siblings, 0 replies; 38+ messages in thread
From: Giovanni Cabiddu @ 2025-10-30 10:31 UTC (permalink / raw)
To: Geert Uytterhoeven
Cc: Michael Turquette, Stephen Boyd, Nicolas Ferre, Alexandre Belloni,
Claudiu Beznea, Herbert Xu, David Miller, Linus Walleij,
Bartosz Golaszewski, Joel Stanley, Andrew Jeffery, Crt Mori,
Jonathan Cameron, Lars-Peter Clausen, Jacky Huang, Shan-Chun Hung,
Yury Norov, Rasmus Villemoes, Jaroslav Kysela, Takashi Iwai,
Johannes Berg, Jakub Kicinski, Alex Elder, David Laight,
Vincent Mailhol, Jason Baron, Borislav Petkov, Tony Luck,
Michael Hennerich, Kim Seer Paller, David Lechner, Nuno Sá,
Andy Shevchenko, Richard Genoud, Cosmin Tanislav, Biju Das,
Jianping Shen, linux-clk, linux-arm-kernel, linux-renesas-soc,
linux-crypto, linux-edac, qat-linux, linux-gpio, linux-aspeed,
linux-iio, linux-sound, linux-kernel
On Mon, Oct 27, 2025 at 07:41:47PM +0100, Geert Uytterhoeven wrote:
> Drop the driver-specific field_get() macro, in favor of the globally
> available variant from <linux/bitfield.h>.
>
> Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
Acked-by: Giovanni Cabiddu <giovanni.cabiddu@intel.com>
> ---
> 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(-)
>
> diff --git a/drivers/crypto/intel/qat/qat_common/adf_pm_dbgfs_utils.c b/drivers/crypto/intel/qat/qat_common/adf_pm_dbgfs_utils.c
> index 6186fafb4a7b0dab..4ccc94ed9493a64c 100644
> --- a/drivers/crypto/intel/qat/qat_common/adf_pm_dbgfs_utils.c
> +++ b/drivers/crypto/intel/qat/qat_common/adf_pm_dbgfs_utils.c
> @@ -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,
> --
> 2.43.0
>
^ permalink raw reply [flat|nested] 38+ messages in thread
end of thread, other threads:[~2025-10-30 10:31 UTC | newest]
Thread overview: 38+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-10-27 18:41 [PATCH v5 00/23] Non-const bitfield helpers Geert Uytterhoeven
2025-10-27 18:41 ` [PATCH v5 01/23] clk: at91: pmc: #undef field_{get,prep}() before definition Geert Uytterhoeven
2025-10-27 20:36 ` Alexandre Belloni
2025-10-27 18:41 ` [PATCH v5 02/23] crypto: qat - #undef field_get() before local definition Geert Uytterhoeven
2025-10-30 10:30 ` Giovanni Cabiddu
2025-10-27 18:41 ` [PATCH v5 03/23] EDAC/ie31200: " Geert Uytterhoeven
2025-10-27 18:41 ` [PATCH v5 04/23] gpio: aspeed: #undef field_{get,prep}() " Geert Uytterhoeven
2025-10-28 14:20 ` Bartosz Golaszewski
2025-10-27 18:41 ` [PATCH v5 05/23] iio: dac: ad3530r: #undef field_prep() " Geert Uytterhoeven
2025-10-27 18:41 ` [PATCH v5 06/23] iio: mlx90614: #undef field_{get,prep}() " Geert Uytterhoeven
2025-10-27 18:41 ` [PATCH v5 07/23] pinctrl: ma35: " Geert Uytterhoeven
2025-10-29 14:19 ` Linus Walleij
2025-10-29 14:30 ` Geert Uytterhoeven
2025-10-29 14:30 ` Yury Norov
2025-10-29 14:33 ` Geert Uytterhoeven
2025-10-29 14:43 ` Yury Norov
2025-10-27 18:41 ` [PATCH v5 08/23] soc: renesas: rz-sysc: #undef field_get() " Geert Uytterhoeven
2025-10-27 18:41 ` [PATCH v5 09/23] ALSA: usb-audio: #undef field_{get,prep}() " Geert Uytterhoeven
2025-10-28 16:13 ` Takashi Iwai
2025-10-27 18:41 ` [PATCH -next v5 10/23] iio: imu: smi330: #undef field_{get,prep}() before definition Geert Uytterhoeven
2025-10-27 18:41 ` [PATCH v5 11/23] bitfield: Add non-constant field_{prep,get}() helpers Geert Uytterhoeven
2025-10-28 9:15 ` Andy Shevchenko
2025-10-27 18:41 ` [PATCH v5 12/23] clk: at91: Convert to common field_{get,prep}() helpers Geert Uytterhoeven
2025-10-27 18:41 ` [PATCH v5 13/23] crypto: qat - convert to common field_get() helper Geert Uytterhoeven
2025-10-30 10:31 ` Giovanni Cabiddu
2025-10-27 18:41 ` [PATCH v5 14/23] EDAC/ie31200: Convert " Geert Uytterhoeven
2025-10-27 18:41 ` [PATCH v5 15/23] gpio: aspeed: Convert to common field_{get,prep}() helpers Geert Uytterhoeven
2025-10-27 18:41 ` [PATCH v5 16/23] iio: dac: Convert to common field_prep() helper Geert Uytterhoeven
2025-10-27 18:41 ` [PATCH v5 17/23] iio: mlx90614: Convert to common field_{get,prep}() helpers Geert Uytterhoeven
2025-10-27 18:41 ` [PATCH v5 18/23] pinctrl: ma35: " Geert Uytterhoeven
2025-10-29 14:21 ` Linus Walleij
2025-10-29 14:34 ` Geert Uytterhoeven
2025-10-27 18:41 ` [PATCH v5 19/23] soc: renesas: rz-sysc: Convert to common field_get() helper Geert Uytterhoeven
2025-10-27 18:41 ` [PATCH v5 20/23] ALSA: usb-audio: Convert to common field_{get,prep}() helpers Geert Uytterhoeven
2025-10-28 16:13 ` Takashi Iwai
2025-10-27 18:41 ` [PATCH -next v5 21/23] iio: imu: smi330: " Geert Uytterhoeven
2025-10-27 18:41 ` [PATCH v5 22/23] clk: renesas: Use bitfield helpers Geert Uytterhoeven
2025-10-27 18:41 ` [PATCH v5 23/23] soc: " Geert Uytterhoeven
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).