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

Codrin Ciubotariu codrin.ciubotariu at freescale.com
Fri Jul 24 15:52:19 CEST 2015


The new bitfield value must not be higher than its mask.

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

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 */
-- 
1.9.3



More information about the U-Boot mailing list