[PATCH] regmap: enforce register alignment to regmap::reg_stride

Ahmad Fatoum a.fatoum at barebox.org
Mon May 25 23:00:15 PDT 2026


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 at 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




More information about the barebox mailing list