linux-usb.vger.kernel.org archive mirror
 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
  2019-09-02 15:29 ` Pawel Laszczak
  0 siblings, 1 reply; 4+ 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] 4+ messages in thread

* RE: [PATCH][usb-next] usb: cdns3: fix missing assignment of ret before error check on ret
  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 15:29 ` Pawel Laszczak
  2019-09-03  3:29   ` Pawel Laszczak
  0 siblings, 1 reply; 4+ 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] 4+ 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
  2019-09-03 13:43     ` Greg Kroah-Hartman
  0 siblings, 1 reply; 4+ 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] 4+ 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
  0 siblings, 0 replies; 4+ 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] 4+ messages in thread

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

Thread overview: 4+ 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 15:29 ` Pawel Laszczak
2019-09-03  3:29   ` Pawel Laszczak
2019-09-03 13:43     ` Greg Kroah-Hartman

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).