2014-12-15 15:26:15

by Karthik Nayak

[permalink] [raw]
Subject: [PATCH] Staging: rtl8712: removed an unnecessary else statement

As per checkpatch warning, removed an unnecessary else statement
proceeding an if statement with a return.

Signed-off-by: Karthik Nayak <[email protected]>
---
drivers/staging/rtl8712/rtl8712_recv.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/staging/rtl8712/rtl8712_recv.c b/drivers/staging/rtl8712/rtl8712_recv.c
index cd8b444..800b2b3 100644
--- a/drivers/staging/rtl8712/rtl8712_recv.c
+++ b/drivers/staging/rtl8712/rtl8712_recv.c
@@ -496,8 +496,7 @@ static int enqueue_reorder_recvframe(struct recv_reorder_ctrl *preorder_ctrl,
plist = plist->next;
else if (SN_EQUAL(pnextattrib->seq_num, pattrib->seq_num))
return false;
- else
- break;
+ break;
}
list_del_init(&(prframe->u.hdr.list));
list_add_tail(&(prframe->u.hdr.list), plist);
--
2.1.3


2014-12-15 16:39:13

by Joe Perches

[permalink] [raw]
Subject: Re: [PATCH] Staging: rtl8712: removed an unnecessary else statement

On Mon, 2014-12-15 at 20:55 +0530, Karthik Nayak wrote:
> As per checkpatch warning, removed an unnecessary else statement
> proceeding an if statement with a return.

This is not a correct change.
The checkpatch message said "generally".
You still have to verify the code.

> diff --git a/drivers/staging/rtl8712/rtl8712_recv.c b/drivers/staging/rtl8712/rtl8712_recv.c
> index cd8b444..800b2b3 100644
> --- a/drivers/staging/rtl8712/rtl8712_recv.c
> +++ b/drivers/staging/rtl8712/rtl8712_recv.c
> @@ -496,8 +496,7 @@ static int enqueue_reorder_recvframe(struct recv_reorder_ctrl *preorder_ctrl,
> plist = plist->next;
> else if (SN_EQUAL(pnextattrib->seq_num, pattrib->seq_num))
> return false;
> - else
> - break;
> + break;


It's not the same logic.
It would be if the code was:

while (end_of_queue_search(phead, plist) == false) {
pnextrframe = LIST_CONTAINOR(plist, union recv_frame, u);
pnextattrib = &pnextrframe->u.hdr.attrib;
if (SN_LESS(pnextattrib->seq_num, pattrib->seq_num)) {
plist = plist->next;
continue;
} else if (SN_EQUAL(pnextattrib->seq_num, pattrib->seq_num)) {
return false;
}
break;
}

But that's not necessary.

2014-12-15 17:12:43

by Larry Finger

[permalink] [raw]
Subject: Re: [PATCH] Staging: rtl8712: removed an unnecessary else statement

On 12/15/2014 10:39 AM, Joe Perches wrote:
> On Mon, 2014-12-15 at 20:55 +0530, Karthik Nayak wrote:
>> As per checkpatch warning, removed an unnecessary else statement
>> proceeding an if statement with a return.
>
> This is not a correct change.
> The checkpatch message said "generally".
> You still have to verify the code.
>
>> diff --git a/drivers/staging/rtl8712/rtl8712_recv.c b/drivers/staging/rtl8712/rtl8712_recv.c
>> index cd8b444..800b2b3 100644
>> --- a/drivers/staging/rtl8712/rtl8712_recv.c
>> +++ b/drivers/staging/rtl8712/rtl8712_recv.c
>> @@ -496,8 +496,7 @@ static int enqueue_reorder_recvframe(struct recv_reorder_ctrl *preorder_ctrl,
>> plist = plist->next;
>> else if (SN_EQUAL(pnextattrib->seq_num, pattrib->seq_num))
>> return false;
>> - else
>> - break;
>> + break;
>
>
> It's not the same logic.
> It would be if the code was:
>
> while (end_of_queue_search(phead, plist) == false) {
> pnextrframe = LIST_CONTAINOR(plist, union recv_frame, u);
> pnextattrib = &pnextrframe->u.hdr.attrib;
> if (SN_LESS(pnextattrib->seq_num, pattrib->seq_num)) {
> plist = plist->next;
> continue;
> } else if (SN_EQUAL(pnextattrib->seq_num, pattrib->seq_num)) {
> return false;
> }
> break;
> }
>
> But that's not necessary.

I have almost been tripped by this warning when the code said

if (...) {
.......
} else if (...) {
.......
return;
} else {
.......
}

Perhaps checkpatch should ignore setting this warning when there is an "else if"
in the flow.

Larry

2014-12-15 17:27:17

by Joe Perches

[permalink] [raw]
Subject: Re: [PATCH] Staging: rtl8712: removed an unnecessary else statement

On Mon, 2014-12-15 at 11:12 -0600, Larry Finger wrote:
> On 12/15/2014 10:39 AM, Joe Perches wrote:
> > On Mon, 2014-12-15 at 20:55 +0530, Karthik Nayak wrote:
> >> As per checkpatch warning, removed an unnecessary else statement
> >> proceeding an if statement with a return.
> >
> > This is not a correct change.
> > The checkpatch message said "generally".
> > You still have to verify the code.
[]
> Perhaps checkpatch should ignore setting this warning when there is an "else if"
> in the flow.

In a patch, that's not possible as the
context may not show the flow.