]> git.kernelconcepts.de Git - karo-tx-uboot.git/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)
committerLothar Waßmann <LW@KARO-electronics.de>
Thu, 10 Sep 2015 06:25:46 +0000 (08:25 +0200)
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);
 }