2022-03-28 22:10:18

by Guo Zhengkui

[permalink] [raw]
Subject: [PATCH linux-next] RDMA: simplify if-if to if-else

`if (!ret)` can be replaced with `else` for simplification.

Signed-off-by: Guo Zhengkui <[email protected]>
---
drivers/infiniband/hw/irdma/puda.c | 4 ++--
drivers/infiniband/hw/mlx4/mcg.c | 3 +--
2 files changed, 3 insertions(+), 4 deletions(-)

diff --git a/drivers/infiniband/hw/irdma/puda.c b/drivers/infiniband/hw/irdma/puda.c
index 397f3d070f90..ee91424eb94a 100644
--- a/drivers/infiniband/hw/irdma/puda.c
+++ b/drivers/infiniband/hw/irdma/puda.c
@@ -842,7 +842,7 @@ static void irdma_puda_free_qp(struct irdma_puda_rsrc *rsrc)
ibdev_dbg(to_ibdev(dev),
"PUDA: error puda qp destroy wqe, status = %d\n",
ret);
- if (!ret) {
+ else {
ret = irdma_sc_poll_for_cqp_op_done(dev->cqp, IRDMA_CQP_OP_DESTROY_QP,
&compl_info);
if (ret)
@@ -871,7 +871,7 @@ static void irdma_puda_free_cq(struct irdma_puda_rsrc *rsrc)
ret = irdma_sc_cq_destroy(&rsrc->cq, 0, true);
if (ret)
ibdev_dbg(to_ibdev(dev), "PUDA: error ieq cq destroy\n");
- if (!ret) {
+ else {
ret = irdma_sc_poll_for_cqp_op_done(dev->cqp, IRDMA_CQP_OP_DESTROY_CQ,
&compl_info);
if (ret)
diff --git a/drivers/infiniband/hw/mlx4/mcg.c b/drivers/infiniband/hw/mlx4/mcg.c
index 33f525b744f2..a8c8d432d0dc 100644
--- a/drivers/infiniband/hw/mlx4/mcg.c
+++ b/drivers/infiniband/hw/mlx4/mcg.c
@@ -304,9 +304,8 @@ static int send_leave_to_wire(struct mcast_group *group, u8 join_state)
ret = send_mad_to_wire(group->demux, (struct ib_mad *)&mad);
if (ret)
group->state = MCAST_IDLE;
-
/* set timeout handler */
- if (!ret) {
+ else {
/* calls mlx4_ib_mcg_timeout_handler */
queue_delayed_work(group->demux->mcg_wq, &group->timeout_work,
msecs_to_jiffies(MAD_TIMEOUT_MS));
--
2.20.1


2022-03-30 12:38:01

by Leon Romanovsky

[permalink] [raw]
Subject: Re: [PATCH linux-next] RDMA: simplify if-if to if-else

On Mon, Mar 28, 2022 at 09:08:59PM +0800, Guo Zhengkui wrote:
> `if (!ret)` can be replaced with `else` for simplification.
>
> Signed-off-by: Guo Zhengkui <[email protected]>
> ---
> drivers/infiniband/hw/irdma/puda.c | 4 ++--
> drivers/infiniband/hw/mlx4/mcg.c | 3 +--
> 2 files changed, 3 insertions(+), 4 deletions(-)
>

Thanks,
Reviewed-by: Leon Romanovsky <[email protected]>

2022-03-31 02:53:01

by Leon Romanovsky

[permalink] [raw]
Subject: Re: [PATCH linux-next] RDMA: simplify if-if to if-else

On Wed, Mar 30, 2022 at 12:26:51PM +0000, Haakon Bugge wrote:
>
>
> > On 30 Mar 2022, at 13:32, Leon Romanovsky <[email protected]> wrote:
> >
> > On Wed, Mar 30, 2022 at 11:06:03AM +0000, Haakon Bugge wrote:
> >>
> >>
> >>> On 30 Mar 2022, at 13:02, Leon Romanovsky <[email protected]> wrote:
> >>>
> >>> On Mon, Mar 28, 2022 at 09:08:59PM +0800, Guo Zhengkui wrote:
> >>>> `if (!ret)` can be replaced with `else` for simplification.
> >>>>
> >>>> Signed-off-by: Guo Zhengkui <[email protected]>
> >>>> ---
> >>>> drivers/infiniband/hw/irdma/puda.c | 4 ++--
> >>>> drivers/infiniband/hw/mlx4/mcg.c | 3 +--
> >>>> 2 files changed, 3 insertions(+), 4 deletions(-)
> >>>>
> >>>
> >>> Thanks,
> >>> Reviewed-by: Leon Romanovsky <[email protected]>
> >>
> >> Fix the unbalanced curly brackets at the same time?
> >
> > I think that it is ok to have if () ... else { ... } code.
>
>
> Hmm, doesn't the kernel coding style say:
>
> "Do not unnecessarily use braces where a single statement will do."
>
> [snip]
>
> "This does not apply if only one branch of a conditional statement is a single statement; in the latter case use braces in both branches"

ok, if it is written in documentation, let's follow it.

Thanks for pointing that out.

>
>
> Thxs, H?kon
>
>
> >
> > There is one place that needs an indentation fix, in mlx4, but it is
> > faster to fix when applying the patch instead of asking to resubmit.
> >
> > thanks
> >
> >>
> >>
> >> Thxs, H?kon
>

2022-03-31 03:12:17

by Leon Romanovsky

[permalink] [raw]
Subject: Re: [PATCH linux-next] RDMA: simplify if-if to if-else

On Wed, Mar 30, 2022 at 11:06:03AM +0000, Haakon Bugge wrote:
>
>
> > On 30 Mar 2022, at 13:02, Leon Romanovsky <[email protected]> wrote:
> >
> > On Mon, Mar 28, 2022 at 09:08:59PM +0800, Guo Zhengkui wrote:
> >> `if (!ret)` can be replaced with `else` for simplification.
> >>
> >> Signed-off-by: Guo Zhengkui <[email protected]>
> >> ---
> >> drivers/infiniband/hw/irdma/puda.c | 4 ++--
> >> drivers/infiniband/hw/mlx4/mcg.c | 3 +--
> >> 2 files changed, 3 insertions(+), 4 deletions(-)
> >>
> >
> > Thanks,
> > Reviewed-by: Leon Romanovsky <[email protected]>
>
> Fix the unbalanced curly brackets at the same time?

I think that it is ok to have if () ... else { ... } code.

There is one place that needs an indentation fix, in mlx4, but it is
faster to fix when applying the patch instead of asking to resubmit.

thanks

>
>
> Thxs, H?kon
>
>

2022-03-31 03:22:12

by Haakon Bugge

[permalink] [raw]
Subject: Re: [PATCH linux-next] RDMA: simplify if-if to if-else



> On 30 Mar 2022, at 13:32, Leon Romanovsky <[email protected]> wrote:
>
> On Wed, Mar 30, 2022 at 11:06:03AM +0000, Haakon Bugge wrote:
>>
>>
>>> On 30 Mar 2022, at 13:02, Leon Romanovsky <[email protected]> wrote:
>>>
>>> On Mon, Mar 28, 2022 at 09:08:59PM +0800, Guo Zhengkui wrote:
>>>> `if (!ret)` can be replaced with `else` for simplification.
>>>>
>>>> Signed-off-by: Guo Zhengkui <[email protected]>
>>>> ---
>>>> drivers/infiniband/hw/irdma/puda.c | 4 ++--
>>>> drivers/infiniband/hw/mlx4/mcg.c | 3 +--
>>>> 2 files changed, 3 insertions(+), 4 deletions(-)
>>>>
>>>
>>> Thanks,
>>> Reviewed-by: Leon Romanovsky <[email protected]>
>>
>> Fix the unbalanced curly brackets at the same time?
>
> I think that it is ok to have if () ... else { ... } code.


Hmm, doesn't the kernel coding style say:

"Do not unnecessarily use braces where a single statement will do."

[snip]

"This does not apply if only one branch of a conditional statement is a single statement; in the latter case use braces in both branches"


Thxs, Håkon


>
> There is one place that needs an indentation fix, in mlx4, but it is
> faster to fix when applying the patch instead of asking to resubmit.
>
> thanks
>
>>
>>
>> Thxs, Håkon

2022-03-31 03:53:18

by Haakon Bugge

[permalink] [raw]
Subject: Re: [PATCH linux-next] RDMA: simplify if-if to if-else



> On 30 Mar 2022, at 13:02, Leon Romanovsky <[email protected]> wrote:
>
> On Mon, Mar 28, 2022 at 09:08:59PM +0800, Guo Zhengkui wrote:
>> `if (!ret)` can be replaced with `else` for simplification.
>>
>> Signed-off-by: Guo Zhengkui <[email protected]>
>> ---
>> drivers/infiniband/hw/irdma/puda.c | 4 ++--
>> drivers/infiniband/hw/mlx4/mcg.c | 3 +--
>> 2 files changed, 3 insertions(+), 4 deletions(-)
>>
>
> Thanks,
> Reviewed-by: Leon Romanovsky <[email protected]>

Fix the unbalanced curly brackets at the same time?


Thxs, Håkon


2022-03-31 05:10:16

by Guo Zhengkui

[permalink] [raw]
Subject: Re: [PATCH linux-next] RDMA: simplify if-if to if-else

On 2022/3/30 20:56, Leon Romanovsky wrote:
> On Wed, Mar 30, 2022 at 12:26:51PM +0000, Haakon Bugge wrote:
>>
>>
>>> On 30 Mar 2022, at 13:32, Leon Romanovsky <[email protected]> wrote:
>>>
>>> On Wed, Mar 30, 2022 at 11:06:03AM +0000, Haakon Bugge wrote:
>>>>
>>>>
>>>>> On 30 Mar 2022, at 13:02, Leon Romanovsky <[email protected]> wrote:
>>>>>
>>>>> On Mon, Mar 28, 2022 at 09:08:59PM +0800, Guo Zhengkui wrote:
>>>>>> `if (!ret)` can be replaced with `else` for simplification.
>>>>>>
>>>>>> Signed-off-by: Guo Zhengkui <[email protected]>
>>>>>> ---
>>>>>> drivers/infiniband/hw/irdma/puda.c | 4 ++--
>>>>>> drivers/infiniband/hw/mlx4/mcg.c | 3 +--
>>>>>> 2 files changed, 3 insertions(+), 4 deletions(-)
>>>>>>
>>>>>
>>>>> Thanks,
>>>>> Reviewed-by: Leon Romanovsky <[email protected]>
>>>>
>>>> Fix the unbalanced curly brackets at the same time?
>>>
>>> I think that it is ok to have if () ... else { ... } code.
>>
>>
>> Hmm, doesn't the kernel coding style say:
>>
>> "Do not unnecessarily use braces where a single statement will do."
>>
>> [snip]
>>
>> "This does not apply if only one branch of a conditional statement is a single statement; in the latter case use braces in both branches"
>
> ok, if it is written in documentation, let's follow it.
>
> Thanks for pointing that out.

Should I resubmit the patch including unbalanced curly brackets fixing?
If not, I can submit another patch to fix this problem.

>
>>
>>
>> Thxs, Håkon
>>
>>
>>>
>>> There is one place that needs an indentation fix, in mlx4, but it is
>>> faster to fix when applying the patch instead of asking to resubmit.
>>>
>>> thanks
>>>
>>>>
>>>>
>>>> Thxs, Håkon
>>

Thanks,

Zhengkui

2022-03-31 09:21:31

by Leon Romanovsky

[permalink] [raw]
Subject: Re: [PATCH linux-next] RDMA: simplify if-if to if-else

On Thu, Mar 31, 2022 at 11:03:30AM +0800, Guo Zhengkui wrote:
> On 2022/3/30 20:56, Leon Romanovsky wrote:
> > On Wed, Mar 30, 2022 at 12:26:51PM +0000, Haakon Bugge wrote:
> > >
> > >
> > > > On 30 Mar 2022, at 13:32, Leon Romanovsky <[email protected]> wrote:
> > > >
> > > > On Wed, Mar 30, 2022 at 11:06:03AM +0000, Haakon Bugge wrote:
> > > > >
> > > > >
> > > > > > On 30 Mar 2022, at 13:02, Leon Romanovsky <[email protected]> wrote:
> > > > > >
> > > > > > On Mon, Mar 28, 2022 at 09:08:59PM +0800, Guo Zhengkui wrote:
> > > > > > > `if (!ret)` can be replaced with `else` for simplification.
> > > > > > >
> > > > > > > Signed-off-by: Guo Zhengkui <[email protected]>
> > > > > > > ---
> > > > > > > drivers/infiniband/hw/irdma/puda.c | 4 ++--
> > > > > > > drivers/infiniband/hw/mlx4/mcg.c | 3 +--
> > > > > > > 2 files changed, 3 insertions(+), 4 deletions(-)
> > > > > > >
> > > > > >
> > > > > > Thanks,
> > > > > > Reviewed-by: Leon Romanovsky <[email protected]>
> > > > >
> > > > > Fix the unbalanced curly brackets at the same time?
> > > >
> > > > I think that it is ok to have if () ... else { ... } code.
> > >
> > >
> > > Hmm, doesn't the kernel coding style say:
> > >
> > > "Do not unnecessarily use braces where a single statement will do."
> > >
> > > [snip]
> > >
> > > "This does not apply if only one branch of a conditional statement is a single statement; in the latter case use braces in both branches"
> >
> > ok, if it is written in documentation, let's follow it.
> >
> > Thanks for pointing that out.
>
> Should I resubmit the patch including unbalanced curly brackets fixing? If
> not, I can submit another patch to fix this problem.

Your patch wasn't merged yet, so new version should be sent.

Thanks
>
> >
> > >
> > >
> > > Thxs, H?kon
> > >
> > >
> > > >
> > > > There is one place that needs an indentation fix, in mlx4, but it is
> > > > faster to fix when applying the patch instead of asking to resubmit.
> > > >
> > > > thanks
> > > >
> > > > >
> > > > >
> > > > > Thxs, H?kon
> > >
>
> Thanks,
>
> Zhengkui

2022-03-31 15:33:25

by Guo Zhengkui

[permalink] [raw]
Subject: [PATCH linux-next v2] RDMA: simplify if-if to if-else

Replace `if (!ret)` with `else` for simplification and
fix the unbalanced curly brackets.

Signed-off-by: Guo Zhengkui <[email protected]>
---
drivers/infiniband/hw/irdma/puda.c | 8 ++++----
drivers/infiniband/hw/mlx4/mcg.c | 29 +++++++++++++++++------------
2 files changed, 21 insertions(+), 16 deletions(-)

diff --git a/drivers/infiniband/hw/irdma/puda.c b/drivers/infiniband/hw/irdma/puda.c
index 397f3d070f90..8dd38e1f6cf0 100644
--- a/drivers/infiniband/hw/irdma/puda.c
+++ b/drivers/infiniband/hw/irdma/puda.c
@@ -838,11 +838,11 @@ static void irdma_puda_free_qp(struct irdma_puda_rsrc *rsrc)
}

ret = irdma_sc_qp_destroy(&rsrc->qp, 0, false, true, true);
- if (ret)
+ if (ret) {
ibdev_dbg(to_ibdev(dev),
"PUDA: error puda qp destroy wqe, status = %d\n",
ret);
- if (!ret) {
+ } else {
ret = irdma_sc_poll_for_cqp_op_done(dev->cqp, IRDMA_CQP_OP_DESTROY_QP,
&compl_info);
if (ret)
@@ -869,9 +869,9 @@ static void irdma_puda_free_cq(struct irdma_puda_rsrc *rsrc)
}

ret = irdma_sc_cq_destroy(&rsrc->cq, 0, true);
- if (ret)
+ if (ret) {
ibdev_dbg(to_ibdev(dev), "PUDA: error ieq cq destroy\n");
- if (!ret) {
+ } else {
ret = irdma_sc_poll_for_cqp_op_done(dev->cqp, IRDMA_CQP_OP_DESTROY_CQ,
&compl_info);
if (ret)
diff --git a/drivers/infiniband/hw/mlx4/mcg.c b/drivers/infiniband/hw/mlx4/mcg.c
index 33f525b744f2..c0beb9f4030a 100644
--- a/drivers/infiniband/hw/mlx4/mcg.c
+++ b/drivers/infiniband/hw/mlx4/mcg.c
@@ -304,13 +304,11 @@ static int send_leave_to_wire(struct mcast_group *group, u8 join_state)
ret = send_mad_to_wire(group->demux, (struct ib_mad *)&mad);
if (ret)
group->state = MCAST_IDLE;
-
/* set timeout handler */
- if (!ret) {
+ else
/* calls mlx4_ib_mcg_timeout_handler */
queue_delayed_work(group->demux->mcg_wq, &group->timeout_work,
msecs_to_jiffies(MAD_TIMEOUT_MS));
- }

return ret;
}
@@ -561,8 +559,9 @@ static void mlx4_ib_mcg_timeout_handler(struct work_struct *work)
return;
}
mutex_lock(&group->lock);
- } else
+ } else {
mcg_warn_group(group, "DRIVER BUG\n");
+ }
} else if (group->state == MCAST_LEAVE_SENT) {
if (group->rec.scope_join_state & 0xf)
group->rec.scope_join_state &= 0xf0;
@@ -571,8 +570,9 @@ static void mlx4_ib_mcg_timeout_handler(struct work_struct *work)
if (release_group(group, 1))
return;
mutex_lock(&group->lock);
- } else
+ } else {
mcg_warn_group(group, "invalid state %s\n", get_state_string(group->state));
+ }
group->state = MCAST_IDLE;
atomic_inc(&group->refcount);
if (!queue_work(group->demux->mcg_wq, &group->work))
@@ -632,7 +632,7 @@ static int handle_join_req(struct mcast_group *group, u8 join_mask,
kfree(req);
ref = 1;
group->state = group->prev_state;
- } else
+ } else {
group->state = MCAST_JOIN_SENT;
}

@@ -681,10 +681,12 @@ static void mlx4_ib_mcg_work_handler(struct work_struct *work)
list_del(&req->func_list);
kfree(req);
++rc;
- } else
+ } else {
mcg_warn_group(group, "no request for failed join\n");
- } else if (method == IB_SA_METHOD_DELETE_RESP && group->demux->flushing)
+ }
+ } else if (method == IB_SA_METHOD_DELETE_RESP && group->demux->flushing) {
++rc;
+ }
} else {
u8 resp_join_state;
u8 cur_join_state;
@@ -697,8 +699,9 @@ static void mlx4_ib_mcg_work_handler(struct work_struct *work)
/* successfull join */
if (!cur_join_state && resp_join_state)
--rc;
- } else if (!resp_join_state)
- ++rc;
+ } else if (!resp_join_state) {
+ ++rc;
+ }
memcpy(&group->rec, group->response_sa_mad.data, sizeof group->rec);
}
group->state = MCAST_IDLE;
@@ -730,8 +733,9 @@ static void mlx4_ib_mcg_work_handler(struct work_struct *work)
if (send_leave_to_wire(group, req_join_state)) {
group->state = group->prev_state;
++rc;
- } else
+ } else {
group->state = MCAST_LEAVE_SENT;
+ }
}
}

@@ -898,8 +902,9 @@ int mlx4_ib_mcg_demux_handler(struct ib_device *ibdev, int port, int slave,
__be64 tid = mad->mad_hdr.tid;
*(u8 *)(&tid) = (u8)slave; /* in group we kept the modified TID */
group = search_relocate_mgid0_group(ctx, tid, &rec->mgid);
- } else
+ } else {
group = NULL;
+ }
}

if (!group)
--
2.20.1

2022-04-01 10:46:33

by Saleem, Shiraz

[permalink] [raw]
Subject: RE: [PATCH linux-next v2] RDMA: simplify if-if to if-else

> Subject: [PATCH linux-next v2] RDMA: simplify if-if to if-else
>
> Replace `if (!ret)` with `else` for simplification and fix the unbalanced curly
> brackets.
>
> Signed-off-by: Guo Zhengkui <[email protected]>
> ---
> drivers/infiniband/hw/irdma/puda.c | 8 ++++----

Acked-by: Shiraz Saleem <[email protected]>

2022-04-05 00:48:47

by Jason Gunthorpe

[permalink] [raw]
Subject: Re: [PATCH linux-next v2] RDMA: simplify if-if to if-else

On Thu, Mar 31, 2022 at 09:05:25PM +0800, Guo Zhengkui wrote:
> @@ -632,7 +632,7 @@ static int handle_join_req(struct mcast_group *group, u8 join_mask,
> kfree(req);
> ref = 1;
> group->state = group->prev_state;
> - } else
> + } else {
> group->state = MCAST_JOIN_SENT;
> }

This doesn't compile.

Jason