summaryrefslogtreecommitdiff
path: root/drivers/base/regmap/regmap.c
diff options
context:
space:
mode:
authorMaxime Coquelin <maxime.coquelin@st.com>2015-06-16 13:53:19 +0200
committerSasha Levin <sasha.levin@oracle.com>2015-07-03 23:02:31 -0400
commitc00a686169ade8556ca010eb5bad6d9b6d4503cb (patch)
treef6d97701669fb21b9effc77bd32351c4129a734a /drivers/base/regmap/regmap.c
parentf099f4aaad04c7fa3f3001796d03f3754e64e748 (diff)
downloadlwn-c00a686169ade8556ca010eb5bad6d9b6d4503cb.tar.gz
lwn-c00a686169ade8556ca010eb5bad6d9b6d4503cb.zip
regmap: Fix possible shift overflow in regmap_field_init()
[ Upstream commit 921cc29473a0d7c109105c1876ddb432f4a4be7d ] The way the mask is generated in regmap_field_init() is wrong. Indeed, a field initialized with msb = 31 and lsb = 0 provokes a shift overflow while calculating the mask field. On some 32 bits architectures, such as x86, the generated mask is 0, instead of the expected 0xffffffff. This patch uses GENMASK() to fix the problem, as this macro is already safe regarding shift overflow. Signed-off-by: Maxime Coquelin <maxime.coquelin@st.com> Signed-off-by: Mark Brown <broonie@kernel.org> Cc: stable@vger.kernel.org Signed-off-by: Sasha Levin <sasha.levin@oracle.com>
Diffstat (limited to 'drivers/base/regmap/regmap.c')
-rw-r--r--drivers/base/regmap/regmap.c3
1 files changed, 1 insertions, 2 deletions
diff --git a/drivers/base/regmap/regmap.c b/drivers/base/regmap/regmap.c
index a434df6d4e09..b389c1dbcdf7 100644
--- a/drivers/base/regmap/regmap.c
+++ b/drivers/base/regmap/regmap.c
@@ -944,11 +944,10 @@ EXPORT_SYMBOL_GPL(devm_regmap_init);
static void regmap_field_init(struct regmap_field *rm_field,
struct regmap *regmap, struct reg_field reg_field)
{
- int field_bits = reg_field.msb - reg_field.lsb + 1;
rm_field->regmap = regmap;
rm_field->reg = reg_field.reg;
rm_field->shift = reg_field.lsb;
- rm_field->mask = ((BIT(field_bits) - 1) << reg_field.lsb);
+ rm_field->mask = GENMASK(reg_field.msb, reg_field.lsb);
rm_field->id_size = reg_field.id_size;
rm_field->id_offset = reg_field.id_offset;
}