linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] usb: renesas_usbhs: fix error return code of usbhsf_pkt_handler()
@ 2021-03-07  9:00 Jia-Ju Bai
  2021-03-09 11:59 ` Yoshihiro Shimoda
  0 siblings, 1 reply; 6+ messages in thread
From: Jia-Ju Bai @ 2021-03-07  9:00 UTC (permalink / raw)
  To: gregkh, yoshihiro.shimoda.uh; +Cc: linux-usb, linux-kernel, Jia-Ju Bai

When __usbhsf_pkt_get() returns NULL to pkt, no error return code of
usbhsf_pkt_handler() is assigned.
To fix this bug, ret is assigned with -EINVAL in this case.

Reported-by: TOTE Robot <oslab@tsinghua.edu.cn>
Signed-off-by: Jia-Ju Bai <baijiaju1990@gmail.com>
---
 drivers/usb/renesas_usbhs/fifo.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/usb/renesas_usbhs/fifo.c b/drivers/usb/renesas_usbhs/fifo.c
index e6fa13701808..b5e7991dc7d9 100644
--- a/drivers/usb/renesas_usbhs/fifo.c
+++ b/drivers/usb/renesas_usbhs/fifo.c
@@ -160,8 +160,10 @@ static int usbhsf_pkt_handler(struct usbhs_pipe *pipe, int type)
 	usbhs_lock(priv, flags);
 
 	pkt = __usbhsf_pkt_get(pipe);
-	if (!pkt)
+	if (!pkt) {
+		ret = -EINVAL;
 		goto __usbhs_pkt_handler_end;
+	}
 
 	switch (type) {
 	case USBHSF_PKT_PREPARE:
-- 
2.17.1


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

* RE: [PATCH] usb: renesas_usbhs: fix error return code of usbhsf_pkt_handler()
  2021-03-07  9:00 [PATCH] usb: renesas_usbhs: fix error return code of usbhsf_pkt_handler() Jia-Ju Bai
@ 2021-03-09 11:59 ` Yoshihiro Shimoda
  2021-03-09 13:38   ` Jia-Ju Bai
  0 siblings, 1 reply; 6+ messages in thread
From: Yoshihiro Shimoda @ 2021-03-09 11:59 UTC (permalink / raw)
  To: Jia-Ju Bai; +Cc: linux-usb, linux-kernel, gregkh

Hi Jia-Ju,

Thank you for the patch!

> From: Jia-Ju Bai, Sent: Sunday, March 7, 2021 6:01 PM
> 
> When __usbhsf_pkt_get() returns NULL to pkt, no error return code of
> usbhsf_pkt_handler() is assigned.

Yes. Also I realized that no error return code of usbhsf_pkt_handler()
was assigned if the type value was unexpected value. So, I'm thinking
initial value of ret should be -EINVAL instead of 0.
---
        int ret = 0;  // should be -EINVAL
        int is_done = 0;

        /********************  spin lock ********************/
        usbhs_lock(priv, flags);

        pkt = __usbhsf_pkt_get(pipe);
        if (!pkt)
                goto __usbhs_pkt_handler_end;

        switch (type) {
        case USBHSF_PKT_PREPARE:
                func = pkt->handler->prepare;
                break;
        case USBHSF_PKT_TRY_RUN:
                func = pkt->handler->try_run;
                break;
        case USBHSF_PKT_DMA_DONE:
                func = pkt->handler->dma_done;
                break;
        default:
                dev_err(dev, "unknown pkt handler\n");
                goto __usbhs_pkt_handler_end;    /// here
        }

        if (likely(func))  /// [1]
                ret = func(pkt, &is_done);

[1] This is always true here, so ret is always assigned by the func().
---

> To fix this bug, ret is assigned with -EINVAL in this case.

Just a record: After fixed this, actual behavior is almost the same
except printing error message.

Best regards,
Yoshihiro Shimoda


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

* Re: [PATCH] usb: renesas_usbhs: fix error return code of usbhsf_pkt_handler()
  2021-03-09 11:59 ` Yoshihiro Shimoda
@ 2021-03-09 13:38   ` Jia-Ju Bai
  2021-03-10  2:54     ` Yoshihiro Shimoda
  0 siblings, 1 reply; 6+ messages in thread
From: Jia-Ju Bai @ 2021-03-09 13:38 UTC (permalink / raw)
  To: Yoshihiro Shimoda; +Cc: linux-usb, linux-kernel, gregkh

Thanks for the reply!

On 2021/3/9 19:59, Yoshihiro Shimoda wrote:
> Hi Jia-Ju,
>
> Thank you for the patch!
>
>> From: Jia-Ju Bai, Sent: Sunday, March 7, 2021 6:01 PM
>>
>> When __usbhsf_pkt_get() returns NULL to pkt, no error return code of
>> usbhsf_pkt_handler() is assigned.
> Yes. Also I realized that no error return code of usbhsf_pkt_handler()
> was assigned if the type value was unexpected value. So, I'm thinking
> initial value of ret should be -EINVAL instead of 0.

This is okay to me.
Need I write a new patch for this?


Best wishes,
Jia-Ju Bai

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

* RE: [PATCH] usb: renesas_usbhs: fix error return code of usbhsf_pkt_handler()
  2021-03-09 13:38   ` Jia-Ju Bai
@ 2021-03-10  2:54     ` Yoshihiro Shimoda
  2021-03-10  3:20       ` Jia-Ju Bai
  0 siblings, 1 reply; 6+ messages in thread
From: Yoshihiro Shimoda @ 2021-03-10  2:54 UTC (permalink / raw)
  To: Jia-Ju Bai; +Cc: linux-usb, linux-kernel, gregkh

Hi Jia-Ju,

> From: Jia-Ju Bai, Sent: Tuesday, March 9, 2021 10:39 PM
> On 2021/3/9 19:59, Yoshihiro Shimoda wrote:
> > Hi Jia-Ju,
> >
> > Thank you for the patch!
> >
> >> From: Jia-Ju Bai, Sent: Sunday, March 7, 2021 6:01 PM
> >>
> >> When __usbhsf_pkt_get() returns NULL to pkt, no error return code of
> >> usbhsf_pkt_handler() is assigned.
> > Yes. Also I realized that no error return code of usbhsf_pkt_handler()
> > was assigned if the type value was unexpected value. So, I'm thinking
> > initial value of ret should be -EINVAL instead of 0.
> 
> This is okay to me.
> Need I write a new patch for this?

Thank you for your reply. I can write such a new patch with your
Reported-by for this as minor refactoring of the usbhsf_pkt_handler().
May I write such a patch?

Best regards,
Yoshihiro Shimoda


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

* Re: [PATCH] usb: renesas_usbhs: fix error return code of usbhsf_pkt_handler()
  2021-03-10  2:54     ` Yoshihiro Shimoda
@ 2021-03-10  3:20       ` Jia-Ju Bai
  2021-03-10  5:18         ` Yoshihiro Shimoda
  0 siblings, 1 reply; 6+ messages in thread
From: Jia-Ju Bai @ 2021-03-10  3:20 UTC (permalink / raw)
  To: Yoshihiro Shimoda; +Cc: linux-usb, linux-kernel, gregkh



On 2021/3/10 10:54, Yoshihiro Shimoda wrote:
> Hi Jia-Ju,
>
>> From: Jia-Ju Bai, Sent: Tuesday, March 9, 2021 10:39 PM
>> On 2021/3/9 19:59, Yoshihiro Shimoda wrote:
>>> Hi Jia-Ju,
>>>
>>> Thank you for the patch!
>>>
>>>> From: Jia-Ju Bai, Sent: Sunday, March 7, 2021 6:01 PM
>>>>
>>>> When __usbhsf_pkt_get() returns NULL to pkt, no error return code of
>>>> usbhsf_pkt_handler() is assigned.
>>> Yes. Also I realized that no error return code of usbhsf_pkt_handler()
>>> was assigned if the type value was unexpected value. So, I'm thinking
>>> initial value of ret should be -EINVAL instead of 0.
>> This is okay to me.
>> Need I write a new patch for this?
> Thank you for your reply. I can write such a new patch with your
> Reported-by for this as minor refactoring of the usbhsf_pkt_handler().
> May I write such a patch?

Okay, sure :)


Best wishes,
Jia-Ju Bai

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

* RE: [PATCH] usb: renesas_usbhs: fix error return code of usbhsf_pkt_handler()
  2021-03-10  3:20       ` Jia-Ju Bai
@ 2021-03-10  5:18         ` Yoshihiro Shimoda
  0 siblings, 0 replies; 6+ messages in thread
From: Yoshihiro Shimoda @ 2021-03-10  5:18 UTC (permalink / raw)
  To: Jia-Ju Bai; +Cc: linux-usb, linux-kernel, gregkh

> From: Jia-Ju Bai, On 2021/3/10 10:54, Yoshihiro Shimoda wrote:
> >> From: Jia-Ju Bai, Sent: Tuesday, March 9, 2021 10:39 PM
> >> On 2021/3/9 19:59, Yoshihiro Shimoda wrote:
> >>>> From: Jia-Ju Bai, Sent: Sunday, March 7, 2021 6:01 PM
> >>>>
> >>>> When __usbhsf_pkt_get() returns NULL to pkt, no error return code of
> >>>> usbhsf_pkt_handler() is assigned.
> >>> Yes. Also I realized that no error return code of usbhsf_pkt_handler()
> >>> was assigned if the type value was unexpected value. So, I'm thinking
> >>> initial value of ret should be -EINVAL instead of 0.
> >> This is okay to me.
> >> Need I write a new patch for this?
> > Thank you for your reply. I can write such a new patch with your
> > Reported-by for this as minor refactoring of the usbhsf_pkt_handler().
> > May I write such a patch?
> 
> Okay, sure :)

I got it :)

Best regards,
Yoshihiro Shimoda


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

end of thread, other threads:[~2021-03-10  5:19 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-07  9:00 [PATCH] usb: renesas_usbhs: fix error return code of usbhsf_pkt_handler() Jia-Ju Bai
2021-03-09 11:59 ` Yoshihiro Shimoda
2021-03-09 13:38   ` Jia-Ju Bai
2021-03-10  2:54     ` Yoshihiro Shimoda
2021-03-10  3:20       ` Jia-Ju Bai
2021-03-10  5:18         ` Yoshihiro Shimoda

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).