Skip to contentSkip to conversation

MFD fixes for v5.2

GIT PULL In review Lee Jones 5 participants 14 messages Jun 17, 2019 – Jun 25, 2019

Subsystems (3)
lore
Share & tools
lore

Lee Jones

author
#0 lore raw

Linus,

Enjoy!

The following changes since commit a188339ca5a396acc588e5851ed7e19f66b0ebd9:

Linux 5.2-rc1 (2019-05-19 15:47:09 -0700)

are available in the Git repository at:

git://git.kernel.org/pub/scm/linux/kernel/git/lee/mfd.git tags/mfd-fixes-5.2

for you to fetch changes up to cd49b84d61b2dfc0360c76d9e6be49f5116ba1a5:

mfd: stmfx: Uninitialized variable in stmfx_irq_handler() (2019-06-17 10:51:15 +0100)

----------------------------------------------------------------
- Bug Fixes
- Resize variable to avoid uninitialised (MSB) data

----------------------------------------------------------------
Dan Carpenter (1):
mfd: stmfx: Uninitialized variable in stmfx_irq_handler()

 drivers/mfd/stmfx.c | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)
Signature · 4 lines
Lee Jones [李琼斯]
Linaro Services Technical Lead
Linaro.org │ Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog
#1 lore raw
Quoted 2 lines · Lee Jones

Enjoy!

No.

This is still entirely wrong.

You can't just randomly cast an "u32 *" to "unsigned long *".

It wasn't correct when you did it the other way in regmap_read(), but it's also not correct when you now for it this way for for_each_set_bit().

You can do

    u32 regmap_bits;
    unsigned long bits;

and then

    ret = regmap_read(stmfx->map, STMFX_REG_IRQ_PENDING, &regmap_bits);
    ...
    bits = regmap_bits;
    for_each_set_bit(n, &bits, STMFX_REG_IRQ_SRC_MAX) ..

but casting pointers at either point is *completely* wrong.

Yes, yes, it happens to work on little-endian, but on a 64-bit big-endian machine, the low 32 bits of the "unsigned int" will have absolutely _zero_ overlap with the low 32 bits of the "unsigned long" in memory.

When you moved the cast to for_each_set_bit(), it only moves the access of the bogus bits to another place instead.

So that patch doesn't fix anything at all, it only moves the same error around.

Linus

#2 lore raw

Ah... Sorry. There are a couple similar bugs in other places and I'll take a look at those tomorrow as well.

regards,
dan carpenter

#3 lore raw

PATCH 1/1 mfd: stmfx: Fix an endian bug in stmfx_irq_handler()

In reply to Linus Torvalds

It's not okay to cast a "u32 *" to "unsigned long *" when you are doing a for_each_set_bit() loop because that will break on big endian systems.

Fixes 386145601b82 ("mfd: stmfx: Uninitialized variable in stmfx_irq_handler()")
---
 drivers/mfd/stmfx.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/mfd/stmfx.c +3 -1
index 7c419c078688..857991cb3cbb 100644
@@ -204,6 +204,7 @@ static struct irq_chip stmfx_irq_chip = {
 static irqreturn_t stmfx_irq_handler(int irq, void *data)
 {
 	struct stmfx *stmfx = data;
+	unsigned long bits;
 	u32 pending, ack;
 	int n, ret;
 
@@ -222,7 +223,8 @@ static irqreturn_t stmfx_irq_handler(int irq, void *data)
 			return IRQ_NONE;
 	}
 
-	for_each_set_bit(n, (unsigned long *)&pending, STMFX_REG_IRQ_SRC_MAX)
+	bits = pending;
+	for_each_set_bit(n, &bits, STMFX_REG_IRQ_SRC_MAX)
 		handle_nested_irq(irq_find_mapping(stmfx->irq_domain, n));
 
 	return IRQ_HANDLED;
Signature · 1 line
2.20.1
author
#4 lore raw

Re: [PATCH] mfd: stmfx: Fix an endian bug in stmfx_irq_handler()

Quoted 5 lines · Dan Carpenter

It's not okay to cast a "u32 *" to "unsigned long *" when you are doing a for_each_set_bit() loop because that will break on big endian systems.

Ideally we can get a review too.

Quoted 28 lines
Fixes 386145601b82 ("mfd: stmfx: Uninitialized variable in stmfx_irq_handler()")
---
 drivers/mfd/stmfx.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/mfd/stmfx.c +3 -1
index 7c419c078688..857991cb3cbb 100644
@@ -204,6 +204,7 @@ static struct irq_chip stmfx_irq_chip = {
 static irqreturn_t stmfx_irq_handler(int irq, void *data)
 {
 	struct stmfx *stmfx = data;
+	unsigned long bits;
 	u32 pending, ack;
 	int n, ret;
 
@@ -222,7 +223,8 @@ static irqreturn_t stmfx_irq_handler(int irq, void *data)
 			return IRQ_NONE;
 	}
 
-	for_each_set_bit(n, (unsigned long *)&pending, STMFX_REG_IRQ_SRC_MAX)
+	bits = pending;
+	for_each_set_bit(n, &bits, STMFX_REG_IRQ_SRC_MAX)
 		handle_nested_irq(irq_find_mapping(stmfx->irq_domain, n));
 
 	return IRQ_HANDLED;
Signature · 4 lines
Lee Jones [李琼斯]
Linaro Services Technical Lead
Linaro.org │ Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog
#5 lore raw

Re: [PATCH] mfd: stmfx: Fix an endian bug in stmfx_irq_handler()

Quoted 4 lines · Lee Jones
Quoted 2 lines

Ideally we can get a review too.

Looks fine to me, but obviously somebody should actually _test_ it too.

Linus

author
#6 lore raw

Re: [PATCH] mfd: stmfx: Fix an endian bug in stmfx_irq_handler()

Quoted 7 lines · Linus Torvalds
Quoted 4 lines · Lee Jones
Quoted 2 lines

Ideally we can get a review too.

Looks fine to me, but obviously somebody should actually _test_ it too.

Amelie, would you be so kind?

Signature · 4 lines
Lee Jones [李琼斯]
Linaro Services Technical Lead
Linaro.org │ Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog
Tested-by
#7 lore raw

Re: [PATCH] mfd: stmfx: Fix an endian bug in stmfx_irq_handler()

T24gNi8xOS8xOSA3OjU4IEFNLCBMZWUgSm9uZXMgd3JvdGU6DQo+IE9uIFR1ZSwgMTggSnVuIDIw MTksIExpbnVzIFRvcnZhbGRzIHdyb3RlOg0KPiANCj4+IE9uIFR1ZSwgSnVuIDE4LCAyMDE5IGF0 IDE6MTYgQU0gTGVlIEpvbmVzIDxsZWUuam9uZXNAbGluYXJvLm9yZz4gd3JvdGU6DQo+Pj4NCj4+ Pj4gUmVwb3J0ZWQtYnk6IExpbnVzIFRvcnZhbGRzIDx0b3J2YWxkc0BsaW51eC1mb3VuZGF0aW9u Lm9yZz4NCj4+Pg0KPj4+IElkZWFsbHkgd2UgY2FuIGdldCBhIHJldmlldyB0b28uDQo+Pg0KPj4g TG9va3MgZmluZSB0byBtZSwgYnV0IG9idmlvdXNseSBzb21lYm9keSBzaG91bGQgYWN0dWFsbHkg X3Rlc3RfIGl0IHRvby4NCj4gDQo+IEFtZWxpZSwgd291bGQgeW91IGJlIHNvIGtpbmQ/DQo+IA0K DQpUZXN0ZWQgb24gc3RtMzJtcDE1N2MtZXYxLg0KDQpUZXN0ZWQtYnk6IEFtZWxpZSBEZWxhdW5h eSA8YW1lbGllLmRlbGF1bmF5QHN0LmNvbT4

author
#8 lore raw
In reply to Linus Torvalds
Quoted 33 lines · Linus Torvalds
Quoted 2 lines · Lee Jones

Enjoy!

No.

This is still entirely wrong.

You can't just randomly cast an "u32 *" to "unsigned long *".

It wasn't correct when you did it the other way in regmap_read(), but it's also not correct when you now for it this way for for_each_set_bit().

You can do

    u32 regmap_bits;
    unsigned long bits;

and then

    ret = regmap_read(stmfx->map, STMFX_REG_IRQ_PENDING, &regmap_bits);
    ...
    bits = regmap_bits;
    for_each_set_bit(n, &bits, STMFX_REG_IRQ_SRC_MAX) ..

but casting pointers at either point is *completely* wrong.

Yes, yes, it happens to work on little-endian, but on a 64-bit big-endian machine, the low 32 bits of the "unsigned int" will have absolutely _zero_ overlap with the low 32 bits of the "unsigned long" in memory.

Quoted 4 lines

When you moved the cast to for_each_set_bit(), it only moves the access of the bogus bits to another place instead.

So that patch doesn't fix anything at all, it only moves the same error around.

Good catch. Thank you for taking the time to review Linus.

Signature · 4 lines
Lee Jones [李琼斯]
Linaro Services Technical Lead
Linaro.org │ Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog
author
#9 lore raw
In reply to Lee Jones

Linus,

Hopefully this is more to your liking.

The following changes since commit a188339ca5a396acc588e5851ed7e19f66b0ebd9:

Linux 5.2-rc1 (2019-05-19 15:47:09 -0700)

are available in the Git repository at:

git://git.kernel.org/pub/scm/linux/kernel/git/lee/mfd.git mfd-fixes-5.2-1

for you to fetch changes up to 63b2de12b7eeacfb2edbe005f5c3cff17a2a02e2:

mfd: stmfx: Fix an endian bug in stmfx_irq_handler() (2019-06-24 15:19:31 +0100)

----------------------------------------------------------------
- Bug Fixes
- Resize variable to avoid uninitialised (MSB) data; stmfx
- Fixe endian bug; stmfx

----------------------------------------------------------------
Dan Carpenter (2):
mfd: stmfx: Uninitialized variable in stmfx_irq_handler()
mfd: stmfx: Fix an endian bug in stmfx_irq_handler()

 drivers/mfd/stmfx.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
Signature · 4 lines
Lee Jones [李琼斯]
Linaro Services Technical Lead
Linaro.org │ Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog
#10 lore raw
Quoted 2 lines · Lee Jones

Hopefully this is more to your liking.

I would actually have preferred you to throw the old buggy "fix" away, and just do the final state.

But the end result looks sane, so I pulled it.

Linus

author
#11 lore raw
Quoted 6 lines · Linus Torvalds
Quoted 2 lines · Lee Jones

Hopefully this is more to your liking.

I would actually have preferred you to throw the old buggy "fix" away, and just do the final state.

You okayed the follow-up patch, so I took it as-is.

Quoted 1 line

But the end result looks sane, so I pulled it.

Sounds good, thanks.

Signature · 4 lines
Lee Jones [李琼斯]
Linaro Services Technical Lead
Linaro.org │ Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog
merge bot Merged
#12 lore raw
In reply to Lee Jones
The pull request you sent on Mon, 24 Jun 2019 15:34:11 +0100:

The pull request you sent on Mon, 24 Jun 2019 15:34:11 +0100:

Quoted 1 line

git://git.kernel.org/pub/scm/linux/kernel/git/lee/mfd.git mfd-fixes-5.2-1

has been merged into torvalds/linux.git:
https://git.kernel.org/torvalds/c/c88e40e07cd967dcdf37321a63ab6e8b0d881100

Thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.wiki.kernel.org/userdoc/prtracker
merge bot Merged
#13 lore raw
In reply to Lee Jones
The pull request you sent on Mon, 17 Jun 2019 11:00:54 +0100:

The pull request you sent on Mon, 17 Jun 2019 11:00:54 +0100:

Quoted 1 line

git://git.kernel.org/pub/scm/linux/kernel/git/lee/mfd.git tags/mfd-fixes-5.2

has been merged into torvalds/linux.git:
https://git.kernel.org/torvalds/c/63b2de12b7eeacfb2edbe005f5c3cff17a2a02e2

Thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.wiki.kernel.org/userdoc/prtracker