IB/qib: fix test of unsigned variable
PATCH 1/1 IB/qib: fix test of unsigned variable
Commit d4988623cc60 ("IB/qib: use arch_phys_wc_add()") adjusted mtrr inititialization to use the new interface.
Unfortunately, the new interface returns a signed value and the patch tested the unsigned wc_cookie.
Fix the issue by using 'ret' and only assigningwc_cookie from ret when ret >= 0. Additionally, insure
ret is 0 on success.
--- drivers/infiniband/hw/qib/qib_wc_x86_64.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)
drivers/infiniband/hw/qib/qib_wc_x86_64.c +5 -3
@@ -116,9 +116,11 @@ int qib_enable_wc(struct qib_devdata *dd) }if (!ret) { - dd->wc_cookie =arch_phys_wc_add (pioaddr, piolen); -if (dd->wc_cookie <0 ) - ret = -EINVAL ; + ret =arch_phys_wc_add (pioaddr, piolen); +if (ret >=0 ) { + dd->wc_cookie = ret; + ret =0 ; + } }return ret;
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Hi,
Quoted 11 lines · Mike Marciniszyn
Commit
d4988623cc60("IB/qib: usearch_phys_wc_add()") adjusted mtrr inititialization to use the new interface.Unfortunately, the new interface returns a signed value and the patch tested the unsigned
wc_cookie.Fix the issue by using 'ret' and only assigning
wc_cookiefrom ret when ret >= 0. Additionally, insure
ret is 0 on success.Signed-off-by Mike Marciniszyn <[email protected]>
Quoted 14 lines
--- drivers/infiniband/hw/qib/qib_wc_x86_64.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)drivers/infiniband/hw/qib/qib_wc_x86_64.c +0
-1@@ -116,9 +116,11 @@ int qib_enable_wc(struct qib_devdata *dd) }if (!ret) { - dd->wc_cookie =arch_phys_wc_add (pioaddr, piolen);
drivers/infiniband/hw/qib/qib_wc_x86_64.c int qib_enable_wc(struct qib_devdata *dd) · line 126
Quoted 10 lines
drivers/infiniband/hw/qib/qib_wc_x86_64.c +5
-2-if (dd->wc_cookie <0 ) - ret = -EINVAL ; + ret =arch_phys_wc_add (pioaddr, piolen); +if (ret >=0 ) { + dd->wc_cookie = ret; + ret =0 ; + } }return ret;
Regards.
Signature · 8 lines
Yann Droneaud OPTEYA -- To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 5 lines · Mike Marciniszyn
Commit
d4988623cc60("IB/qib: usearch_phys_wc_add()") adjusted mtrr inititialization to use the new interface.Unfortunately, the new interface returns a signed value and the patch tested the unsigned
wc_cookie.
Looks like wc_cookie is only used with arch_phys_wc_add/del, so it should become an int, not casted..
Jason
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 29 lines · Yann Droneaud
Hi,
Quoted 11 lines · Mike Marciniszyn
Commit
d4988623cc60("IB/qib: usearch_phys_wc_add()") adjusted mtrr inititialization to use the new interface.Unfortunately, the new interface returns a signed value and the patch tested the unsigned
wc_cookie.Fix the issue by using 'ret' and only assigning
wc_cookiefrom ret when ret >= 0. Additionally, insure
ret is 0 on success.Signed-off-by Mike Marciniszyn <[email protected]>Cc Luis R. Rodriguez <[email protected]>Cc Luis R. Rodriguez <mcgrof-IBi9RG/[email protected]>Quoted 11 lines
--- drivers/infiniband/hw/qib/qib_wc_x86_64.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)drivers/infiniband/hw/qib/qib_wc_x86_64.c +0
-0@@ -116,9 +116,11 @@ int qib_enable_wc(struct qib_devdata *dd) }
Quoted 9 lines
drivers/infiniband/hw/qib/qib_wc_x86_64.c int qib_enable_wc(struct qib_devdata *dd) · line 123
Quoted 9 lines
drivers/infiniband/hw/qib/qib_wc_x86_64.c +5
-3if (!ret) { - dd->wc_cookie =arch_phys_wc_add (pioaddr, piolen); -if (dd->wc_cookie <0 ) - ret = -EINVAL ; + ret =arch_phys_wc_add (pioaddr, piolen); +if (ret >=0 ) { + dd->wc_cookie = ret; + ret =0 ; + }
This fix is broken. Luis and I discussed this at some length with his original patch. You're right that the code is broken because wc_cookie is unsigned and that needs fixed, but once qib_enable_wc returns an error, we don't fail the adapter init, we print out a warning about poor performance and move on. Later, we test wc_cookie != 0 in order to determine if we used PAT. It doesn't matter if our return was positive or negative, we only try to enable wc via arch_phys_wc_add() when we didn't use PAT, and so we need to capture the return value whether it's a valid cookie or an error return in order to make sure we don't attempt to use PAT later on.
So, the matrix of what the driver does now looks like this:
dd->wc_cookie == 0: PAT was useddd->wc_cookie > 0: wc was used successfullydd->wc_cookie < 0: neither PAT nor wc was used
I've fixed up the change to simply switch wc_cookie from unsigned long to plain long and left the original code as it was, and it is now staged for 4.1-rc.
Signature · 2 lines
Doug Ledford <[email protected]> GPG KeyID: 0E572FDD
PiBTbywgdGhlIG1hdHJpeCBvZiB3aGF0IHRoZSBkcml2ZXIgZG9lcyBub3cgbG9va3MgbGlrZSB0 aGlzOg0KPiANCj4gZGQtPndjX2Nvb2tpZSA9PSAwOiBQQVQgd2FzIHVzZWQNCj4gZGQtPndjX2Nv b2tpZSA+IDA6IHdjIHdhcyB1c2VkIHN1Y2Nlc3NmdWxseSB3Y19jb29raWUgPCAwOiBuZWl0aGVy IFBBVA0KPiBkZC0+bm9yIHdjIHdhcyB1c2VkDQo+IA0KPiBJJ3ZlIGZpeGVkIHVwIHRoZSBjaGFu Z2UgdG8gc2ltcGx5IHN3aXRjaCB3Y19jb29raWUgZnJvbSB1bnNpZ25lZCBsb25nIHRvIHBsYWlu DQo+IGxvbmcgYW5kIGxlZnQgdGhlIG9yaWdpbmFsIGNvZGUgYXMgaXQgd2FzLCBhbmQgaXQgaXMg bm93IHN0YWdlZCBmb3IgNC4xLXJjLg0KPiANCg0KSSBoYXZlIGEgdjIgb2YgdGhpcyBwYXRjaCB0 aGF0IGNoYW5nZXMgdGhlIHR5cGUgb2YgdGhlIHdjX2Nvb2tpZS4NCg0KSXQgYWxzbyB1c2VzIGFu eSBuZWdhdGl2ZSBjb29raWUgYXMgdGhlIHJldC4gICBJdCBzZWVtcyBiZXR0ZXIgdG8gdXNlIGlu IGFjdHVhbCBlcnJvciBhcmNoX3BoeXNfd2NfYWRkKCkgZnJvbSAgdnMuIGEgY2FubmVkIG9uZS4N Cg0KTWlrZSANCg==
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html