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 <codrin.ciubotariu@freescale.com>
Reviewed-by: Joe Hershberger <joe.hershberger@ni.com>
This commit is contained in:
Codrin Ciubotariu 2015-07-24 16:52:19 +03:00 committed by Tom Rini
parent 4cffbec96a
commit c69abd801b

View 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);
}