Skip to contentSkip to conversation

IB/qib: remove superfluous fallthrough statements

PATCH Superseded Alex Dewar 6 participants 16 messages Aug 25, 2020 – Aug 31, 2020 InfiniBand

lore
Share & tools
lore

Alex Dewar

author
#0 lore raw

PATCH 1/1 IB/qib: remove superfluous fallthrough statements

Commit 36a8f01cd24b ("IB/qib: Add congestion control agent implementation") erroneously marked a couple of switch cases as /* FALLTHROUGH */, which were later converted to fallthrough statements by commit df561f6688fe ("treewide: Use fallthrough pseudo-keyword"). This triggered a Coverity warning about unreachable code.

Remove the fallthrough statements and replace the mass of gotos with simple return statements to make the code terser and less bug-prone.

Addresses-Coverity: ("Unreachable code")

Fixes 36a8f01cd24b ("IB/qib: Add congestion control agent implementation")
---
 drivers/infiniband/hw/qib/qib_mad.c | 52 ++++++++---------------------
 1 file changed, 13 insertions(+), 39 deletions(-)
drivers/infiniband/hw/qib/qib_mad.c +13 -39
index e7789e724f56..f83e331977f8 100644
@@ -2293,76 +2293,50 @@ static int process_cc(struct ib_device *ibdev, int mad_flags,
 			struct ib_mad *out_mad)
 {
 	struct ib_cc_mad *ccp = (struct ib_cc_mad *)out_mad;
-	int ret;
-
 	*out_mad = *in_mad;
 
 	if (ccp->class_version != 2) {
 		ccp->status |= IB_SMP_UNSUP_VERSION;
-		ret = reply((struct ib_smp *)ccp);
-		goto bail;
+		return reply((struct ib_smp *)ccp);
 	}
 
 	switch (ccp->method) {
 	case IB_MGMT_METHOD_GET:
 		switch (ccp->attr_id) {
 		case IB_CC_ATTR_CLASSPORTINFO:
-			ret = cc_get_classportinfo(ccp, ibdev);
-			goto bail;
-
+			return cc_get_classportinfo(ccp, ibdev);
 		case IB_CC_ATTR_CONGESTION_INFO:
-			ret = cc_get_congestion_info(ccp, ibdev, port);
-			goto bail;
-
+			return cc_get_congestion_info(ccp, ibdev, port);
 		case IB_CC_ATTR_CA_CONGESTION_SETTING:
-			ret = cc_get_congestion_setting(ccp, ibdev, port);
-			goto bail;
-
+			return cc_get_congestion_setting(ccp, ibdev, port);
 		case IB_CC_ATTR_CONGESTION_CONTROL_TABLE:
-			ret = cc_get_congestion_control_table(ccp, ibdev, port);
-			goto bail;
-
-			fallthrough;
+			return cc_get_congestion_control_table(ccp, ibdev, port);
 		default:
 			ccp->status |= IB_SMP_UNSUP_METH_ATTR;
-			ret = reply((struct ib_smp *) ccp);
-			goto bail;
+			return reply((struct ib_smp *) ccp);
 		}
-
 	case IB_MGMT_METHOD_SET:
 		switch (ccp->attr_id) {
 		case IB_CC_ATTR_CA_CONGESTION_SETTING:
-			ret = cc_set_congestion_setting(ccp, ibdev, port);
-			goto bail;
-
+			return cc_set_congestion_setting(ccp, ibdev, port);
 		case IB_CC_ATTR_CONGESTION_CONTROL_TABLE:
-			ret = cc_set_congestion_control_table(ccp, ibdev, port);
-			goto bail;
-
-			fallthrough;
+			return cc_set_congestion_control_table(ccp, ibdev, port);
 		default:
 			ccp->status |= IB_SMP_UNSUP_METH_ATTR;
-			ret = reply((struct ib_smp *) ccp);
-			goto bail;
+			return reply((struct ib_smp *) ccp);
 		}
-
 	case IB_MGMT_METHOD_GET_RESP:
 		/*
 		 * The ib_mad module will call us to process responses
 		 * before checking for other consumers.
 		 * Just tell the caller to process it normally.
 		 */
-		ret = IB_MAD_RESULT_SUCCESS;
-		goto bail;
-
-	case IB_MGMT_METHOD_TRAP:
-	default:
-		ccp->status |= IB_SMP_UNSUP_METHOD;
-		ret = reply((struct ib_smp *) ccp);
+		return IB_MAD_RESULT_SUCCESS;
 	}
 
-bail:
-	return ret;
+	/* method is unsupported */
+	ccp->status |= IB_SMP_UNSUP_METHOD;
+	return reply((struct ib_smp *) ccp);
 }
 
 /**
Signature · 1 line
2.28.0
#1 lore raw
Quoted 9 lines · Alex Dewar

Commit 36a8f01cd24b ("IB/qib: Add congestion control agent implementation") erroneously marked a couple of switch cases as /* FALLTHROUGH */, which were later converted to fallthrough statements by commit df561f6688fe ("treewide: Use fallthrough pseudo-keyword"). This triggered a Coverity warning about unreachable code.

Remove the fallthrough statements and replace the mass of gotos with simple return statements to make the code terser and less bug-prone.

This should be split up into two separate patches: one to address the fallthrough markings, and another one for the gotos.

Thanks
--
Gustavo

#2 lore raw
Quoted 8 lines · Gustavo A. R. Silva
Quoted 6 lines · Alex Dewar

Commit 36a8f01cd24b ("IB/qib: Add congestion control agent implementation") erroneously marked a couple of switch cases as /* FALLTHROUGH */, which were later converted to fallthrough statements by commit df561f6688fe ("treewide: Use fallthrough pseudo-keyword"). This triggered a Coverity warning about unreachable code.

Quoted 6 lines
Quoted 3 lines

Remove the fallthrough statements and replace the mass of gotos with simple return statements to make the code terser and less bug-prone.

This should be split up into two separate patches: one to address the fallthrough markings, and another one for the gotos.

I don't think it's necessary to break this into multiple patches. Logical changes in a single patch are just fine, micro patches aren't that useful.

#3 lore raw
Quoted 13 lines · Joe Perches
Quoted 12 lines · Gustavo A. R. Silva
Quoted 9 lines · Alex Dewar

Commit 36a8f01cd24b ("IB/qib: Add congestion control agent implementation") erroneously marked a couple of switch cases as /* FALLTHROUGH */, which were later converted to fallthrough statements by commit df561f6688fe ("treewide: Use fallthrough pseudo-keyword"). This triggered a Coverity warning about unreachable code.

Remove the fallthrough statements and replace the mass of gotos with simple return statements to make the code terser and less bug-prone.

Quoted 7 lines
Quoted 2 lines

This should be split up into two separate patches: one to address the fallthrough markings, and another one for the gotos.

I don't think it's necessary to break this into multiple patches. Logical changes in a single patch are just fine, micro patches aren't that useful.

There is a reason for this. Read the changelog text and review the patch.

Thanks
--
Gustavo

#4 lore raw
Quoted 17 lines · Gustavo A. R. Silva
Quoted 15 lines · Joe Perches
Quoted 13 lines · Gustavo A. R. Silva
Quoted 9 lines · Alex Dewar

Commit 36a8f01cd24b ("IB/qib: Add congestion control agent implementation") erroneously marked a couple of switch cases as /* FALLTHROUGH */, which were later converted to fallthrough statements by commit df561f6688fe ("treewide: Use fallthrough pseudo-keyword"). This triggered a Coverity warning about unreachable code.

Remove the fallthrough statements and replace the mass of gotos with simple return statements to make the code terser and less bug-prone.

This should be split up into two separate patches: one to address the fallthrough markings, and another one for the gotos.

Quoted 6 lines
Quoted 4 lines

I don't think it's necessary to break this into multiple patches. Logical changes in a single patch are just fine, micro patches aren't that useful.

There is a reason for this. Read the changelog text and review the patch.

What makes you think I didn't already do that?

I think your desire for micropatches is unnecessary.

#5 lore raw
Quoted 18 lines · Joe Perches
Quoted 17 lines · Gustavo A. R. Silva
Quoted 15 lines · Joe Perches
Quoted 13 lines · Gustavo A. R. Silva
Quoted 9 lines · Alex Dewar

Commit 36a8f01cd24b ("IB/qib: Add congestion control agent implementation") erroneously marked a couple of switch cases as /* FALLTHROUGH */, which were later converted to fallthrough statements by commit df561f6688fe ("treewide: Use fallthrough pseudo-keyword"). This triggered a Coverity warning about unreachable code.

Remove the fallthrough statements and replace the mass of gotos with simple return statements to make the code terser and less bug-prone.

This should be split up into two separate patches: one to address the fallthrough markings, and another one for the gotos.

Quoted 9 lines
Quoted 6 lines
Quoted 4 lines

I don't think it's necessary to break this into multiple patches. Logical changes in a single patch are just fine, micro patches aren't that useful.

There is a reason for this. Read the changelog text and review the patch.

What makes you think I didn't already do that?

You would have noticed this should be two patches.

Quoted 2 lines

I think your desire for micropatches is unnecessary.

You might be generalizing. My 'desire' here is justified and specific.

Thanks
--
Gustavo

#6 lore raw
Quoted 1 line · Gustavo A. R. Silva

On 8/25/20 11:47, Joe Perches wrote

[]

Quoted 1 line

You would have noticed this should be two patches.

That's interpretational.

Quoted 3 lines
Quoted 2 lines

I think your desire for micropatches is unnecessary.

You might be generalizing. My 'desire' here is justified and specific.

And to date undescribed.

author
#7 lore raw
In reply to Gustavo A. R. Silva
Quoted 19 lines · Gustavo A. R. Silva
Quoted 8 lines · Joe Perches
Quoted 7 lines · Gustavo A. R. Silva
Quoted 6 lines · Alex Dewar

Commit 36a8f01cd24b ("IB/qib: Add congestion control agent implementation") erroneously marked a couple of switch cases as /* FALLTHROUGH */, which were later converted to fallthrough statements by commit df561f6688fe ("treewide: Use fallthrough pseudo-keyword"). This triggered a Coverity warning about unreachable code.

Quoted 9 lines
Quoted 5 lines
Quoted 3 lines

Remove the fallthrough statements and replace the mass of gotos with simple return statements to make the code terser and less bug-prone.

This should be split up into two separate patches: one to address the fallthrough markings, and another one for the gotos.

I don't think it's necessary to break this into multiple patches. Logical changes in a single patch are just fine, micro patches aren't that useful.

Quoted 5 lines

There is a reason for this. Read the changelog text and review the patch.

Thanks
--
Gustavo

I think it probably does make sense as two patches. I'll do a resend.

author
#8 lore raw

PATCH v2 1/2 IB/qib: remove superfluous fallthrough statements

Commit 36a8f01cd24b ("IB/qib: Add congestion control agent implementation") erroneously marked a couple of switch cases as /* FALLTHROUGH */, which were later converted to fallthrough statements by commit df561f6688fe ("treewide: Use fallthrough pseudo-keyword"). This triggered a Coverity warning about unreachable code.

Remove the fallthrough statements.

Addresses-Coverity: ("Unreachable code")

Fixes 36a8f01cd24b ("IB/qib: Add congestion control agent implementation")

---
v2: Do refactoring in a separate patch (Gustavo)

---
 drivers/infiniband/hw/qib/qib_mad.c | 2 --
 1 file changed, 2 deletions(-)
drivers/infiniband/hw/qib/qib_mad.c +0 -2
index e7789e724f56..f972e559a8a7 100644
@@ -2322,7 +2322,6 @@ static int process_cc(struct ib_device *ibdev, int mad_flags,
 			ret = cc_get_congestion_control_table(ccp, ibdev, port);
 			goto bail;
 
-			fallthrough;
 		default:
 			ccp->status |= IB_SMP_UNSUP_METH_ATTR;
 			ret = reply((struct ib_smp *) ccp);
@@ -2339,7 +2338,6 @@ static int process_cc(struct ib_device *ibdev, int mad_flags,
 			ret = cc_set_congestion_control_table(ccp, ibdev, port);
 			goto bail;
 
-			fallthrough;
 		default:
 			ccp->status |= IB_SMP_UNSUP_METH_ATTR;
 			ret = reply((struct ib_smp *) ccp);
Signature · 1 line
2.28.0
Reviewed-by on v2 1/2
#9 lore raw
Quoted 6 lines · Alex Dewar

Commit 36a8f01cd24b ("IB/qib: Add congestion control agent implementation") erroneously marked a couple of switch cases as /* FALLTHROUGH */, which were later converted to fallthrough statements by commit df561f6688fe ("treewide: Use fallthrough pseudo-keyword"). This triggered a Coverity warning about unreachable code.

It's worth mentioning that this warning is triggered only by compilers that don't support __attribute__((__fallthrough__)), which has been supported since GCC 7.1.

Quoted 5 lines

Remove the fallthrough statements.

Addresses-Coverity: ("Unreachable code")

Fixes 36a8f01cd24b ("IB/qib: Add congestion control agent implementation")
Quoted 3 lines

---
v2: Do refactoring in a separate patch (Gustavo)
---

^^^
These dashes are not needed.

Thanks
--
Gustavo

Quoted 26 lines
 drivers/infiniband/hw/qib/qib_mad.c | 2 --
 1 file changed, 2 deletions(-)
drivers/infiniband/hw/qib/qib_mad.c +0 -2
index e7789e724f56..f972e559a8a7 100644
@@ -2322,7 +2322,6 @@ static int process_cc(struct ib_device *ibdev, int mad_flags,
 			ret = cc_get_congestion_control_table(ccp, ibdev, port);
 			goto bail;
 
-			fallthrough;
 		default:
 			ccp->status |= IB_SMP_UNSUP_METH_ATTR;
 			ret = reply((struct ib_smp *) ccp);
@@ -2339,7 +2338,6 @@ static int process_cc(struct ib_device *ibdev, int mad_flags,
 			ret = cc_set_congestion_control_table(ccp, ibdev, port);
 			goto bail;
 
-			fallthrough;
 		default:
 			ccp->status |= IB_SMP_UNSUP_METH_ATTR;
 			ret = reply((struct ib_smp *) ccp);
Signature · 1 line
2.28.0
#10 lore raw

Hi,

Quoted 12 lines · Gustavo A. R. Silva
Quoted 6 lines · Alex Dewar

Commit 36a8f01cd24b ("IB/qib: Add congestion control agent implementation") erroneously marked a couple of switch cases as /* FALLTHROUGH */, which were later converted to fallthrough statements by commit df561f6688fe ("treewide: Use fallthrough pseudo-keyword"). This triggered a Coverity warning about unreachable code.

It's worth mentioning that this warning is triggered only by compilers that don't support __attribute__((__fallthrough__)), which has been supported since GCC 7.1.

Quoted 8 lines
Quoted 5 lines

Remove the fallthrough statements.

Addresses-Coverity: ("Unreachable code")

Fixes 36a8f01cd24b ("IB/qib: Add congestion control agent implementation")

I can take this in my tree for 5.9-rc3.

Thanks
--
Gustavo

#11 lore raw
Quoted 17 lines · Gustavo A. R. Silva

Hi,

Quoted 14 lines · Gustavo A. R. Silva
Quoted 6 lines · Alex Dewar

Commit 36a8f01cd24b ("IB/qib: Add congestion control agent implementation") erroneously marked a couple of switch cases as /* FALLTHROUGH */, which were later converted to fallthrough statements by commit df561f6688fe ("treewide: Use fallthrough pseudo-keyword"). This triggered a Coverity warning about unreachable code.

It's worth mentioning that this warning is triggered only by compilers that don't support __attribute__((__fallthrough__)), which has been supported since GCC 7.1.

Quoted 2 lines

Remove the fallthrough statements.

Quoted 8 lines
Quoted 6 lines
Quoted 3 lines

Addresses-Coverity: ("Unreachable code")

Fixes 36a8f01cd24b ("IB/qib: Add congestion control agent implementation")

I can take this in my tree for 5.9-rc3.

That would make conflicts for the 2nd patch, lets just send them all through the rdma tree please. Is there a reason this is -rc material?

Jason

#12 lore raw
Quoted 22 lines · Jason Gunthorpe
Quoted 21 lines · Gustavo A. R. Silva

Hi,

Quoted 18 lines · Gustavo A. R. Silva
Quoted 6 lines · Alex Dewar

Commit 36a8f01cd24b ("IB/qib: Add congestion control agent implementation") erroneously marked a couple of switch cases as /* FALLTHROUGH */, which were later converted to fallthrough statements by commit df561f6688fe ("treewide: Use fallthrough pseudo-keyword"). This triggered a Coverity warning about unreachable code.

It's worth mentioning that this warning is triggered only by compilers that don't support __attribute__((__fallthrough__)), which has been supported since GCC 7.1.

Quoted 5 lines

Remove the fallthrough statements.

Addresses-Coverity: ("Unreachable code")

Fixes 36a8f01cd24b ("IB/qib: Add congestion control agent implementation")
Quoted 7 lines
Quoted 4 lines
Quoted 2 lines

I can take this in my tree for 5.9-rc3.

That would make conflicts for the 2nd patch, lets just send them all through the rdma tree please.

OK.

Quoted 1 line

Is there a reason this is -rc material?

It's just that this warning is currently in mainline.

Thanks
--
Gustavo

author
#13 lore raw
Quoted 28 lines · Gustavo A. R. Silva
Quoted 27 lines · Jason Gunthorpe
Quoted 25 lines · Gustavo A. R. Silva

Hi,

Quoted 12 lines · Gustavo A. R. Silva
Quoted 6 lines · Alex Dewar

Commit 36a8f01cd24b ("IB/qib: Add congestion control agent implementation") erroneously marked a couple of switch cases as /* FALLTHROUGH */, which were later converted to fallthrough statements by commit df561f6688fe ("treewide: Use fallthrough pseudo-keyword"). This triggered a Coverity warning about unreachable code.

It's worth mentioning that this warning is triggered only by compilers that don't support __attribute__((__fallthrough__)), which has been supported since GCC 7.1.

Quoted 8 lines
Quoted 5 lines

Remove the fallthrough statements.

Addresses-Coverity: ("Unreachable code")

Fixes 36a8f01cd24b ("IB/qib: Add congestion control agent implementation")

I can take this in my tree for 5.9-rc3.

Quoted 8 lines
Quoted 2 lines

That would make conflicts for the 2nd patch, lets just send them all through the rdma tree please.

OK.

Quoted 1 line

Is there a reason this is -rc material?

It's just that this warning is currently in mainline.

FYI this issue was found with Coverity, not a compiler. I just built the unfixed version from mainline (with gcc 10.2.0) and didn't get any warnings.

Quoted 4 lines

Thanks
--
Gustavo

maintainer
#14 lore raw
In reply to Alex Dewar
Quoted 9 lines · Alex Dewar

Commit 36a8f01cd24b ("IB/qib: Add congestion control agent implementation") erroneously marked a couple of switch cases as /* FALLTHROUGH */, which were later converted to fallthrough statements by commit df561f6688fe ("treewide: Use fallthrough pseudo-keyword"). This triggered a Coverity warning about unreachable code.

Remove the fallthrough statements.

Addresses-Coverity: ("Unreachable code")

Quoted 8 lines
Fixes 36a8f01cd24b ("IB/qib: Add congestion control agent implementation")

---
v2: Do refactoring in a separate patch (Gustavo)

---
 drivers/infiniband/hw/qib/qib_mad.c | 2 --
 1 file changed, 2 deletions(-)

Both applied to for-next, thanks

Jason

author
#15 lore raw

PATCH v2 2/2 IB/qib: tidy up process_cc()

In reply to Alex Dewar

This function has a lot of gotos which could be replaced by simple returns, making the function tidier and less bug prone.

---
 drivers/infiniband/hw/qib/qib_mad.c | 50 ++++++++---------------------
 1 file changed, 13 insertions(+), 37 deletions(-)
drivers/infiniband/hw/qib/qib_mad.c +13 -37
index f972e559a8a7..f83e331977f8 100644
@@ -2293,74 +2293,50 @@ static int process_cc(struct ib_device *ibdev, int mad_flags,
 			struct ib_mad *out_mad)
 {
 	struct ib_cc_mad *ccp = (struct ib_cc_mad *)out_mad;
-	int ret;
-
 	*out_mad = *in_mad;
 
 	if (ccp->class_version != 2) {
 		ccp->status |= IB_SMP_UNSUP_VERSION;
-		ret = reply((struct ib_smp *)ccp);
-		goto bail;
+		return reply((struct ib_smp *)ccp);
 	}
 
 	switch (ccp->method) {
 	case IB_MGMT_METHOD_GET:
 		switch (ccp->attr_id) {
 		case IB_CC_ATTR_CLASSPORTINFO:
-			ret = cc_get_classportinfo(ccp, ibdev);
-			goto bail;
-
+			return cc_get_classportinfo(ccp, ibdev);
 		case IB_CC_ATTR_CONGESTION_INFO:
-			ret = cc_get_congestion_info(ccp, ibdev, port);
-			goto bail;
-
+			return cc_get_congestion_info(ccp, ibdev, port);
 		case IB_CC_ATTR_CA_CONGESTION_SETTING:
-			ret = cc_get_congestion_setting(ccp, ibdev, port);
-			goto bail;
-
+			return cc_get_congestion_setting(ccp, ibdev, port);
 		case IB_CC_ATTR_CONGESTION_CONTROL_TABLE:
-			ret = cc_get_congestion_control_table(ccp, ibdev, port);
-			goto bail;
-
+			return cc_get_congestion_control_table(ccp, ibdev, port);
 		default:
 			ccp->status |= IB_SMP_UNSUP_METH_ATTR;
-			ret = reply((struct ib_smp *) ccp);
-			goto bail;
+			return reply((struct ib_smp *) ccp);
 		}
-
 	case IB_MGMT_METHOD_SET:
 		switch (ccp->attr_id) {
 		case IB_CC_ATTR_CA_CONGESTION_SETTING:
-			ret = cc_set_congestion_setting(ccp, ibdev, port);
-			goto bail;
-
+			return cc_set_congestion_setting(ccp, ibdev, port);
 		case IB_CC_ATTR_CONGESTION_CONTROL_TABLE:
-			ret = cc_set_congestion_control_table(ccp, ibdev, port);
-			goto bail;
-
+			return cc_set_congestion_control_table(ccp, ibdev, port);
 		default:
 			ccp->status |= IB_SMP_UNSUP_METH_ATTR;
-			ret = reply((struct ib_smp *) ccp);
-			goto bail;
+			return reply((struct ib_smp *) ccp);
 		}
-
 	case IB_MGMT_METHOD_GET_RESP:
 		/*
 		 * The ib_mad module will call us to process responses
 		 * before checking for other consumers.
 		 * Just tell the caller to process it normally.
 		 */
-		ret = IB_MAD_RESULT_SUCCESS;
-		goto bail;
-
-	case IB_MGMT_METHOD_TRAP:
-	default:
-		ccp->status |= IB_SMP_UNSUP_METHOD;
-		ret = reply((struct ib_smp *) ccp);
+		return IB_MAD_RESULT_SUCCESS;
 	}
 
-bail:
-	return ret;
+	/* method is unsupported */
+	ccp->status |= IB_SMP_UNSUP_METHOD;
+	return reply((struct ib_smp *) ccp);
 }
 
 /**
Signature · 1 line
2.28.0