mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Ahmad Fatoum <a.fatoum@barebox.org>
To: barebox@lists.infradead.org
Cc: jre@pengutronix.de, Ahmad Fatoum <a.fatoum@barebox.org>
Subject: [PATCH] regmap: enforce register alignment to regmap::reg_stride
Date: Tue, 26 May 2026 08:00:15 +0200	[thread overview]
Message-ID: <20260526060041.1726523-1-a.fatoum@barebox.org> (raw)

We currently enforce this only for regmap_bulk_read/write, but really
it's applicable to all regmap read/write operations.

Linux already enforces this everywhere, so follow suit in barebox.

Signed-off-by: Ahmad Fatoum <a.fatoum@barebox.org>
---
 drivers/base/regmap/regmap.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/drivers/base/regmap/regmap.c b/drivers/base/regmap/regmap.c
index e4b20c07809d..f41e9d94944e 100644
--- a/drivers/base/regmap/regmap.c
+++ b/drivers/base/regmap/regmap.c
@@ -69,6 +69,9 @@ static int _regmap_bus_reg_read(void *context, unsigned int reg,
 {
 	struct regmap *map = context;
 
+	if (!IS_ALIGNED(reg, map->reg_stride))
+		return -EINVAL;
+
 	return map->bus->reg_read(map->bus_context, reg, val);
 }
 
@@ -78,6 +81,9 @@ static int _regmap_bus_reg_write(void *context, unsigned int reg,
 {
 	struct regmap *map = context;
 
+	if (!IS_ALIGNED(reg, map->reg_stride))
+		return -EINVAL;
+
 	return map->bus->reg_write(map->bus_context, reg, val);
 }
 
@@ -86,6 +92,8 @@ static int _regmap_bus_reg_seal(void *context, unsigned int reg,
 {
 	struct regmap *map = context;
 
+	if (!IS_ALIGNED(reg, map->reg_stride))
+		return -EINVAL;
 	if (!map->bus->reg_seal)
 		return -EOPNOTSUPP;
 
@@ -182,6 +190,8 @@ struct device *regmap_get_device(struct regmap *map)
  */
 int regmap_write(struct regmap *map, unsigned int reg, unsigned int val)
 {
+	if (!IS_ALIGNED(reg, map->reg_stride))
+		return -EINVAL;
 	return map->reg_write(map, reg, val);
 }
 
@@ -196,6 +206,8 @@ int regmap_write(struct regmap *map, unsigned int reg, unsigned int val)
  */
 int regmap_read(struct regmap *map, unsigned int reg, unsigned int *val)
 {
+	if (!IS_ALIGNED(reg, map->reg_stride))
+		return -EINVAL;
 	return map->reg_read(map, reg, val);
 }
 
@@ -213,6 +225,8 @@ int regmap_read(struct regmap *map, unsigned int reg, unsigned int *val)
  */
 int regmap_seal(struct regmap *map, unsigned int reg, unsigned int flags)
 {
+	if (!IS_ALIGNED(reg, map->reg_stride))
+		return -EINVAL;
 	return map->reg_seal(map, reg, flags);
 }
 
-- 
2.47.3




             reply	other threads:[~2026-05-26  6:02 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-26  6:00 Ahmad Fatoum [this message]
2026-05-26  6:26 ` Sascha Hauer

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=20260526060041.1726523-1-a.fatoum@barebox.org \
    --to=a.fatoum@barebox.org \
    --cc=barebox@lists.infradead.org \
    --cc=jre@pengutronix.de \
    /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