2018-03-28 17:59:22

by Varsha Rao

[permalink] [raw]
Subject: [PATCH] crypto: cavium: zip: Remove unnecessary parentheses

This patch fixes the clang warning of extraneous parentheses, with the
following coccinelle script.

@@
identifier i;
constant c;
@@
(
-((i == c))
+i == c
|
-((i <= c))
+i <= c
)

Signed-off-by: Varsha Rao <[email protected]>
---
drivers/crypto/cavium/zip/zip_regs.h | 42 ++++++++++++++++++------------------
1 file changed, 21 insertions(+), 21 deletions(-)

diff --git a/drivers/crypto/cavium/zip/zip_regs.h b/drivers/crypto/cavium/zip/zip_regs.h
index d0be682305c1..874e0236c87e 100644
--- a/drivers/crypto/cavium/zip/zip_regs.h
+++ b/drivers/crypto/cavium/zip/zip_regs.h
@@ -443,7 +443,7 @@ union zip_corex_bist_status {

static inline u64 ZIP_COREX_BIST_STATUS(u64 param1)
{
- if (((param1 <= 1)))
+ if (param1 <= 1)
return 0x0520ull + (param1 & 1) * 0x8ull;
pr_err("ZIP_COREX_BIST_STATUS: %llu\n", param1);
return 0;
@@ -537,7 +537,7 @@ union zip_dbg_corex_inst {

static inline u64 ZIP_DBG_COREX_INST(u64 param1)
{
- if (((param1 <= 1)))
+ if (param1 <= 1)
return 0x0640ull + (param1 & 1) * 0x8ull;
pr_err("ZIP_DBG_COREX_INST: %llu\n", param1);
return 0;
@@ -568,7 +568,7 @@ union zip_dbg_corex_sta {

static inline u64 ZIP_DBG_COREX_STA(u64 param1)
{
- if (((param1 <= 1)))
+ if (param1 <= 1)
return 0x0680ull + (param1 & 1) * 0x8ull;
pr_err("ZIP_DBG_COREX_STA: %llu\n", param1);
return 0;
@@ -599,7 +599,7 @@ union zip_dbg_quex_sta {

static inline u64 ZIP_DBG_QUEX_STA(u64 param1)
{
- if (((param1 <= 7)))
+ if (param1 <= 7)
return 0x1800ull + (param1 & 7) * 0x8ull;
pr_err("ZIP_DBG_QUEX_STA: %llu\n", param1);
return 0;
@@ -817,7 +817,7 @@ union zip_msix_pbax {

static inline u64 ZIP_MSIX_PBAX(u64 param1)
{
- if (((param1 == 0)))
+ if (param1 == 0)
return 0x0000838000FF0000ull;
pr_err("ZIP_MSIX_PBAX: %llu\n", param1);
return 0;
@@ -846,7 +846,7 @@ union zip_msix_vecx_addr {

static inline u64 ZIP_MSIX_VECX_ADDR(u64 param1)
{
- if (((param1 <= 17)))
+ if (param1 <= 17)
return 0x0000838000F00000ull + (param1 & 31) * 0x10ull;
pr_err("ZIP_MSIX_VECX_ADDR: %llu\n", param1);
return 0;
@@ -875,7 +875,7 @@ union zip_msix_vecx_ctl {

static inline u64 ZIP_MSIX_VECX_CTL(u64 param1)
{
- if (((param1 <= 17)))
+ if (param1 <= 17)
return 0x0000838000F00008ull + (param1 & 31) * 0x10ull;
pr_err("ZIP_MSIX_VECX_CTL: %llu\n", param1);
return 0;
@@ -900,7 +900,7 @@ union zip_quex_done {

static inline u64 ZIP_QUEX_DONE(u64 param1)
{
- if (((param1 <= 7)))
+ if (param1 <= 7)
return 0x2000ull + (param1 & 7) * 0x8ull;
pr_err("ZIP_QUEX_DONE: %llu\n", param1);
return 0;
@@ -925,7 +925,7 @@ union zip_quex_done_ack {

static inline u64 ZIP_QUEX_DONE_ACK(u64 param1)
{
- if (((param1 <= 7)))
+ if (param1 <= 7)
return 0x2200ull + (param1 & 7) * 0x8ull;
pr_err("ZIP_QUEX_DONE_ACK: %llu\n", param1);
return 0;
@@ -950,7 +950,7 @@ union zip_quex_done_ena_w1c {

static inline u64 ZIP_QUEX_DONE_ENA_W1C(u64 param1)
{
- if (((param1 <= 7)))
+ if (param1 <= 7)
return 0x2600ull + (param1 & 7) * 0x8ull;
pr_err("ZIP_QUEX_DONE_ENA_W1C: %llu\n", param1);
return 0;
@@ -975,7 +975,7 @@ union zip_quex_done_ena_w1s {

static inline u64 ZIP_QUEX_DONE_ENA_W1S(u64 param1)
{
- if (((param1 <= 7)))
+ if (param1 <= 7)
return 0x2400ull + (param1 & 7) * 0x8ull;
pr_err("ZIP_QUEX_DONE_ENA_W1S: %llu\n", param1);
return 0;
@@ -1004,7 +1004,7 @@ union zip_quex_done_wait {

static inline u64 ZIP_QUEX_DONE_WAIT(u64 param1)
{
- if (((param1 <= 7)))
+ if (param1 <= 7)
return 0x2800ull + (param1 & 7) * 0x8ull;
pr_err("ZIP_QUEX_DONE_WAIT: %llu\n", param1);
return 0;
@@ -1029,7 +1029,7 @@ union zip_quex_doorbell {

static inline u64 ZIP_QUEX_DOORBELL(u64 param1)
{
- if (((param1 <= 7)))
+ if (param1 <= 7)
return 0x4000ull + (param1 & 7) * 0x8ull;
pr_err("ZIP_QUEX_DOORBELL: %llu\n", param1);
return 0;
@@ -1058,7 +1058,7 @@ union zip_quex_err_ena_w1c {

static inline u64 ZIP_QUEX_ERR_ENA_W1C(u64 param1)
{
- if (((param1 <= 7)))
+ if (param1 <= 7)
return 0x3600ull + (param1 & 7) * 0x8ull;
pr_err("ZIP_QUEX_ERR_ENA_W1C: %llu\n", param1);
return 0;
@@ -1087,7 +1087,7 @@ union zip_quex_err_ena_w1s {

static inline u64 ZIP_QUEX_ERR_ENA_W1S(u64 param1)
{
- if (((param1 <= 7)))
+ if (param1 <= 7)
return 0x3400ull + (param1 & 7) * 0x8ull;
pr_err("ZIP_QUEX_ERR_ENA_W1S: %llu\n", param1);
return 0;
@@ -1120,7 +1120,7 @@ union zip_quex_err_int {

static inline u64 ZIP_QUEX_ERR_INT(u64 param1)
{
- if (((param1 <= 7)))
+ if (param1 <= 7)
return 0x3000ull + (param1 & 7) * 0x8ull;
pr_err("ZIP_QUEX_ERR_INT: %llu\n", param1);
return 0;
@@ -1150,7 +1150,7 @@ union zip_quex_err_int_w1s {

static inline u64 ZIP_QUEX_ERR_INT_W1S(u64 param1)
{
- if (((param1 <= 7)))
+ if (param1 <= 7)
return 0x3200ull + (param1 & 7) * 0x8ull;
pr_err("ZIP_QUEX_ERR_INT_W1S: %llu\n", param1);
return 0;
@@ -1179,7 +1179,7 @@ union zip_quex_gcfg {

static inline u64 ZIP_QUEX_GCFG(u64 param1)
{
- if (((param1 <= 7)))
+ if (param1 <= 7)
return 0x1A00ull + (param1 & 7) * 0x8ull;
pr_err("ZIP_QUEX_GCFG: %llu\n", param1);
return 0;
@@ -1204,7 +1204,7 @@ union zip_quex_map {

static inline u64 ZIP_QUEX_MAP(u64 param1)
{
- if (((param1 <= 7)))
+ if (param1 <= 7)
return 0x1400ull + (param1 & 7) * 0x8ull;
pr_err("ZIP_QUEX_MAP: %llu\n", param1);
return 0;
@@ -1236,7 +1236,7 @@ union zip_quex_sbuf_addr {

static inline u64 ZIP_QUEX_SBUF_ADDR(u64 param1)
{
- if (((param1 <= 7)))
+ if (param1 <= 7)
return 0x1000ull + (param1 & 7) * 0x8ull;
pr_err("ZIP_QUEX_SBUF_ADDR: %llu\n", param1);
return 0;
@@ -1276,7 +1276,7 @@ union zip_quex_sbuf_ctl {

static inline u64 ZIP_QUEX_SBUF_CTL(u64 param1)
{
- if (((param1 <= 7)))
+ if (param1 <= 7)
return 0x1200ull + (param1 & 7) * 0x8ull;
pr_err("ZIP_QUEX_SBUF_CTL: %llu\n", param1);
return 0;
--
2.14.3



2018-03-28 18:12:32

by Joe Perches

[permalink] [raw]
Subject: Re: [PATCH] crypto: cavium: zip: Remove unnecessary parentheses

On Wed, 2018-03-28 at 23:27 +0530, Varsha Rao wrote:
> This patch fixes the clang warning of extraneous parentheses, with the
> following coccinelle script.
>
> @@
> identifier i;
> constant c;
> @@
> (
> -((i == c))
> +i == c
> >
>
> -((i <= c))
> +i <= c

Why just the "==" and "<=" cases?
Why not "<", ">" and ">=" too?

Why not expression instead of constant?


2018-03-29 15:35:50

by Varsha Rao

[permalink] [raw]
Subject: Re: [PATCH] crypto: cavium: zip: Remove unnecessary parentheses

On Wed, Mar 28, 2018 at 11:41 PM, Joe Perches wrote:
>
> On Wed, 2018-03-28 at 23:27, Varsha Rao wrote:
> > This patch fixes the clang warning of extraneous parentheses, with the
> > following coccinelle script.
> >
> > @@
> > identifier i;
> > constant c;
> > @@
> > (
> > -((i == c))
> > +i == c
> > >
> >
> > -((i <= c))
> > +i <= c
>
> Why just the "==" and "<=" cases?
> Why not "<", ">" and ">=" too?
>
> Why not expression instead of constant?

Initially I had the other cases too and used expression instead of
constant. But the results included only "==" and "<=" cases with
constant. Along with one false positive case.

--- a/drivers/crypto/cavium/zip/zip_main.c
+++ b/drivers/crypto/cavium/zip/zip_main.c
@@ -99,7 +99,7 @@ static struct zip_device *zip_alloc_devi
*/
struct zip_device *zip_get_device(int node)
{
- if ((node < MAX_ZIP_DEVICES) && (node >= 0))
+ if (node < MAX_ZIP_DEVICES && node >= 0)
return zip_dev[node];

zip_err("ZIP device not found for node id %d\n", node);

I checked if there was any case of extra parentheses around relational
operators left, but there were none. Hence, in the script I included
only the cases present in the result.

Thanks,
Varsha

2018-03-30 20:19:17

by Joe Perches

[permalink] [raw]
Subject: Re: [PATCH] crypto: cavium: zip: Remove unnecessary parentheses

On Thu, 2018-03-29 at 21:03 +0530, Varsha Rao wrote:
> On Wed, Mar 28, 2018 at 11:41 PM, Joe Perches wrote:
> >
> > On Wed, 2018-03-28 at 23:27, Varsha Rao wrote:
> > > This patch fixes the clang warning of extraneous parentheses, with the
> > > following coccinelle script.
> > >
> > > @@
> > > identifier i;
> > > constant c;
> > > @@
> > > (
> > > -((i == c))
> > > +i == c
> > > >
> > >
> > > -((i <= c))
> > > +i <= c
> >
> > Why just the "==" and "<=" cases?
> > Why not "<", ">" and ">=" too?
> >
> > Why not expression instead of constant?
>
> Initially I had the other cases too and used expression instead of
> constant. But the results included only "==" and "<=" cases with
> constant. Along with one false positive case.
hmm
Perhaps you should use something like this?
@@
identifier i;
constant c;
@@

-(
\(i == c\|i <= c\|i < c\|i >= c\|i > c\)
-)


2018-03-31 06:18:57

by Julia Lawall

[permalink] [raw]
Subject: Re: [Cocci] [PATCH] crypto: cavium: zip: Remove unnecessary parentheses



On Fri, 30 Mar 2018, Joe Perches wrote:

> On Thu, 2018-03-29 at 21:03 +0530, Varsha Rao wrote:
> > On Wed, Mar 28, 2018 at 11:41 PM, Joe Perches wrote:
> > >
> > > On Wed, 2018-03-28 at 23:27, Varsha Rao wrote:
> > > > This patch fixes the clang warning of extraneous parentheses, with the
> > > > following coccinelle script.
> > > >
> > > > @@
> > > > identifier i;
> > > > constant c;
> > > > @@
> > > > (
> > > > -((i == c))
> > > > +i == c
> > > > >
> > > >
> > > > -((i <= c))
> > > > +i <= c
> > >
> > > Why just the "==" and "<=" cases?
> > > Why not "<", ">" and ">=" too?
> > >
> > > Why not expression instead of constant?
> >
> > Initially I had the other cases too and used expression instead of
> > constant. But the results included only "==" and "<=" cases with
> > constant. Along with one false positive case.
> hmm
> Perhaps you should use something like this?
> @@
> identifier i;
> constant c;
> @@
>
> -(
> \(i == c\|i <= c\|i < c\|i >= c\|i > c\)
> -)

This is not safe with respect to !. The following seems to address this
problem:

@@
identifier i;
constant c;
expression e;
@@

(
!(e)
|
-(
\(i == c\|i <= c\|i < c\|i >= c\|i > c\)
-)
)

julia

2018-03-31 06:19:25

by Julia Lawall

[permalink] [raw]
Subject: Re: [Cocci] [PATCH] crypto: cavium: zip: Remove unnecessary parentheses



On Thu, 29 Mar 2018, Varsha Rao wrote:

> On Wed, Mar 28, 2018 at 11:41 PM, Joe Perches wrote:
> >
> > On Wed, 2018-03-28 at 23:27, Varsha Rao wrote:
> > > This patch fixes the clang warning of extraneous parentheses, with the
> > > following coccinelle script.
> > >
> > > @@
> > > identifier i;
> > > constant c;
> > > @@
> > > (
> > > -((i == c))
> > > +i == c
> > > >
> > >
> > > -((i <= c))
> > > +i <= c
> >
> > Why just the "==" and "<=" cases?
> > Why not "<", ">" and ">=" too?
> >
> > Why not expression instead of constant?
>
> Initially I had the other cases too and used expression instead of
> constant. But the results included only "==" and "<=" cases with
> constant. Along with one false positive case.
>
> --- a/drivers/crypto/cavium/zip/zip_main.c
> +++ b/drivers/crypto/cavium/zip/zip_main.c
> @@ -99,7 +99,7 @@ static struct zip_device *zip_alloc_devi
> */
> struct zip_device *zip_get_device(int node)
> {
> - if ((node < MAX_ZIP_DEVICES) && (node >= 0))
> + if (node < MAX_ZIP_DEVICES && node >= 0)

Why is it a false positive?

julia

> return zip_dev[node];
>
> zip_err("ZIP device not found for node id %d\n", node);
>
> I checked if there was any case of extra parentheses around relational
> operators left, but there were none. Hence, in the script I included
> only the cases present in the result.
>
> Thanks,
> Varsha
> _______________________________________________
> Cocci mailing list
> [email protected]
> https://systeme.lip6.fr/mailman/listinfo/cocci
>

2018-03-31 08:50:51

by Varsha Rao

[permalink] [raw]
Subject: Re: [Cocci] [PATCH] crypto: cavium: zip: Remove unnecessary parentheses

On Sat, Mar 31, 2018 at 11:48 AM, Julia Lawall wrote:
> On Thu, 29 Mar 2018, Varsha Rao wrote:
>
>> On Wed, Mar 28, 2018 at 11:41 PM, Joe Perches wrote:
>> >
>> > On Wed, 2018-03-28 at 23:27, Varsha Rao wrote:
>> > > This patch fixes the clang warning of extraneous parentheses, with the
>> > > following coccinelle script.
>> > >
>> > > @@
>> > > identifier i;
>> > > constant c;
>> > > @@
>> > > (
>> > > -((i == c))
>> > > +i == c
>> > > >
>> > >
>> > > -((i <= c))
>> > > +i <= c
>> >
>> > Why just the "==" and "<=" cases?
>> > Why not "<", ">" and ">=" too?
>> >
>> > Why not expression instead of constant?
>>
>> Initially I had the other cases too and used expression instead of
>> constant. But the results included only "==" and "<=" cases with
>> constant. Along with one false positive case.
>>
>> --- a/drivers/crypto/cavium/zip/zip_main.c
>> +++ b/drivers/crypto/cavium/zip/zip_main.c
>> @@ -99,7 +99,7 @@ static struct zip_device *zip_alloc_devi
>> */
>> struct zip_device *zip_get_device(int node)
>> {
>> - if ((node < MAX_ZIP_DEVICES) && (node >= 0))
>> + if (node < MAX_ZIP_DEVICES && node >= 0)
>
> Why is it a false positive?

The parentheses around multiple expressions in if statement is not
considered extra, right?

Thanks,
Varsha

> julia
>
>> return zip_dev[node];
>>
>> zip_err("ZIP device not found for node id %d\n", node);
>>
>> I checked if there was any case of extra parentheses around relational
>> operators left, but there were none. Hence, in the script I included
>> only the cases present in the result.
>>
>> Thanks,
>> Varsha
>> _______________________________________________
>> Cocci mailing list
>> [email protected]
>> https://systeme.lip6.fr/mailman/listinfo/cocci
>>

2018-03-31 08:57:14

by Julia Lawall

[permalink] [raw]
Subject: Re: [Cocci] [PATCH] crypto: cavium: zip: Remove unnecessary parentheses



On Sat, 31 Mar 2018, Varsha Rao wrote:

> On Sat, Mar 31, 2018 at 11:48 AM, Julia Lawall wrote:
> > On Thu, 29 Mar 2018, Varsha Rao wrote:
> >
> >> On Wed, Mar 28, 2018 at 11:41 PM, Joe Perches wrote:
> >> >
> >> > On Wed, 2018-03-28 at 23:27, Varsha Rao wrote:
> >> > > This patch fixes the clang warning of extraneous parentheses, with the
> >> > > following coccinelle script.
> >> > >
> >> > > @@
> >> > > identifier i;
> >> > > constant c;
> >> > > @@
> >> > > (
> >> > > -((i == c))
> >> > > +i == c
> >> > > >
> >> > >
> >> > > -((i <= c))
> >> > > +i <= c
> >> >
> >> > Why just the "==" and "<=" cases?
> >> > Why not "<", ">" and ">=" too?
> >> >
> >> > Why not expression instead of constant?
> >>
> >> Initially I had the other cases too and used expression instead of
> >> constant. But the results included only "==" and "<=" cases with
> >> constant. Along with one false positive case.
> >>
> >> --- a/drivers/crypto/cavium/zip/zip_main.c
> >> +++ b/drivers/crypto/cavium/zip/zip_main.c
> >> @@ -99,7 +99,7 @@ static struct zip_device *zip_alloc_devi
> >> */
> >> struct zip_device *zip_get_device(int node)
> >> {
> >> - if ((node < MAX_ZIP_DEVICES) && (node >= 0))
> >> + if (node < MAX_ZIP_DEVICES && node >= 0)
> >
> > Why is it a false positive?
>
> The parentheses around multiple expressions in if statement is not
> considered extra, right?

< and >= should bind tighter than &&. But perhaps one could fine the
original code to be more readable.

julia