IB/qib: remove redundant setting of any in for-loop
Subsystems (2)
PATCH 1/1 IB/qib: remove redundant setting of any in for-loop
From: Colin Ian King <[email protected]>
The variable all is being set but is never read after this hence it can be removed from the for loop initialization. Cleans up clang warning:
drivers/infiniband/hw/qib/qib_file_ops.c:640:7: warning: Value stored to 'any' is never read
--- drivers/infiniband/hw/qib/qib_file_ops.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/infiniband/hw/qib/qib_file_ops.c +1 -1
@@ -637,7 +637,7 @@ static int qib_set_part_key(struct qib_ctxtdata *rcd, u16 key) ret = -EBUSY ; goto bail; } -for (any = i =0 ; i <ARRAY_SIZE (ppd->pkeys); i++) { +for (i =0 ; i <ARRAY_SIZE (ppd->pkeys); i++) {if (!ppd->pkeys[i] &&atomic_inc_return (&ppd->pkeyrefs[i]) =1 ) { rcd->pkeys[pidx] = key;
Signature · 1 line
2.14.1
Quoted 5 lines · Colin King
From: Colin Ian King <[email protected]>
The variable all is being set but is never read after this hence it can be removed from the for loop initialization. Cleans up clang warning:
any is really used as bool and is initialized at function entry. The earlier loop also reinitializes any unnecessarily.
Quoted 13 lines
drivers/infiniband/hw/qib/qib_file_ops.c:640:7: warning: Value stored to 'any' is never readSigned-off-by Colin Ian King <[email protected]>--- drivers/infiniband/hw/qib/qib_file_ops.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/infiniband/hw/qib/qib_file_ops.c +0
-0
drivers/infiniband/hw/qib/qib_file_ops.c static int qib_set_part_key(struct qib_ctxtdata *rcd, u16 key) · line 643
Quoted 8 lines
drivers/infiniband/hw/qib/qib_file_ops.c +1
-1@@ -637,7 +637,7 @@ static int qib_set_part_key(struct qib_ctxtdata *rcd, u16 key) ret = -EBUSY ; goto bail; } -for (any = i =0 ; i <ARRAY_SIZE (ppd->pkeys); i++) { +for (i =0 ; i <ARRAY_SIZE (ppd->pkeys); i++) {if (!ppd->pkeys[i] &&atomic_inc_return (&ppd->pkeyrefs[i]) =1 ) { rcd->pkeys[pidx] = key;
Perhaps the function is better written without
the empty bail: label and without setting ret
and just using return.
Combining the int/bool conversion of any and the
direct returns seems clearer to me.
Something like:
---
drivers/infiniband/hw/qib/qib_file_ops.c | 70 ++++++++++++--------------------
1 file changed, 27 insertions(+), 43 deletions(-)
drivers/infiniband/hw/qib/qib_file_ops.c +0 -0
@@ -568,20 +568,17 @@ static int qib_tid_free(struct qib_ctxtdata *rcd, unsigned subctxt,
static int qib_set_part_key(struct qib_ctxtdata *rcd, u16 key)
{
struct qib_pportdata *ppd = rcd->ppd;
- int i, any = 0, pidx = -1;
+ int i;
+ bool any = false;
+ int pidx = -1;
u16 lkey = key & 0x7FFF;
- int ret;
- if (lkey = (QIB_DEFAULT_P_KEY & 0x7FFF)) {
- /* nothing to do; this key always valid */
- ret = 0;
- goto bail;
- }
+ /* nothing to do; this key always valid */
+ if (lkey = (QIB_DEFAULT_P_KEY & 0x7FFF))
+ return 0;
- if (!lkey) {
- ret = -EINVAL;
- goto bail;
- }
+ if (!lkey)
+ return -EINVAL;
/*
* Set the full membership bit, because it has to be
@@ -594,18 +591,15 @@ static int qib_set_part_key(struct qib_ctxtdata *rcd, u16 key) for (i = 0; i < ARRAY_SIZE(rcd->pkeys); i++) {
if (!rcd->pkeys[i] && pidx = -1)
pidx = i;
- if (rcd->pkeys[i] = key) {
- ret = -EEXIST;
- goto bail;
- }
- }
- if (pidx = -1) {
- ret = -EBUSY;
- goto bail;
+ if (rcd->pkeys[i] = key)
+ return -EEXIST;
}
- for (any = i = 0; i < ARRAY_SIZE(ppd->pkeys); i++) {
+ if (pidx = -1)
+ return -EBUSY;
+
+ for (i = 0; i < ARRAY_SIZE(ppd->pkeys); i++) {
if (!ppd->pkeys[i]) {
- any++;
+ any = true;
continue;
}
if (ppd->pkeys[i] = key) {
@@ -613,44 +607,34 @@ static int qib_set_part_key(struct qib_ctxtdata *rcd, u16 key)
if (atomic_inc_return(pkrefs) > 1) { rcd->pkeys[pidx] = key;
- ret = 0;
- goto bail;
- } else {
- /*
- * lost race, decrement count, catch below
- */
- atomic_dec(pkrefs);
- any++;
+ return 0;
}
+ /* lost race, decrement count, catch below */
+ atomic_dec(pkrefs);
+ any = true;
}
- if ((ppd->pkeys[i] & 0x7FFF) = lkey) {
+ if ((ppd->pkeys[i] & 0x7FFF) = lkey)
/*
* It makes no sense to have both the limited and
* full membership PKEY set at the same time since
* the unlimited one will disable the limited one. */
- ret = -EEXIST;
- goto bail;
- }
- }
- if (!any) {
- ret = -EBUSY;
- goto bail;
+ return -EEXIST;
}
- for (any = i = 0; i < ARRAY_SIZE(ppd->pkeys); i++) {
+ if (!any)
+ return -EBUSY;
+
+ for (i = 0; i < ARRAY_SIZE(ppd->pkeys); i++) {
if (!ppd->pkeys[i] && atomic_inc_return(&ppd->pkeyrefs[i]) = 1) { rcd->pkeys[pidx] = key;
ppd->pkeys[i] = key;
(void) ppd->dd->f_set_ib_cfg(ppd, QIB_IB_CFG_PKEYS, 0);
- ret = 0;
- goto bail;
+ return 0;
}
}
- ret = -EBUSY;
-bail:
- return ret;
+ return -EBUSY;
}
/**
--
To unsubscribe from this list: send the line "unsubscribe kernel-janitors" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 9 lines · Joe Perches
Quoted 5 lines · Colin King
From: Colin Ian King <[email protected]>
The variable all is being set but is never read after this hence it can be removed from the for loop initialization. Cleans up clang warning:
any is really used as bool and is initialized at function entry. The earlier loop also reinitializes any unnecessarily.
Denny, can you weigh in on what you want in this thread? Thanks.
Quoted 150 lines
Quoted 13 lines
drivers/infiniband/hw/qib/qib_file_ops.c:640:7: warning: Value stored to 'any' is never readSigned-off-by Colin Ian King <[email protected]>--- drivers/infiniband/hw/qib/qib_file_ops.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/infiniband/hw/qib/qib_file_ops.c +0
-0drivers/infiniband/hw/qib/qib_file_ops.c static int qib_set_part_key(struct qib_ctxtdata *rcd, u16 key) · line 643
Quoted 8 lines
drivers/infiniband/hw/qib/qib_file_ops.c +1
-1@@ -637,7 +637,7 @@ static int qib_set_part_key(struct qib_ctxtdata *rcd, u16 key) ret = -EBUSY ; goto bail; } -for (any = i =0 ; i <ARRAY_SIZE (ppd->pkeys); i++) { +for (i =0 ; i <ARRAY_SIZE (ppd->pkeys); i++) {if (!ppd->pkeys[i] &&atomic_inc_return (&ppd->pkeyrefs[i]) ==1 ) { rcd->pkeys[pidx] = key;Perhaps the function is better written without the empty bail: label and without setting ret and just using return.
Combining the int/bool conversion of any and the direct returns seems clearer to me.
Something like:
--- drivers/infiniband/hw/qib/qib_file_ops.c | 70 ++++++++++++-------------------- 1 file changed, 27 insertions(+), 43 deletions(-)drivers/infiniband/hw/qib/qib_file_ops.c +27
-43@@ -568,20 +568,17 @@ static int qib_tid_free(struct qib_ctxtdata *rcd, unsigned subctxt,static int qib_set_part_key (struct qib_ctxtdata *rcd,u16 key) {struct qib_pportdata *ppd = rcd->ppd; -int i, any =0 , pidx =-1 ; +int i; +bool any = false; +int pidx =-1 ;u16 lkey = key &0x7FFF ; -int ret; -if (lkey == (QIB_DEFAULT_P_KEY &0x7FFF )) { -/* nothing to do; this key always valid */ - ret =0 ; - goto bail; - } +/* nothing to do; this key always valid */ +if (lkey == (QIB_DEFAULT_P_KEY &0x7FFF )) +return 0 ; -if (!lkey) { - ret = -EINVAL ; - goto bail; - } +if (!lkey) +return -EINVAL ;/* * Set the full membership bit, because it has to be @@ -594,18 +591,15 @@ static int qib_set_part_key(struct qib_ctxtdata *rcd, u16 key)for (i =0 ; i <ARRAY_SIZE (rcd->pkeys); i++) {if (!rcd->pkeys[i] && pidx ==-1 ) pidx = i; -if (rcd->pkeys[i] == key) { - ret = -EEXIST ; - goto bail; - } - } -if (pidx ==-1 ) { - ret = -EBUSY ; - goto bail; +if (rcd->pkeys[i] == key) +return -EEXIST ; } -for (any = i =0 ; i <ARRAY_SIZE (ppd->pkeys); i++) { +if (pidx ==-1 ) +return -EBUSY ; + +for (i =0 ; i <ARRAY_SIZE (ppd->pkeys); i++) {if (!ppd->pkeys[i]) { - any++; + any = true;continue ; }if (ppd->pkeys[i] == key) {@@ -613,44 +607,34 @@ static int qib_set_part_key(struct qib_ctxtdata *rcd, u16 key)if (atomic_inc_return (pkrefs) >1 ) { rcd->pkeys[pidx] = key; - ret =0 ; - goto bail; - }else { -/* -* lost race, decrement count, catch below -*/ -atomic_dec (pkrefs); - any++; +return 0 ; } +/* lost race, decrement count, catch below */ +atomic_dec (pkrefs); + any = true; } -if ((ppd->pkeys[i] &0x7FFF ) == lkey) { +if ((ppd->pkeys[i] &0x7FFF ) == lkey)/* * It makes no sense to have both the limited and * full membership PKEY set at the same time since * the unlimited one will disable the limited one. */ - ret = -EEXIST ; - goto bail; - } - } -if (!any) { - ret = -EBUSY ; - goto bail; +return -EEXIST ; } -for (any = i =0 ; i <ARRAY_SIZE (ppd->pkeys); i++) { +if (!any) +return -EBUSY ; + +for (i =0 ; i <ARRAY_SIZE (ppd->pkeys); i++) {if (!ppd->pkeys[i] &&atomic_inc_return (&ppd->pkeyrefs[i]) ==1 ) { rcd->pkeys[pidx] = key; ppd->pkeys[i] = key; (void ) ppd->dd->f_set_ib_cfg (ppd,QIB_IB_CFG_PKEYS ,0 ); - ret =0 ; - goto bail; +return 0 ; } } - ret = -EBUSY ; -bail: -return ret; +return -EBUSY ; }/**
Signature · 3 lines
Doug Ledford <[email protected]> GPG KeyID: B826A3330E572FDD Key fingerprint = AE6B 1BDA 122B 23B4 265B 1274 B826 A333 0E57 2FDD
PiA+IE9uIEZyaSwgMjAxNy0xMC0yMCBhdCAwOToyMSArMDIwMCwgQ29saW4gS2luZyB3cm90ZToN Cj4gPiA+IEZyb206IENvbGluIElhbiBLaW5nIDxjb2xpbi5raW5nQGNhbm9uaWNhbC5jb20+DQo+ ID4gPg0KPiA+ID4gVGhlIHZhcmlhYmxlIGFsbCBpcyBiZWluZyBzZXQgYnV0IGlzIG5ldmVyIHJl YWQgYWZ0ZXIgdGhpcw0KPiA+ID4gaGVuY2UgaXQgY2FuIGJlIHJlbW92ZWQgZnJvbSB0aGUgZm9y IGxvb3AgaW5pdGlhbGl6YXRpb24uDQo+ID4gPiBDbGVhbnMgdXAgY2xhbmcgd2FybmluZzoNCj4g Pg0KPiA+IGFueSBpcyByZWFsbHkgdXNlZCBhcyBib29sIGFuZCBpcyBpbml0aWFsaXplZCBhdCBm dW5jdGlvbg0KPiA+IGVudHJ5LiAgVGhlIGVhcmxpZXIgbG9vcCBhbHNvIHJlaW5pdGlhbGl6ZXMg YW55IHVubmVjZXNzYXJpbHkuDQo+IA0KPiBEZW5ueSwgY2FuIHlvdSB3ZWlnaCBpbiBvbiB3aGF0 IHlvdSB3YW50IGluIHRoaXMgdGhyZWFkPyAgVGhhbmtzLg0KPiANCg0KSSBhbSBvayB3aXRoIGJv dGggQ29saW4ncyBhbmQgSm9lJ3MgcGF0Y2guDQoNCkpvZSdzIHBhdGNoIHdvdWxkIHJlcXVpcmUg YWRkaXRpb25hbCB0ZXN0aW5nIHZzLiB0aGUgdHJpdmlhbCB3YXJuaW5nIGZpeC4NCg0KVGhlbiB0 aGVyZSBpcyBhICJndWlkZWxpbmUiICB0byBrZWVwIGZpeGVzIHNlcGFyYXRlIGZyb20gY2xlYW4g dXAuLi4NCg0KRG91ZywgIGRvIHlvdSB3YW50IGEgdGVzdGVkIHBhdGNoIGZyb20gbWU/DQoNCk1p a2UNCg0K
Quoted 13 lines · Mike
Quoted 12 lines
Quoted 9 lines · Colin King
Quoted 5 lines
From: Colin Ian King <[email protected]>
The variable all is being set but is never read after this hence it can be removed from the for loop initialization. Cleans up clang warning:
any is really used as bool and is initialized at function entry. The earlier loop also reinitializes any unnecessarily.
Denny, can you weigh in on what you want in this thread? Thanks.
Quoted 7 lines
I am ok with both Colin's and Joe's patch.
Joe's patch would require additional testing vs. the trivial warning fix.
Then there is a "guideline" to keep fixes separate from clean up...
Doug, do you want a tested patch from me?
Preferably, yes :-)
Signature · 3 lines
Doug Ledford <[email protected]> GPG KeyID: B826A3330E572FDD Key fingerprint = AE6B 1BDA 122B 23B4 265B 1274 B826 A333 0E57 2FDD
PiA+IERvdWcsICBkbyB5b3Ugd2FudCBhIHRlc3RlZCBwYXRjaCBmcm9tIG1lPw0KPiANCj4gUHJl ZmVyYWJseSwgeWVzIDotKQ0KPiANCg0KVGhlc2UgcGF0Y2hlcyBhcmUgaW4gYSB0d28gcGF0Y2gg c2VyaWVzOg0KaHR0cHM6Ly9tYXJjLmluZm8vP2w9bGludXgtcmRtYSZtPTE1MTA2OTQ5NzUwNjky MyZ3PTINCg0KVGhlIGZpcnN0IGlzIENvbGluJ3Mgd2FybmluZyBmaXggYW5kIHRoZSBzZWNvbmQg aXMgSm9lJ3MgY2xlYW51cC4NCg0KTXkgdmFsdWUgYWRkIGlzIHRoZSB0ZXN0aW5nLiAgOikNCg0K VGhleSBwYXNzIG91ciBwc20gdGVzdGluZy4NCg0KVGhhbmtzIGZvciB0aGUgcGF0Y2hlcyENCg0K TWlrZQ0K