diff mbox

[U-Boot] include/bitfield.h: Assure new bitfield value doesn't touch unwanted bits

Message ID 1437745939-14192-1-git-send-email-codrin.ciubotariu@freescale.com
State Accepted
Delegated to: Tom Rini
Headers show

Commit Message

Codrin Ciubotariu July 24, 2015, 1:52 p.m. UTC
The new bitfield value must not be higher than its mask.

Signed-off-by: Codrin Ciubotariu <codrin.ciubotariu@freescale.com>
---
 include/bitfield.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Joe Hershberger July 24, 2015, 2:53 p.m. UTC | #1
Hi Codrin,

On Fri, Jul 24, 2015 at 8:52 AM, Codrin Ciubotariu
<codrin.ciubotariu@freescale.com> wrote:
> The new bitfield value must not be higher than its mask.
>
> Signed-off-by: Codrin Ciubotariu <codrin.ciubotariu@freescale.com>
> ---

Reviewed-by: Joe Hershberger <joe.hershberger@ni.com>
Tom Rini Aug. 13, 2015, 1:19 p.m. UTC | #2
On Fri, Jul 24, 2015 at 04:52:19PM +0300, Codrin Ciubotariu wrote:

> The new bitfield value must not be higher than its mask.
> 
> Signed-off-by: Codrin Ciubotariu <codrin.ciubotariu@freescale.com>
> Reviewed-by: Joe Hershberger <joe.hershberger@ni.com>

Applied to u-boot/master, thanks!
diff mbox

Patch

diff --git a/include/bitfield.h b/include/bitfield.h
index cffaf7a..a59f3c2 100644
--- a/include/bitfield.h
+++ b/include/bitfield.h
@@ -60,7 +60,7 @@  static inline uint bitfield_replace(uint reg_val, uint shift, uint width,
 {
 	uint mask = bitfield_mask(shift, width);
 
-	return (reg_val & ~mask) | (bitfield_val << shift);
+	return (reg_val & ~mask) | ((bitfield_val << shift) & mask);
 }
 
 /* Produces a shift of the bitfield given a mask */