diff mbox series

mfd: stmfx: Fix an endian bug in stmfx_irq_handler()

Message ID 20190617190605.GA21332@mwanda (mailing list archive)
State Mainlined, archived
Commit 63b2de12b7eeacfb2edbe005f5c3cff17a2a02e2
Headers show
Series mfd: stmfx: Fix an endian bug in stmfx_irq_handler() | expand

Commit Message

Dan Carpenter June 17, 2019, 7:06 p.m. UTC
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.

Reported-by: Linus Torvalds <torvalds@linux-foundation.org>
Fixes: 386145601b82 ("mfd: stmfx: Uninitialized variable in stmfx_irq_handler()")
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
---
 drivers/mfd/stmfx.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

Comments

Lee Jones June 18, 2019, 8:16 a.m. UTC | #1
On Mon, 17 Jun 2019, Dan Carpenter wrote:

> 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.
> 
> Reported-by: Linus Torvalds <torvalds@linux-foundation.org>

Ideally we can get a review too.

> Fixes: 386145601b82 ("mfd: stmfx: Uninitialized variable in stmfx_irq_handler()")
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
> ---
>  drivers/mfd/stmfx.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/mfd/stmfx.c b/drivers/mfd/stmfx.c
> index 7c419c078688..857991cb3cbb 100644
> --- a/drivers/mfd/stmfx.c
> +++ b/drivers/mfd/stmfx.c
> @@ -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;
Linus Torvalds June 18, 2019, 8:55 p.m. UTC | #2
On Tue, Jun 18, 2019 at 1:16 AM Lee Jones <lee.jones@linaro.org> wrote:
>
> > Reported-by: Linus Torvalds <torvalds@linux-foundation.org>
>
> Ideally we can get a review too.

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

              Linus
Lee Jones June 19, 2019, 5:58 a.m. UTC | #3
On Tue, 18 Jun 2019, Linus Torvalds wrote:

> On Tue, Jun 18, 2019 at 1:16 AM Lee Jones <lee.jones@linaro.org> wrote:
> >
> > > Reported-by: Linus Torvalds <torvalds@linux-foundation.org>
> >
> > 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?
Amelie Delaunay June 20, 2019, 3:18 p.m. UTC | #4
On 6/19/19 7:58 AM, Lee Jones wrote:
> On Tue, 18 Jun 2019, Linus Torvalds wrote:
> 
>> On Tue, Jun 18, 2019 at 1:16 AM Lee Jones <lee.jones@linaro.org> wrote:
>>>
>>>> Reported-by: Linus Torvalds <torvalds@linux-foundation.org>
>>>
>>> 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?
> 

Tested on stm32mp157c-ev1.

Tested-by: Amelie Delaunay <amelie.delaunay@st.com>
diff mbox series

Patch

diff --git a/drivers/mfd/stmfx.c b/drivers/mfd/stmfx.c
index 7c419c078688..857991cb3cbb 100644
--- a/drivers/mfd/stmfx.c
+++ b/drivers/mfd/stmfx.c
@@ -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;