From: Codrin Ciubotariu Date: Fri, 24 Jul 2015 13:52:19 +0000 (+0300) Subject: include/bitfield.h: Assure new bitfield value doesn't touch unwanted bits X-Git-Url: http://git.dujemihanovic.xyz/?a=commitdiff_plain;h=c69abd801b3600252726948e0763b2b3c3fe9e19;p=u-boot.git include/bitfield.h: Assure new bitfield value doesn't touch unwanted bits The new bitfield value must not be higher than its mask. Signed-off-by: Codrin Ciubotariu Reviewed-by: Joe Hershberger --- diff --git a/include/bitfield.h b/include/bitfield.h index ec4815c8e0..b884c74600 100644 --- a/include/bitfield.h +++ b/include/bitfield.h @@ -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); }