2013-10-02 11:10:30

by Taras Kondratiuk

[permalink] [raw]
Subject: [PATCH] mfd: twl6030: Fix endianness problem in IRQ handler

From: Danke Xie <[email protected]>

The current TWL 6030 IRQ handler assumes little endianness.
This change makes it endian-neutral.

Signed-off-by: Danke Xie <[email protected]>
Signed-off-by: Taras Kondratiuk <[email protected]>
---
drivers/mfd/twl6030-irq.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/mfd/twl6030-irq.c b/drivers/mfd/twl6030-irq.c
index 517eda8..1941dc6 100644
--- a/drivers/mfd/twl6030-irq.c
+++ b/drivers/mfd/twl6030-irq.c
@@ -178,6 +178,7 @@ static irqreturn_t twl6030_irq_thread(int irq, void *data)
u8 bytes[4];
u32 int_sts;
} sts;
+ u32 int_sts; /* sts.int_sts converted to CPU endianness */
struct twl6030_irq *pdata = data;

/* read INT_STS_A, B and C in one shot using a burst read */
@@ -196,8 +197,9 @@ static irqreturn_t twl6030_irq_thread(int irq, void *data)
if (sts.bytes[2] & 0x10)
sts.bytes[2] |= 0x08;

- for (i = 0; sts.int_sts; sts.int_sts >>= 1, i++)
- if (sts.int_sts & 0x1) {
+ int_sts = le32_to_cpu(sts.int_sts);
+ for (i = 0; int_sts; int_sts >>= 1, i++)
+ if (int_sts & 0x1) {
int module_irq =
irq_find_mapping(pdata->irq_domain,
pdata->irq_mapping_tbl[i]);
--
1.7.9.5


2013-10-02 16:44:06

by Kim Phillips

[permalink] [raw]
Subject: Re: [LNG] [PATCH] mfd: twl6030: Fix endianness problem in IRQ handler

On Wed, 2 Oct 2013 14:08:44 +0300
Taras Kondratiuk <[email protected]> wrote:

> From: Danke Xie <[email protected]>
>
> The current TWL 6030 IRQ handler assumes little endianness.
> This change makes it endian-neutral.
>
> Signed-off-by: Danke Xie <[email protected]>
> Signed-off-by: Taras Kondratiuk <[email protected]>
> ---

this patch causes a new sparse warning:

make C=2 CF="-D__CHECK_ENDIAN__" drivers/mfd/twl6030-irq.o
...
CHECK drivers/mfd/twl6030-irq.c
drivers/mfd/twl6030-irq.c:200:19: warning: cast to restricted __le32

does int_sts in the sts union need to be defined as __le32?

Thanks,

Kim

2013-10-02 21:08:53

by Taras Kondratiuk

[permalink] [raw]
Subject: Re: [LNG] [PATCH] mfd: twl6030: Fix endianness problem in IRQ handler

On 2 October 2013 19:43, Kim Phillips <[email protected]> wrote:
> On Wed, 2 Oct 2013 14:08:44 +0300
> Taras Kondratiuk <[email protected]> wrote:
>
>> From: Danke Xie <[email protected]>
>>
>> The current TWL 6030 IRQ handler assumes little endianness.
>> This change makes it endian-neutral.
>>
>> Signed-off-by: Danke Xie <[email protected]>
>> Signed-off-by: Taras Kondratiuk <[email protected]>
>> ---
>
> this patch causes a new sparse warning:
>
> make C=2 CF="-D__CHECK_ENDIAN__" drivers/mfd/twl6030-irq.o
> ...
> CHECK drivers/mfd/twl6030-irq.c
> drivers/mfd/twl6030-irq.c:200:19: warning: cast to restricted __le32
>
> does int_sts in the sts union need to be defined as __le32?

You are right.
I will update the patch.

--
Regards,
Taras Kondratiuk

2013-10-03 23:01:10

by Taras Kondratiuk

[permalink] [raw]
Subject: [PATCH v2] mfd: twl6030: Fix endianness problem in IRQ handler

From: Danke Xie <[email protected]>

The current TWL 6030 IRQ handler assumes little endianness.
This change makes it endian-neutral.

Signed-off-by: Danke Xie <[email protected]>
Signed-off-by: Taras Kondratiuk <[email protected]>
---
v2: fixed sparse warning
v1: https://patchwork.kernel.org/patch/2974331/

drivers/mfd/twl6030-irq.c | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/drivers/mfd/twl6030-irq.c b/drivers/mfd/twl6030-irq.c
index 517eda8..18a607e 100644
--- a/drivers/mfd/twl6030-irq.c
+++ b/drivers/mfd/twl6030-irq.c
@@ -176,8 +176,9 @@ static irqreturn_t twl6030_irq_thread(int irq, void *data)
int i, ret;
union {
u8 bytes[4];
- u32 int_sts;
+ __le32 int_sts;
} sts;
+ u32 int_sts; /* sts.int_sts converted to CPU endianness */
struct twl6030_irq *pdata = data;

/* read INT_STS_A, B and C in one shot using a burst read */
@@ -196,8 +197,9 @@ static irqreturn_t twl6030_irq_thread(int irq, void *data)
if (sts.bytes[2] & 0x10)
sts.bytes[2] |= 0x08;

- for (i = 0; sts.int_sts; sts.int_sts >>= 1, i++)
- if (sts.int_sts & 0x1) {
+ int_sts = le32_to_cpu(sts.int_sts);
+ for (i = 0; int_sts; int_sts >>= 1, i++)
+ if (int_sts & 0x1) {
int module_irq =
irq_find_mapping(pdata->irq_domain,
pdata->irq_mapping_tbl[i]);
--
1.7.9.5