diff mbox

drivers: CCI: Correct use of ! and &

Message ID 1406716655-32494-1-git-send-email-punit.agrawal@arm.com (mailing list archive)
State New, archived
Headers show

Commit Message

Punit Agrawal July 30, 2014, 10:37 a.m. UTC
From: Himangi Saraogi <himangi774@gmail.com>

In commit ae91d60ba88ef0bdb1b5e9b2363bd52fc45d2af7, a bug was fixed that
involved converting !x & y to !(x & y).  The code below shows the same
pattern, and thus should perhaps be fixed in the same way.

The Coccinelle semantic patch that makes this change is as follows:

// <smpl>
@@ expression E1,E2; @@
(
  !E1 & !E2
|
- !E1 & E2
+ !(E1 & E2)
)
// </smpl>

Cc: stable@vger.kernel.org
Signed-off-by: Himangi Saraogi <himangi774@gmail.com>
Acked-by: Julia Lawall <julia.lawall@lip6.fr>
Acked-by: Punit Agrawal <punit.agrawal@arm.com>
---
 drivers/bus/arm-cci.c |    3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

Comments

Olof Johansson July 30, 2014, 7:54 p.m. UTC | #1
On Wed, Jul 30, 2014 at 11:37:35AM +0100, Punit Agrawal wrote:
> From: Himangi Saraogi <himangi774@gmail.com>
> 
> In commit ae91d60ba88ef0bdb1b5e9b2363bd52fc45d2af7, a bug was fixed that
> involved converting !x & y to !(x & y).  The code below shows the same
> pattern, and thus should perhaps be fixed in the same way.
> 
> The Coccinelle semantic patch that makes this change is as follows:
> 
> // <smpl>
> @@ expression E1,E2; @@
> (
>   !E1 & !E2
> |
> - !E1 & E2
> + !(E1 & E2)
> )
> // </smpl>
> 
> Cc: stable@vger.kernel.org
> Signed-off-by: Himangi Saraogi <himangi774@gmail.com>
> Acked-by: Julia Lawall <julia.lawall@lip6.fr>
> Acked-by: Punit Agrawal <punit.agrawal@arm.com>
> ---

Thanks, applied (adding a Fixes: tag, please use those in the future)


-Olof
Olof Johansson July 31, 2014, 6 a.m. UTC | #2
Hi,

On Wed, Jul 30, 2014 at 12:54 PM, Olof Johansson <olof@lixom.net> wrote:
> On Wed, Jul 30, 2014 at 11:37:35AM +0100, Punit Agrawal wrote:
>> From: Himangi Saraogi <himangi774@gmail.com>
>>
>> In commit ae91d60ba88ef0bdb1b5e9b2363bd52fc45d2af7, a bug was fixed that
>> involved converting !x & y to !(x & y).  The code below shows the same
>> pattern, and thus should perhaps be fixed in the same way.
>>
>> The Coccinelle semantic patch that makes this change is as follows:
>>
>> // <smpl>
>> @@ expression E1,E2; @@
>> (
>>   !E1 & !E2
>> |
>> - !E1 & E2
>> + !(E1 & E2)
>> )
>> // </smpl>
>>
>> Cc: stable@vger.kernel.org
>> Signed-off-by: Himangi Saraogi <himangi774@gmail.com>
>> Acked-by: Julia Lawall <julia.lawall@lip6.fr>
>> Acked-by: Punit Agrawal <punit.agrawal@arm.com>
>> ---
>
> Thanks, applied (adding a Fixes: tag, please use those in the future)

On second look, I see that the code doesn't actually change behavior
(since the mask is done with 0x1, it happens to have the same result).
Pure luck before. :)

Because of this, I've moved this to our next/fixes-non-critical
branch, which will be sent up during the 3.17 merge window, and I took
off the stable cc. It's still a good fix, but since it doesn't
actually fix broken behavior there's no need to rush it.


-Olof
Punit Agrawal July 31, 2014, 3:38 p.m. UTC | #3
Hi Olof,

Olof Johansson <olof@lixom.net> writes:

> Hi,
>
> On Wed, Jul 30, 2014 at 12:54 PM, Olof Johansson <olof@lixom.net> wrote:
>> On Wed, Jul 30, 2014 at 11:37:35AM +0100, Punit Agrawal wrote:
>>> From: Himangi Saraogi <himangi774@gmail.com>
>>>
>>> In commit ae91d60ba88ef0bdb1b5e9b2363bd52fc45d2af7, a bug was fixed that
>>> involved converting !x & y to !(x & y).  The code below shows the same
>>> pattern, and thus should perhaps be fixed in the same way.
>>>
>>> The Coccinelle semantic patch that makes this change is as follows:
>>>
>>> // <smpl>
>>> @@ expression E1,E2; @@
>>> (
>>>   !E1 & !E2
>>> |
>>> - !E1 & E2
>>> + !(E1 & E2)
>>> )
>>> // </smpl>
>>>
>>> Cc: stable@vger.kernel.org
>>> Signed-off-by: Himangi Saraogi <himangi774@gmail.com>
>>> Acked-by: Julia Lawall <julia.lawall@lip6.fr>
>>> Acked-by: Punit Agrawal <punit.agrawal@arm.com>
>>> ---
>>
>> Thanks, applied (adding a Fixes: tag, please use those in the future)

Will do.

>
> On second look, I see that the code doesn't actually change behavior
> (since the mask is done with 0x1, it happens to have the same result).
> Pure luck before. :)

Although I'd tested the original submission and had seen interrupts
handled correctly, this fix made me question if I was mis-remembering
(since this was about a year ago).

I had convinced myself that the fix was required. Re-evaluating all the
conditions after reading your response, I agree that it is not a change
in behaviour but still a correct fix.

>
> Because of this, I've moved this to our next/fixes-non-critical
> branch, which will be sent up during the 3.17 merge window, and I took
> off the stable cc. It's still a good fix, but since it doesn't
> actually fix broken behavior there's no need to rush it.

Ack. Thanks a lot.

>
>
> -Olof
>
> _______________________________________________
> linux-arm-kernel mailing list
> linux-arm-kernel@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
diff mbox

Patch

diff --git a/drivers/bus/arm-cci.c b/drivers/bus/arm-cci.c
index 5a86da9..7af78df 100644
--- a/drivers/bus/arm-cci.c
+++ b/drivers/bus/arm-cci.c
@@ -397,7 +397,8 @@  static irqreturn_t pmu_handle_irq(int irq_num, void *dev)
 		hw_counter = &event->hw;
 
 		/* Did this counter overflow? */
-		if (!pmu_read_register(idx, CCI_PMU_OVRFLW) & CCI_PMU_OVRFLW_FLAG)
+		if (!(pmu_read_register(idx, CCI_PMU_OVRFLW) &
+		      CCI_PMU_OVRFLW_FLAG))
 			continue;
 
 		pmu_write_register(CCI_PMU_OVRFLW_FLAG, idx, CCI_PMU_OVRFLW);