diff mbox series

[U-Boot,v1,1/5] regmap: Fix potential overflow in regmap_update_bits()

Message ID 20190927132221.17892-2-jjhiblot@ti.com
State Superseded
Delegated to: Tom Rini
Headers show
Series regmap: Add a managed API, custom read/write callbacks and support for regmap fields | expand

Commit Message

Jean-Jacques Hiblot Sept. 27, 2019, 1:22 p.m. UTC
Mask the value to write so that it cannot affect the bits outside of the
mask

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
---

 drivers/core/regmap.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Simon Glass Oct. 30, 2019, 1:48 a.m. UTC | #1
On Fri, 27 Sep 2019 at 07:22, Jean-Jacques Hiblot <jjhiblot@ti.com> wrote:
>
> Mask the value to write so that it cannot affect the bits outside of the
> mask
>
> Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
> ---
>
>  drivers/core/regmap.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)

Reviewed-by: Simon Glass <sjg@chromium.org>

It would be encouraging to see a test updated to catch this problem.

Hmmm actually I just remembered I fixed this - see u-boot-dm/master

Sorry, it looks like your patch was first, but mine does add a test :-)


>
> diff --git a/drivers/core/regmap.c b/drivers/core/regmap.c
> index d1d12eef38..e9e55c9d16 100644
> --- a/drivers/core/regmap.c
> +++ b/drivers/core/regmap.c
> @@ -462,5 +462,5 @@ int regmap_update_bits(struct regmap *map, uint offset, uint mask, uint val)
>
>         reg &= ~mask;
>
> -       return regmap_write(map, offset, reg | val);
> +       return regmap_write(map, offset, reg | (val & mask));
>  }
> --
> 2.17.1
>
diff mbox series

Patch

diff --git a/drivers/core/regmap.c b/drivers/core/regmap.c
index d1d12eef38..e9e55c9d16 100644
--- a/drivers/core/regmap.c
+++ b/drivers/core/regmap.c
@@ -462,5 +462,5 @@  int regmap_update_bits(struct regmap *map, uint offset, uint mask, uint val)
 
 	reg &= ~mask;
 
-	return regmap_write(map, offset, reg | val);
+	return regmap_write(map, offset, reg | (val & mask));
 }