]> git.sur5r.net Git - u-boot/commitdiff
include/bitfield.h: Assure new bitfield value doesn't touch unwanted bits
authorCodrin Ciubotariu <codrin.ciubotariu@freescale.com>
Fri, 24 Jul 2015 13:52:19 +0000 (16:52 +0300)
committerTom Rini <trini@konsulko.com>
Thu, 13 Aug 2015 00:47:44 +0000 (20:47 -0400)
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>
include/bitfield.h

index ec4815c8e05179508c00cce24655acd7382ba62e..b884c7460013faab98010d48b08952c77287683d 100644 (file)
@@ -54,5 +54,5 @@ 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);
 }