diff mbox series

[U-Boot,4/5] dm: regmap: Fix mask in regmap_update_bits()

Message ID 20191011221650.19482-5-sjg@chromium.org
State Accepted
Commit 5ca5ec1e3272f40a7ad26a15e3df3bb18e0b11d8
Delegated to: Simon Glass
Headers show
Series dm: regmap: Various fixes for regmap | expand

Commit Message

Simon Glass Oct. 11, 2019, 10:16 p.m. UTC
This function assumes that the 'val' parameter has no masked bits set.
This is not defined by the function prototype though. Fix the function to
mask the value and update the documentation.

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

 drivers/core/regmap.c | 2 +-
 include/regmap.h      | 3 ++-
 2 files changed, 3 insertions(+), 2 deletions(-)

Comments

Bin Meng Oct. 12, 2019, 2:17 a.m. UTC | #1
On Sat, Oct 12, 2019 at 6:25 AM Simon Glass <sjg@chromium.org> wrote:
>
> This function assumes that the 'val' parameter has no masked bits set.
> This is not defined by the function prototype though. Fix the function to
> mask the value and update the documentation.
>
> Signed-off-by: Simon Glass <sjg@chromium.org>
> ---
>
>  drivers/core/regmap.c | 2 +-
>  include/regmap.h      | 3 ++-
>  2 files changed, 3 insertions(+), 2 deletions(-)
>

Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Jean-Jacques Hiblot Oct. 25, 2019, 9:40 a.m. UTC | #2
On 12/10/2019 00:16, Simon Glass wrote:
> This function assumes that the 'val' parameter has no masked bits set.
> This is not defined by the function prototype though. Fix the function to
> mask the value and update the documentation.
>
> Signed-off-by: Simon Glass <sjg@chromium.org>
> ---
>
>   drivers/core/regmap.c | 2 +-
>   include/regmap.h      | 3 ++-
>   2 files changed, 3 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/core/regmap.c b/drivers/core/regmap.c
> index d1d12eef385..e9e55c9d165 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));
>   }
> diff --git a/include/regmap.h b/include/regmap.h
> index 0854200a9c1..9ada1af5ef0 100644
> --- a/include/regmap.h
> +++ b/include/regmap.h
> @@ -295,7 +295,8 @@ int regmap_raw_read_range(struct regmap *map, uint range_num, uint offset,
>    * @map:	The map returned by regmap_init_mem*()
>    * @offset:	Offset of the memory
>    * @mask:	Mask to apply to the read value
> - * @val:	Value to apply to the value to write
> + * @val:	Value to OR with the read value after masking. Note that any
> + *	bits set in @val which are not set in @mask are ignored
>    * Return: 0 if OK, -ve on error
>    */
>   int regmap_update_bits(struct regmap *map, uint offset, uint mask, uint val);

Reviewed-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
Simon Glass Oct. 29, 2019, 11:21 p.m. UTC | #3
On 12/10/2019 00:16, Simon Glass wrote:
> This function assumes that the 'val' parameter has no masked bits set.
> This is not defined by the function prototype though. Fix the function to
> mask the value and update the documentation.
>
> Signed-off-by: Simon Glass <sjg@chromium.org>
> ---
>
>   drivers/core/regmap.c | 2 +-
>   include/regmap.h      | 3 ++-
>   2 files changed, 3 insertions(+), 2 deletions(-)
>
Applied to u-boot-dm, thanks!
diff mbox series

Patch

diff --git a/drivers/core/regmap.c b/drivers/core/regmap.c
index d1d12eef385..e9e55c9d165 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));
 }
diff --git a/include/regmap.h b/include/regmap.h
index 0854200a9c1..9ada1af5ef0 100644
--- a/include/regmap.h
+++ b/include/regmap.h
@@ -295,7 +295,8 @@  int regmap_raw_read_range(struct regmap *map, uint range_num, uint offset,
  * @map:	The map returned by regmap_init_mem*()
  * @offset:	Offset of the memory
  * @mask:	Mask to apply to the read value
- * @val:	Value to apply to the value to write
+ * @val:	Value to OR with the read value after masking. Note that any
+ *	bits set in @val which are not set in @mask are ignored
  * Return: 0 if OK, -ve on error
  */
 int regmap_update_bits(struct regmap *map, uint offset, uint mask, uint val);