linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] regmap: Fix possible shift overflow in regmap_field_init()
@ 2015-06-16 11:53 Maxime Coquelin
  2015-06-16 11:58 ` Mark Brown
  0 siblings, 1 reply; 2+ messages in thread
From: Maxime Coquelin @ 2015-06-16 11:53 UTC (permalink / raw)
  To: Mark Brown, Greg Kroah-Hartman, linux-kernel; +Cc: maxime.coquelin

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>
---
 drivers/base/regmap/regmap.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/base/regmap/regmap.c b/drivers/base/regmap/regmap.c
index 6273ff0..e5194f6 100644
--- a/drivers/base/regmap/regmap.c
+++ b/drivers/base/regmap/regmap.c
@@ -945,11 +945,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;
 }
-- 
1.9.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] regmap: Fix possible shift overflow in regmap_field_init()
  2015-06-16 11:53 [PATCH] regmap: Fix possible shift overflow in regmap_field_init() Maxime Coquelin
@ 2015-06-16 11:58 ` Mark Brown
  0 siblings, 0 replies; 2+ messages in thread
From: Mark Brown @ 2015-06-16 11:58 UTC (permalink / raw)
  To: Maxime Coquelin; +Cc: Greg Kroah-Hartman, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 266 bytes --]

On Tue, Jun 16, 2015 at 01:53:19PM +0200, Maxime Coquelin wrote:
> 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.

Applied, thanks.

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 473 bytes --]

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2015-06-16 11:59 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-06-16 11:53 [PATCH] regmap: Fix possible shift overflow in regmap_field_init() Maxime Coquelin
2015-06-16 11:58 ` Mark Brown

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).