linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Geert Uytterhoeven <geert+renesas@glider.be>
To: "Michael Turquette" <mturquette@baylibre.com>,
	"Stephen Boyd" <sboyd@kernel.org>,
	"Nicolas Ferre" <nicolas.ferre@microchip.com>,
	"Alexandre Belloni" <alexandre.belloni@bootlin.com>,
	"Claudiu Beznea" <claudiu.beznea@tuxon.dev>,
	"Giovanni Cabiddu" <giovanni.cabiddu@intel.com>,
	"Herbert Xu" <herbert@gondor.apana.org.au>,
	"David Miller" <davem@davemloft.net>,
	"Linus Walleij" <linus.walleij@linaro.org>,
	"Bartosz Golaszewski" <brgl@bgdev.pl>,
	"Joel Stanley" <joel@jms.id.au>,
	"Andrew Jeffery" <andrew@codeconstruct.com.au>,
	"Crt Mori" <cmo@melexis.com>,
	"Jonathan Cameron" <jic23@kernel.org>,
	"Lars-Peter Clausen" <lars@metafoo.de>,
	"Jacky Huang" <ychuang3@nuvoton.com>,
	"Shan-Chun Hung" <schung@nuvoton.com>,
	"Yury Norov" <yury.norov@gmail.com>,
	"Rasmus Villemoes" <linux@rasmusvillemoes.dk>,
	"Jaroslav Kysela" <perex@perex.cz>,
	"Takashi Iwai" <tiwai@suse.com>,
	"Johannes Berg" <johannes@sipsolutions.net>,
	"Jakub Kicinski" <kuba@kernel.org>, "Alex Elder" <elder@ieee.org>,
	"David Laight" <david.laight.linux@gmail.com>,
	"Vincent Mailhol" <mailhol.vincent@wanadoo.fr>,
	"Jason Baron" <jbaron@akamai.com>,
	"Borislav Petkov" <bp@alien8.de>,
	"Tony Luck" <tony.luck@intel.com>,
	"Michael Hennerich" <Michael.Hennerich@analog.com>,
	"Kim Seer Paller" <kimseer.paller@analog.com>,
	"David Lechner" <dlechner@baylibre.com>,
	"Nuno Sá" <nuno.sa@analog.com>,
	"Andy Shevchenko" <andy@kernel.org>,
	"Richard Genoud" <richard.genoud@bootlin.com>,
	"Cosmin Tanislav" <demonsingur@gmail.com>,
	"Biju Das" <biju.das.jz@bp.renesas.com>,
	"Jianping Shen" <Jianping.Shen@de.bosch.com>
Cc: linux-clk@vger.kernel.org, linux-arm-kernel@lists.infradead.org,
	linux-renesas-soc@vger.kernel.org, linux-crypto@vger.kernel.org,
	linux-edac@vger.kernel.org, qat-linux@intel.com,
	linux-gpio@vger.kernel.org, linux-aspeed@lists.ozlabs.org,
	linux-iio@vger.kernel.org, linux-sound@vger.kernel.org,
	linux-kernel@vger.kernel.org,
	Geert Uytterhoeven <geert+renesas@glider.be>
Subject: [PATCH v5 00/23] Non-const bitfield helpers
Date: Mon, 27 Oct 2025 19:41:34 +0100	[thread overview]
Message-ID: <cover.1761588465.git.geert+renesas@glider.be> (raw)

	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

             reply	other threads:[~2025-10-27 18:42 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-10-27 18:41 Geert Uytterhoeven [this message]
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-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-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-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-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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=cover.1761588465.git.geert+renesas@glider.be \
    --to=geert+renesas@glider.be \
    --cc=Jianping.Shen@de.bosch.com \
    --cc=Michael.Hennerich@analog.com \
    --cc=alexandre.belloni@bootlin.com \
    --cc=andrew@codeconstruct.com.au \
    --cc=andy@kernel.org \
    --cc=biju.das.jz@bp.renesas.com \
    --cc=bp@alien8.de \
    --cc=brgl@bgdev.pl \
    --cc=claudiu.beznea@tuxon.dev \
    --cc=cmo@melexis.com \
    --cc=davem@davemloft.net \
    --cc=david.laight.linux@gmail.com \
    --cc=demonsingur@gmail.com \
    --cc=dlechner@baylibre.com \
    --cc=elder@ieee.org \
    --cc=giovanni.cabiddu@intel.com \
    --cc=herbert@gondor.apana.org.au \
    --cc=jbaron@akamai.com \
    --cc=jic23@kernel.org \
    --cc=joel@jms.id.au \
    --cc=johannes@sipsolutions.net \
    --cc=kimseer.paller@analog.com \
    --cc=kuba@kernel.org \
    --cc=lars@metafoo.de \
    --cc=linus.walleij@linaro.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-aspeed@lists.ozlabs.org \
    --cc=linux-clk@vger.kernel.org \
    --cc=linux-crypto@vger.kernel.org \
    --cc=linux-edac@vger.kernel.org \
    --cc=linux-gpio@vger.kernel.org \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-renesas-soc@vger.kernel.org \
    --cc=linux-sound@vger.kernel.org \
    --cc=linux@rasmusvillemoes.dk \
    --cc=mailhol.vincent@wanadoo.fr \
    --cc=mturquette@baylibre.com \
    --cc=nicolas.ferre@microchip.com \
    --cc=nuno.sa@analog.com \
    --cc=perex@perex.cz \
    --cc=qat-linux@intel.com \
    --cc=richard.genoud@bootlin.com \
    --cc=sboyd@kernel.org \
    --cc=schung@nuvoton.com \
    --cc=tiwai@suse.com \
    --cc=tony.luck@intel.com \
    --cc=ychuang3@nuvoton.com \
    --cc=yury.norov@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).