From c69abd801b3600252726948e0763b2b3c3fe9e19 Mon Sep 17 00:00:00 2001 From: Codrin Ciubotariu Date: Fri, 24 Jul 2015 16:52:19 +0300 Subject: [PATCH] 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 --- include/bitfield.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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); } -- 2.39.5