Skip to contentSkip to conversation

staging: rtl8188eu: Fix else after return WARNING (checkpatch)

PATCH RESEND In review Sohom Datta 4 participants 6 messages Sep 13, 2020 – Sep 15, 2020 Staging

lore
Share & tools
lore
#0 lore raw

PATCH RESEND 1/1 staging: rtl8188eu: Fix else after return WARNING (checkpatch)

From 4c8c8f3ff7f4d711daea4ac3bb987fcecc7ef1ed Mon Sep 17 00:00:00 2001
From: Sohom <[email protected]>
Date: Sat, 12 Sep 2020 18:04:56 +0530
Subject: [RESEND PATCH] staging: rtl8188eu: Fix else after return WARNING
(checkpatch)

Fixed:
WARNING: else is not generally useful after a break or return 1636: FILE: ./rtw_recv.c:1636:
+ return false;
+ else

Separated the return statement into a separate block since it doesn't seem to depend on the SN_LESS explicity being false.

---
 drivers/staging/rtl8188eu/core/rtw_recv.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/staging/rtl8188eu/core/rtw_recv.c +3 -2
index 5fe7a0458dd2..5e81134ffb6d 100644
@@ -1629,10 +1629,11 @@ static int enqueue_reorder_recvframe(struct recv_reorder_ctrl *preorder_ctrl,
 		hdr = list_entry(plist, struct recv_frame, list);
 		pnextattrib = &hdr->attrib;
 
+		if (SN_EQUAL(pnextattrib->seq_num, pattrib->seq_num))
+			return false;
+
 		if (SN_LESS(pnextattrib->seq_num, pattrib->seq_num))
 			plist = plist->next;
-		else if (SN_EQUAL(pnextattrib->seq_num, pattrib->seq_num))
-			return false;
 		else
 			break;
 	}
Signature · 1 line
2.28.0
#1 lore raw
Quoted 5 lines · Sohom Datta
Quoted 1 line

From 4c8c8f3ff7f4d711daea4ac3bb987fcecc7ef1ed Mon Sep 17 00:00:00 2001

From: Sohom <[email protected]>
Date: Sat, 12 Sep 2020 18:04:56 +0530
Subject: [RESEND PATCH] staging: rtl8188eu: Fix else after return WARNING
(checkpatch)

Why is this in the body of your email?

Just use 'git send-email' to send the patch, no need to include it in the body itself, right?

thanks,

greg k-h

#2 lore raw
In reply to Sohom Datta
Quoted 28 lines · Sohom Datta
Quoted 1 line

From 4c8c8f3ff7f4d711daea4ac3bb987fcecc7ef1ed Mon Sep 17 00:00:00 2001

From: Sohom <[email protected]>
Date: Sat, 12 Sep 2020 18:04:56 +0530
Subject: [RESEND PATCH] staging: rtl8188eu: Fix else after return WARNING
(checkpatch)

Fixed:
WARNING: else is not generally useful after a break or return 1636: FILE: ./rtw_recv.c:1636:

(quoted diff) +2 -0
+           return false;
+       else

Separated the return statement into a separate block since it doesn't seem to depend on the SN_LESS explicity being false.

---
 drivers/staging/rtl8188eu/core/rtw_recv.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/staging/rtl8188eu/core/rtw_recv.c +0 -0
index 5fe7a0458dd2..5e81134ffb6d 100644
@@ -1629,10 +1629,11 @@ static int enqueue_reorder_recvframe(struct recv_reorder_ctrl *preorder_ctrl,
 		hdr = list_entry(plist, struct recv_frame, list);
 		pnextattrib = &hdr->attrib;
 

drivers/staging/rtl8188eu/core/rtw_recv.c static int enqueue_reorder_recvframe(struct recv_reorder_ctrl *preorder_ctrl, · line 1639

Quoted 10 lines
drivers/staging/rtl8188eu/core/rtw_recv.c +3 -2
+		if (SN_EQUAL(pnextattrib->seq_num, pattrib->seq_num))
+			return false;
+
 		if (SN_LESS(pnextattrib->seq_num, pattrib->seq_num))
 			plist = plist->next;
-		else if (SN_EQUAL(pnextattrib->seq_num, pattrib->seq_num))
-			return false;
 		else
 			break;
 	}

Checkpatch is just wrong here. Ignore it when it's wrong.

regards,
dan carpenter

#3 lore raw
Quoted 29 lines · Dan Carpenter
Quoted 28 lines · Sohom Datta
Quoted 1 line

From 4c8c8f3ff7f4d711daea4ac3bb987fcecc7ef1ed Mon Sep 17 00:00:00 2001

From: Sohom <[email protected]>
Date: Sat, 12 Sep 2020 18:04:56 +0530
Subject: [RESEND PATCH] staging: rtl8188eu: Fix else after return WARNING
(checkpatch)

Fixed:
WARNING: else is not generally useful after a break or return 1636: FILE: ./rtw_recv.c:1636:

(quoted diff) +2 -0
+           return false;
+       else

Separated the return statement into a separate block since it doesn't seem to depend on the SN_LESS explicity being false.

---
 drivers/staging/rtl8188eu/core/rtw_recv.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/staging/rtl8188eu/core/rtw_recv.c +0 -0
index 5fe7a0458dd2..5e81134ffb6d 100644
@@ -1629,10 +1629,11 @@ static int enqueue_reorder_recvframe(struct recv_reorder_ctrl *preorder_ctrl,
 		hdr = list_entry(plist, struct recv_frame, list);
 		pnextattrib = &hdr->attrib;
 
Quoted 12 lines

drivers/staging/rtl8188eu/core/rtw_recv.c static int enqueue_reorder_recvframe(struct recv_reorder_ctrl *preorder_ctrl, · line 1639

Quoted 10 lines
drivers/staging/rtl8188eu/core/rtw_recv.c +3 -2
+		if (SN_EQUAL(pnextattrib->seq_num, pattrib->seq_num))
+			return false;
+
 		if (SN_LESS(pnextattrib->seq_num, pattrib->seq_num))
 			plist = plist->next;
-		else if (SN_EQUAL(pnextattrib->seq_num, pattrib->seq_num))
-			return false;
 		else
 			break;
 	}

Checkpatch is just wrong here. Ignore it when it's wrong.

It's not "wrong" here. It's making a suggestion.

Perhaps read the SN_EQUAL and SN_LESS macros.

a and b are both u16's here.

drivers/staging/rtl8188eu/include/rtw_recv.h:#define SN_LESS(a, b) (((a - b) & 0x800) != 0)
drivers/staging/rtl8188eu/include/rtw_recv.h:#define SN_EQUAL(a, b) (a == b)

Reordering works, perhaps it's just a question of
whether it's the most likely result of the test.

This is in a while loop.

If the expected test is really the most likely that SN_LESS is true, then perhaps this loop could be something like:

		if (SN_LESS(pnextattrib->seq_num, pattrib->seq_num)) {
			plist = plist->next;
			continue;
		}
		if (SN_EQUAL(pnextattrib->seq_num, pattrib->seq_num))
			return false;
		break;
	}

The real question is whether or not that's more readable.

#4 lore raw
Quoted 70 lines · Joe Perches
Quoted 29 lines · Dan Carpenter
Quoted 28 lines · Sohom Datta
Quoted 1 line

From 4c8c8f3ff7f4d711daea4ac3bb987fcecc7ef1ed Mon Sep 17 00:00:00 2001

From: Sohom <[email protected]>
Date: Sat, 12 Sep 2020 18:04:56 +0530
Subject: [RESEND PATCH] staging: rtl8188eu: Fix else after return WARNING
(checkpatch)

Fixed:
WARNING: else is not generally useful after a break or return 1636: FILE: ./rtw_recv.c:1636:

(quoted diff) +2 -0
+           return false;
+       else

Separated the return statement into a separate block since it doesn't seem to depend on the SN_LESS explicity being false.

---
 drivers/staging/rtl8188eu/core/rtw_recv.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/staging/rtl8188eu/core/rtw_recv.c +0 -0
index 5fe7a0458dd2..5e81134ffb6d 100644
@@ -1629,10 +1629,11 @@ static int enqueue_reorder_recvframe(struct recv_reorder_ctrl *preorder_ctrl,
 		hdr = list_entry(plist, struct recv_frame, list);
 		pnextattrib = &hdr->attrib;
 
Quoted 12 lines

drivers/staging/rtl8188eu/core/rtw_recv.c static int enqueue_reorder_recvframe(struct recv_reorder_ctrl *preorder_ctrl, · line 1639

Quoted 10 lines
drivers/staging/rtl8188eu/core/rtw_recv.c +3 -2
+		if (SN_EQUAL(pnextattrib->seq_num, pattrib->seq_num))
+			return false;
+
 		if (SN_LESS(pnextattrib->seq_num, pattrib->seq_num))
 			plist = plist->next;
-		else if (SN_EQUAL(pnextattrib->seq_num, pattrib->seq_num))
-			return false;
 		else
 			break;
 	}

Checkpatch is just wrong here. Ignore it when it's wrong.

It's not "wrong" here. It's making a suggestion.

Perhaps read the SN_EQUAL and SN_LESS macros.

a and b are both u16's here.

drivers/staging/rtl8188eu/include/rtw_recv.h:#define SN_LESS(a, b) (((a - b) & 0x800) != 0)
drivers/staging/rtl8188eu/include/rtw_recv.h:#define SN_EQUAL(a, b) (a == b)

Reordering works, perhaps it's just a question of
whether it's the most likely result of the test.

This is in a while loop.

If the expected test is really the most likely that SN_LESS is true, then perhaps this loop could be something like:

		if (SN_LESS(pnextattrib->seq_num, pattrib->seq_num)) {
			plist = plist->next;
			continue;
		}
		if (SN_EQUAL(pnextattrib->seq_num, pattrib->seq_num))
			return false;
		break;
	}
Quoted 2 lines

The real question is whether or not that's more readable.

It's not clear to me that any of these are more readable than the other.

I see that someone broke the staging/rtl8712 version of this driver in June. See commit 98fe05e21a6e ("staging: rtl8712: Remove unnecesary else after return statement."). That patch went through LKML instead of going through the driver-devel list... :/

regards,
dan carpenter

#5 lore raw
Quoted 74 lines · Dan Carpenter
Quoted 70 lines · Joe Perches
Quoted 29 lines · Dan Carpenter
Quoted 28 lines · Sohom Datta
Quoted 1 line

From 4c8c8f3ff7f4d711daea4ac3bb987fcecc7ef1ed Mon Sep 17 00:00:00 2001

From: Sohom <[email protected]>
Date: Sat, 12 Sep 2020 18:04:56 +0530
Subject: [RESEND PATCH] staging: rtl8188eu: Fix else after return WARNING
(checkpatch)

Fixed:
WARNING: else is not generally useful after a break or return 1636: FILE: ./rtw_recv.c:1636:

(quoted diff) +2 -0
+           return false;
+       else

Separated the return statement into a separate block since it doesn't seem to depend on the SN_LESS explicity being false.

---
 drivers/staging/rtl8188eu/core/rtw_recv.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/staging/rtl8188eu/core/rtw_recv.c +0 -0
index 5fe7a0458dd2..5e81134ffb6d 100644
@@ -1629,10 +1629,11 @@ static int enqueue_reorder_recvframe(struct recv_reorder_ctrl *preorder_ctrl,
 		hdr = list_entry(plist, struct recv_frame, list);
 		pnextattrib = &hdr->attrib;
 
Quoted 12 lines

drivers/staging/rtl8188eu/core/rtw_recv.c static int enqueue_reorder_recvframe(struct recv_reorder_ctrl *preorder_ctrl, · line 1639

Quoted 10 lines
drivers/staging/rtl8188eu/core/rtw_recv.c +3 -2
+		if (SN_EQUAL(pnextattrib->seq_num, pattrib->seq_num))
+			return false;
+
 		if (SN_LESS(pnextattrib->seq_num, pattrib->seq_num))
 			plist = plist->next;
-		else if (SN_EQUAL(pnextattrib->seq_num, pattrib->seq_num))
-			return false;
 		else
 			break;
 	}

Checkpatch is just wrong here. Ignore it when it's wrong.

It's not "wrong" here. It's making a suggestion.

Perhaps read the SN_EQUAL and SN_LESS macros.

a and b are both u16's here.

drivers/staging/rtl8188eu/include/rtw_recv.h:#define SN_LESS(a, b) (((a - b) & 0x800) != 0)
drivers/staging/rtl8188eu/include/rtw_recv.h:#define SN_EQUAL(a, b) (a == b)

Reordering works, perhaps it's just a question of
whether it's the most likely result of the test.

This is in a while loop.

If the expected test is really the most likely that SN_LESS is true, then perhaps this loop could be something like:

		if (SN_LESS(pnextattrib->seq_num, pattrib->seq_num)) {
			plist = plist->next;
			continue;
		}
		if (SN_EQUAL(pnextattrib->seq_num, pattrib->seq_num))
			return false;
		break;
	}
Quoted 2 lines

The real question is whether or not that's more readable.

Quoted 6 lines

It's not clear to me that any of these are more readable than the other.

I see that someone broke the staging/rtl8712 version of this driver in June. See commit 98fe05e21a6e ("staging: rtl8712: Remove unnecesary else after return statement."). That patch went through LKML instead of going through the driver-devel list... :/

That's sad.

Then another question is whether either is more prone to unintentional breakage by novice code readers being guided by brainless scripts...

A bit of a pity as the original intent of the checkpatch test was somewhat useful. Maybe it's outlived its value though when used with -f files.

There aren't many of these left in the kernel.

Maybe it should be changed to work only on patches.