All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH][usb-next] usb: cdns3: fix missing assignment of ret before error check on ret
@ 2019-09-02 14:50 ` Colin King
  0 siblings, 0 replies; 8+ messages in thread
From: Colin King @ 2019-09-02 14:50 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Felipe Balbi, Pawel Laszczak, linux-usb
  Cc: kernel-janitors, linux-kernel

From: Colin Ian King <colin.king@canonical.com>

Currently the check on a non-zero return code in ret is false because
ret has been initialized to zero.  I believe that ret should be assigned
to the return from the call to readl_poll_timeout_atomic before the
check on ret.  Since ret is being re-assinged the original initialization
of ret to zero can be removed.

Addresses-Coverity: ("'Constant' variable guards dead code")
Fixes: 7733f6c32e36 ("usb: cdns3: Add Cadence USB3 DRD Driver")
Signed-off-by: Colin Ian King <colin.king@canonical.com>
---
 drivers/usb/cdns3/gadget.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/usb/cdns3/gadget.c b/drivers/usb/cdns3/gadget.c
index 3094ad65ffc9..0eb3022838d6 100644
--- a/drivers/usb/cdns3/gadget.c
+++ b/drivers/usb/cdns3/gadget.c
@@ -2154,7 +2154,7 @@ int __cdns3_gadget_ep_clear_halt(struct cdns3_endpoint *priv_ep)
 {
 	struct cdns3_device *priv_dev = priv_ep->cdns3_dev;
 	struct usb_request *request;
-	int ret = 0;
+	int ret;
 	int val;
 
 	trace_cdns3_halt(priv_ep, 0, 0);
@@ -2162,8 +2162,8 @@ int __cdns3_gadget_ep_clear_halt(struct cdns3_endpoint *priv_ep)
 	writel(EP_CMD_CSTALL | EP_CMD_EPRST, &priv_dev->regs->ep_cmd);
 
 	/* wait for EPRST cleared */
-	readl_poll_timeout_atomic(&priv_dev->regs->ep_cmd, val,
-				  !(val & EP_CMD_EPRST), 1, 100);
+	ret = readl_poll_timeout_atomic(&priv_dev->regs->ep_cmd, val,
+					!(val & EP_CMD_EPRST), 1, 100);
 	if (ret)
 		return -EINVAL;
 
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH][usb-next] usb: cdns3: fix missing assignment of ret before error check on ret
@ 2019-09-02 14:50 ` Colin King
  0 siblings, 0 replies; 8+ messages in thread
From: Colin King @ 2019-09-02 14:50 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Felipe Balbi, Pawel Laszczak, linux-usb
  Cc: kernel-janitors, linux-kernel

From: Colin Ian King <colin.king@canonical.com>

Currently the check on a non-zero return code in ret is false because
ret has been initialized to zero.  I believe that ret should be assigned
to the return from the call to readl_poll_timeout_atomic before the
check on ret.  Since ret is being re-assinged the original initialization
of ret to zero can be removed.

Addresses-Coverity: ("'Constant' variable guards dead code")
Fixes: 7733f6c32e36 ("usb: cdns3: Add Cadence USB3 DRD Driver")
Signed-off-by: Colin Ian King <colin.king@canonical.com>
---
 drivers/usb/cdns3/gadget.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/usb/cdns3/gadget.c b/drivers/usb/cdns3/gadget.c
index 3094ad65ffc9..0eb3022838d6 100644
--- a/drivers/usb/cdns3/gadget.c
+++ b/drivers/usb/cdns3/gadget.c
@@ -2154,7 +2154,7 @@ int __cdns3_gadget_ep_clear_halt(struct cdns3_endpoint *priv_ep)
 {
 	struct cdns3_device *priv_dev = priv_ep->cdns3_dev;
 	struct usb_request *request;
-	int ret = 0;
+	int ret;
 	int val;
 
 	trace_cdns3_halt(priv_ep, 0, 0);
@@ -2162,8 +2162,8 @@ int __cdns3_gadget_ep_clear_halt(struct cdns3_endpoint *priv_ep)
 	writel(EP_CMD_CSTALL | EP_CMD_EPRST, &priv_dev->regs->ep_cmd);
 
 	/* wait for EPRST cleared */
-	readl_poll_timeout_atomic(&priv_dev->regs->ep_cmd, val,
-				  !(val & EP_CMD_EPRST), 1, 100);
+	ret = readl_poll_timeout_atomic(&priv_dev->regs->ep_cmd, val,
+					!(val & EP_CMD_EPRST), 1, 100);
 	if (ret)
 		return -EINVAL;
 
-- 
2.20.1

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* RE: [PATCH][usb-next] usb: cdns3: fix missing assignment of ret before error check on ret
  2019-09-02 14:50 ` Colin King
@ 2019-09-02 15:29   ` Pawel Laszczak
  -1 siblings, 0 replies; 8+ messages in thread
From: Pawel Laszczak @ 2019-09-02 15:29 UTC (permalink / raw)
  To: Colin King, Greg Kroah-Hartman, Felipe Balbi, linux-usb
  Cc: kernel-janitors, linux-kernel

Hi Colin

>
>From: Colin Ian King <colin.king@canonical.com>
>
>Currently the check on a non-zero return code in ret is false because
>ret has been initialized to zero.  I believe that ret should be assigned
>to the return from the call to readl_poll_timeout_atomic before the
>check on ret.  Since ret is being re-assinged the original initialization
>of ret to zero can be removed.

Thanks you for letting me know. 
Fortunately that's not a critical bug and has no impact for driver. 
I will correct it.  

Cheers
Pawell

>
>Addresses-Coverity: ("'Constant' variable guards dead code")
>Fixes: 7733f6c32e36 ("usb: cdns3: Add Cadence USB3 DRD Driver")
>Signed-off-by: Colin Ian King <colin.king@canonical.com>
>---
> drivers/usb/cdns3/gadget.c | 6 +++---
> 1 file changed, 3 insertions(+), 3 deletions(-)
>
>diff --git a/drivers/usb/cdns3/gadget.c b/drivers/usb/cdns3/gadget.c
>index 3094ad65ffc9..0eb3022838d6 100644
>--- a/drivers/usb/cdns3/gadget.c
>+++ b/drivers/usb/cdns3/gadget.c
>@@ -2154,7 +2154,7 @@ int __cdns3_gadget_ep_clear_halt(struct cdns3_endpoint *priv_ep)
> {
> 	struct cdns3_device *priv_dev = priv_ep->cdns3_dev;
> 	struct usb_request *request;
>-	int ret = 0;
>+	int ret;
> 	int val;
>
> 	trace_cdns3_halt(priv_ep, 0, 0);
>@@ -2162,8 +2162,8 @@ int __cdns3_gadget_ep_clear_halt(struct cdns3_endpoint *priv_ep)
> 	writel(EP_CMD_CSTALL | EP_CMD_EPRST, &priv_dev->regs->ep_cmd);
>
> 	/* wait for EPRST cleared */
>-	readl_poll_timeout_atomic(&priv_dev->regs->ep_cmd, val,
>-				  !(val & EP_CMD_EPRST), 1, 100);
>+	ret = readl_poll_timeout_atomic(&priv_dev->regs->ep_cmd, val,
>+					!(val & EP_CMD_EPRST), 1, 100);
> 	if (ret)
> 		return -EINVAL;
>

>--
>2.20.1


^ permalink raw reply	[flat|nested] 8+ messages in thread

* RE: [PATCH][usb-next] usb: cdns3: fix missing assignment of ret before error check on ret
@ 2019-09-02 15:29   ` Pawel Laszczak
  0 siblings, 0 replies; 8+ messages in thread
From: Pawel Laszczak @ 2019-09-02 15:29 UTC (permalink / raw)
  To: Colin King, Greg Kroah-Hartman, Felipe Balbi, linux-usb
  Cc: kernel-janitors, linux-kernel

SGkgQ29saW4NCg0KPg0KPkZyb206IENvbGluIElhbiBLaW5nIDxjb2xpbi5raW5nQGNhbm9uaWNh
bC5jb20+DQo+DQo+Q3VycmVudGx5IHRoZSBjaGVjayBvbiBhIG5vbi16ZXJvIHJldHVybiBjb2Rl
IGluIHJldCBpcyBmYWxzZSBiZWNhdXNlDQo+cmV0IGhhcyBiZWVuIGluaXRpYWxpemVkIHRvIHpl
cm8uICBJIGJlbGlldmUgdGhhdCByZXQgc2hvdWxkIGJlIGFzc2lnbmVkDQo+dG8gdGhlIHJldHVy
biBmcm9tIHRoZSBjYWxsIHRvIHJlYWRsX3BvbGxfdGltZW91dF9hdG9taWMgYmVmb3JlIHRoZQ0K
PmNoZWNrIG9uIHJldC4gIFNpbmNlIHJldCBpcyBiZWluZyByZS1hc3NpbmdlZCB0aGUgb3JpZ2lu
YWwgaW5pdGlhbGl6YXRpb24NCj5vZiByZXQgdG8gemVybyBjYW4gYmUgcmVtb3ZlZC4NCg0KVGhh
bmtzIHlvdSBmb3IgbGV0dGluZyBtZSBrbm93LiANCkZvcnR1bmF0ZWx5IHRoYXQncyBub3QgYSBj
cml0aWNhbCBidWcgYW5kIGhhcyBubyBpbXBhY3QgZm9yIGRyaXZlci4gDQpJIHdpbGwgY29ycmVj
dCBpdC4gIA0KDQpDaGVlcnMNClBhd2Vsb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X2NkbnMzX2dhZGdldF9lcF9jbGVhcl9oYWx0KHN0cnVjdCBjZG5zM19lbmRwb2ludCAqcHJpdl9l
cCkNCj4gCXdyaXRlbChFUF9DTURfQ1NUQUxMIHwgRVBfQ01EX0VQUlNULCAmcHJpdl9kZXYtPnJl
Z3MtPmVwX2NtZCk7DQo+DQo+IAkvKiB3YWl0IGZvciBFUFJTVCBjbGVhcmVkICovDQo+LQlyZWFk
bF9wb2xsX3RpbWVvdXRfYXRvbWljKCZwcml2X2Rldi0+cmVncy0+ZXBfY21kLCB2YWwsDQo+LQkJ
CQkgICEodmFsICYgRVBfQ01EX0VQUlNUKSwgMSwgMTAwKTsNCj4rCXJldCA9IHJlYWRsX3BvbGxf
dGltZW91dF9hdG9taWMoJnByaXZfZGV2LT5yZWdzLT5lcF9jbWQsIHZhbCwNCj4rCQkJCQkhKHZh
bCAmIEVQX0NNRF9FUFJTVCksIDEsIDEwMCk7DQo+IAlpZiAocmV0KQ0KPiAJCXJldHVybiAtRUlO
VkFMOw0KPg0KDQo+LS0NCj4yLjIwLjENCg0K

^ permalink raw reply	[flat|nested] 8+ messages in thread

* RE: [PATCH][usb-next] usb: cdns3: fix missing assignment of ret before error check on ret
  2019-09-02 15:29   ` Pawel Laszczak
@ 2019-09-03  3:29     ` Pawel Laszczak
  -1 siblings, 0 replies; 8+ messages in thread
From: Pawel Laszczak @ 2019-09-03  3:29 UTC (permalink / raw)
  To: Colin King, Greg Kroah-Hartman, Felipe Balbi, linux-usb
  Cc: kernel-janitors, linux-kernel

Hi Colin

>Hi Colin
>
>>
>>From: Colin Ian King <colin.king@canonical.com>
>>
>>Currently the check on a non-zero return code in ret is false because
>>ret has been initialized to zero.  I believe that ret should be assigned
>>to the return from the call to readl_poll_timeout_atomic before the
>>check on ret.  Since ret is being re-assinged the original initialization
>>of ret to zero can be removed.
>
>Thanks you for letting me know.
>Fortunately that's not a critical bug and has no impact for driver.
>I will correct it.
>
>Cheers
>Pawell
>
>>
>>Addresses-Coverity: ("'Constant' variable guards dead code")
>>Fixes: 7733f6c32e36 ("usb: cdns3: Add Cadence USB3 DRD Driver")
>>Signed-off-by: Colin Ian King <colin.king@canonical.com>
>>---
>> drivers/usb/cdns3/gadget.c | 6 +++---
>> 1 file changed, 3 insertions(+), 3 deletions(-)
>>
>>diff --git a/drivers/usb/cdns3/gadget.c b/drivers/usb/cdns3/gadget.c
>>index 3094ad65ffc9..0eb3022838d6 100644
>>--- a/drivers/usb/cdns3/gadget.c
>>+++ b/drivers/usb/cdns3/gadget.c
>>@@ -2154,7 +2154,7 @@ int __cdns3_gadget_ep_clear_halt(struct cdns3_endpoint *priv_ep)
>> {
>> 	struct cdns3_device *priv_dev = priv_ep->cdns3_dev;
>> 	struct usb_request *request;
>>-	int ret = 0;
>>+	int ret;
>> 	int val;
>>
>> 	trace_cdns3_halt(priv_ep, 0, 0);
>>@@ -2162,8 +2162,8 @@ int __cdns3_gadget_ep_clear_halt(struct cdns3_endpoint *priv_ep)
>> 	writel(EP_CMD_CSTALL | EP_CMD_EPRST, &priv_dev->regs->ep_cmd);
>>
>> 	/* wait for EPRST cleared */
>>-	readl_poll_timeout_atomic(&priv_dev->regs->ep_cmd, val,
>>-				  !(val & EP_CMD_EPRST), 1, 100);
>>+	ret = readl_poll_timeout_atomic(&priv_dev->regs->ep_cmd, val,
>>+					!(val & EP_CMD_EPRST), 1, 100);
>> 	if (ret)
>> 		return -EINVAL;

What about such condition:
	if (unlikely(ret)) {
		dev_err(priv_dev->dev, "Failed to clear halt %s (timeout).",
			priv_ep->name);
		return ret;
	}

Invalid return value in this place is rather impossible case. If it occurs 
then it should be treated as critical error, so it could be good to have 
information about it.

Cheers,
Pawel

>>
>
>>--
>>2.20.1


^ permalink raw reply	[flat|nested] 8+ messages in thread

* RE: [PATCH][usb-next] usb: cdns3: fix missing assignment of ret before error check on ret
@ 2019-09-03  3:29     ` Pawel Laszczak
  0 siblings, 0 replies; 8+ messages in thread
From: Pawel Laszczak @ 2019-09-03  3:29 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CBjbGVhcmVkICovDQo+Pi0JcmVhZGxfcG9s
bF90aW1lb3V0X2F0b21pYygmcHJpdl9kZXYtPnJlZ3MtPmVwX2NtZCwgdmFsLA0KPj4tCQkJCSAg
ISh2YWwgJiBFUF9DTURfRVBSU1QpLCAxLCAxMDApOw0KPj4rCXJldCA9IHJlYWRsX3BvbGxfdGlt
ZW91dF9hdG9taWMoJnByaXZfZGV2LT5yZWdzLT5lcF9jbWQsIHZhbCwNCj4+KwkJCQkJISh2YWwg
JiBFUF9DTURfRVBSU1QpLCAxLCAxMDApOw0KPj4gCWlmIChyZXQpDQo+PiAJCXJldHVybiAtRUlO
VkFMOw0KDQpXaGF0IGFib3V0IHN1Y2ggY29uZGl0aW9uOg0KCWlmICh1bmxpa2VseShyZXQpKSB7
DQoJCWRldl9lcnIocHJpdl9kZXYtPmRldiwgIkZhaWxlZCB0byBjbGVhciBoYWx0ICVzICh0aW1l
b3V0KS4iLA0KCQkJcHJpdl9lcC0+bmFtZSk7DQoJCXJldHVybiByZXQ7DQoJfQ0KDQpJbnZhbGlk
IHJldHVybiB2YWx1ZSBpbiB0aGlzIHBsYWNlIGlzIHJhdGhlciBpbXBvc3NpYmxlIGNhc2UuIElm
IGl0IG9jY3VycyANCnRoZW4gaXQgc2hvdWxkIGJlIHRyZWF0ZWQgYXMgY3JpdGljYWwgZXJyb3Is
IHNvIGl0IGNvdWxkIGJlIGdvb2QgdG8gaGF2ZSANCmluZm9ybWF0aW9uIGFib3V0IGl0Lg0KDQpD
aGVlcnMsDQpQYXdlbA0KDQo+Pg0KPg0KPj4tLQ0KPj4yLjIwLjENCg0K

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH][usb-next] usb: cdns3: fix missing assignment of ret before error check on ret
  2019-09-03  3:29     ` Pawel Laszczak
@ 2019-09-03 13:43       ` Greg Kroah-Hartman
  -1 siblings, 0 replies; 8+ messages in thread
From: Greg Kroah-Hartman @ 2019-09-03 13:43 UTC (permalink / raw)
  To: Pawel Laszczak
  Cc: Colin King, Felipe Balbi, linux-usb, kernel-janitors, linux-kernel

On Tue, Sep 03, 2019 at 03:29:50AM +0000, Pawel Laszczak wrote:
> Hi Colin
> 
> >Hi Colin
> >
> >>
> >>From: Colin Ian King <colin.king@canonical.com>
> >>
> >>Currently the check on a non-zero return code in ret is false because
> >>ret has been initialized to zero.  I believe that ret should be assigned
> >>to the return from the call to readl_poll_timeout_atomic before the
> >>check on ret.  Since ret is being re-assinged the original initialization
> >>of ret to zero can be removed.
> >
> >Thanks you for letting me know.
> >Fortunately that's not a critical bug and has no impact for driver.
> >I will correct it.
> >
> >Cheers
> >Pawell
> >
> >>
> >>Addresses-Coverity: ("'Constant' variable guards dead code")
> >>Fixes: 7733f6c32e36 ("usb: cdns3: Add Cadence USB3 DRD Driver")
> >>Signed-off-by: Colin Ian King <colin.king@canonical.com>
> >>---
> >> drivers/usb/cdns3/gadget.c | 6 +++---
> >> 1 file changed, 3 insertions(+), 3 deletions(-)
> >>
> >>diff --git a/drivers/usb/cdns3/gadget.c b/drivers/usb/cdns3/gadget.c
> >>index 3094ad65ffc9..0eb3022838d6 100644
> >>--- a/drivers/usb/cdns3/gadget.c
> >>+++ b/drivers/usb/cdns3/gadget.c
> >>@@ -2154,7 +2154,7 @@ int __cdns3_gadget_ep_clear_halt(struct cdns3_endpoint *priv_ep)
> >> {
> >> 	struct cdns3_device *priv_dev = priv_ep->cdns3_dev;
> >> 	struct usb_request *request;
> >>-	int ret = 0;
> >>+	int ret;
> >> 	int val;
> >>
> >> 	trace_cdns3_halt(priv_ep, 0, 0);
> >>@@ -2162,8 +2162,8 @@ int __cdns3_gadget_ep_clear_halt(struct cdns3_endpoint *priv_ep)
> >> 	writel(EP_CMD_CSTALL | EP_CMD_EPRST, &priv_dev->regs->ep_cmd);
> >>
> >> 	/* wait for EPRST cleared */
> >>-	readl_poll_timeout_atomic(&priv_dev->regs->ep_cmd, val,
> >>-				  !(val & EP_CMD_EPRST), 1, 100);
> >>+	ret = readl_poll_timeout_atomic(&priv_dev->regs->ep_cmd, val,
> >>+					!(val & EP_CMD_EPRST), 1, 100);
> >> 	if (ret)
> >> 		return -EINVAL;
> 
> What about such condition:
> 	if (unlikely(ret)) {

Only use likely/unlikely if you can actually measure the performance
impact of not using it.  Otherwise drop it as the compiler and CPU will
almost always get it correct for you (like in this case).

thanks,

greg k-h

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH][usb-next] usb: cdns3: fix missing assignment of ret before error check on ret
@ 2019-09-03 13:43       ` Greg Kroah-Hartman
  0 siblings, 0 replies; 8+ messages in thread
From: Greg Kroah-Hartman @ 2019-09-03 13:43 UTC (permalink / raw)
  To: Pawel Laszczak
  Cc: Colin King, Felipe Balbi, linux-usb, kernel-janitors, linux-kernel

On Tue, Sep 03, 2019 at 03:29:50AM +0000, Pawel Laszczak wrote:
> Hi Colin
> 
> >Hi Colin
> >
> >>
> >>From: Colin Ian King <colin.king@canonical.com>
> >>
> >>Currently the check on a non-zero return code in ret is false because
> >>ret has been initialized to zero.  I believe that ret should be assigned
> >>to the return from the call to readl_poll_timeout_atomic before the
> >>check on ret.  Since ret is being re-assinged the original initialization
> >>of ret to zero can be removed.
> >
> >Thanks you for letting me know.
> >Fortunately that's not a critical bug and has no impact for driver.
> >I will correct it.
> >
> >Cheers
> >Pawell
> >
> >>
> >>Addresses-Coverity: ("'Constant' variable guards dead code")
> >>Fixes: 7733f6c32e36 ("usb: cdns3: Add Cadence USB3 DRD Driver")
> >>Signed-off-by: Colin Ian King <colin.king@canonical.com>
> >>---
> >> drivers/usb/cdns3/gadget.c | 6 +++---
> >> 1 file changed, 3 insertions(+), 3 deletions(-)
> >>
> >>diff --git a/drivers/usb/cdns3/gadget.c b/drivers/usb/cdns3/gadget.c
> >>index 3094ad65ffc9..0eb3022838d6 100644
> >>--- a/drivers/usb/cdns3/gadget.c
> >>+++ b/drivers/usb/cdns3/gadget.c
> >>@@ -2154,7 +2154,7 @@ int __cdns3_gadget_ep_clear_halt(struct cdns3_endpoint *priv_ep)
> >> {
> >> 	struct cdns3_device *priv_dev = priv_ep->cdns3_dev;
> >> 	struct usb_request *request;
> >>-	int ret = 0;
> >>+	int ret;
> >> 	int val;
> >>
> >> 	trace_cdns3_halt(priv_ep, 0, 0);
> >>@@ -2162,8 +2162,8 @@ int __cdns3_gadget_ep_clear_halt(struct cdns3_endpoint *priv_ep)
> >> 	writel(EP_CMD_CSTALL | EP_CMD_EPRST, &priv_dev->regs->ep_cmd);
> >>
> >> 	/* wait for EPRST cleared */
> >>-	readl_poll_timeout_atomic(&priv_dev->regs->ep_cmd, val,
> >>-				  !(val & EP_CMD_EPRST), 1, 100);
> >>+	ret = readl_poll_timeout_atomic(&priv_dev->regs->ep_cmd, val,
> >>+					!(val & EP_CMD_EPRST), 1, 100);
> >> 	if (ret)
> >> 		return -EINVAL;
> 
> What about such condition:
> 	if (unlikely(ret)) {

Only use likely/unlikely if you can actually measure the performance
impact of not using it.  Otherwise drop it as the compiler and CPU will
almost always get it correct for you (like in this case).

thanks,

greg k-h

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2019-09-03 13:43 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-09-02 14:50 [PATCH][usb-next] usb: cdns3: fix missing assignment of ret before error check on ret Colin King
2019-09-02 14:50 ` Colin King
2019-09-02 15:29 ` Pawel Laszczak
2019-09-02 15:29   ` Pawel Laszczak
2019-09-03  3:29   ` Pawel Laszczak
2019-09-03  3:29     ` Pawel Laszczak
2019-09-03 13:43     ` Greg Kroah-Hartman
2019-09-03 13:43       ` Greg Kroah-Hartman

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.