Browse Source

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>
Codrin Ciubotariu 9 years ago
parent
commit
c69abd801b
1 changed files with 1 additions and 1 deletions
  1. 1 1
      include/bitfield.h

+ 1 - 1
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);
 }