Skip to contentSkip to conversation

usb: renesas_usbhs: fix error return code of usbhsf_pkt_handler()

PATCH In review Jia-Ju Bai 2 participants 6 messages Mar 7, 2021 – Mar 10, 2021 USB

lore
Share & tools
lore

Jia-Ju Bai

author
#0 lore raw

PATCH 1/1 usb: renesas_usbhs: fix error return code of usbhsf_pkt_handler()

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.

---
 drivers/usb/renesas_usbhs/fifo.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/usb/renesas_usbhs/fifo.c +3 -1
index e6fa13701808..b5e7991dc7d9 100644
@@ -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:
Signature · 1 line
2.17.1
#1 lore raw

Hi Jia-Ju,

Thank you for the patch!

Quoted 4 lines

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

Quoted 1 line

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

author
#2 lore raw

Thanks for the reply!

Quoted 11 lines · Yoshihiro Shimoda

Hi Jia-Ju,

Thank you for the patch!

Quoted 4 lines

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

#3 lore raw

Hi Jia-Ju,

Quoted 8 lines

From: Jia-Ju Bai, Sent: Tuesday, March 9, 2021 10:39 PM

Quoted 6 lines · Yoshihiro Shimoda

Hi Jia-Ju,

Thank you for the patch!

Quoted 2 lines

From: Jia-Ju Bai, Sent: Sunday, March 7, 2021 6:01 PM

Quoted 8 lines
Quoted 5 lines
Quoted 2 lines

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

author
#4 lore raw
Quoted 12 lines · Yoshihiro Shimoda

Hi Jia-Ju,

Quoted 10 lines

From: Jia-Ju Bai, Sent: Tuesday, March 9, 2021 10:39 PM

Quoted 8 lines · Yoshihiro Shimoda

Hi Jia-Ju,

Thank you for the patch!

Quoted 4 lines

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.

Quoted 8 lines
Quoted 5 lines
Quoted 3 lines

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

#5 lore raw
Quoted 10 lines
Quoted 9 lines · Yoshihiro Shimoda
Quoted 9 lines

From: Jia-Ju Bai, Sent: Tuesday, March 9, 2021 10:39 PM

Quoted 7 lines · Yoshihiro Shimoda
Quoted 4 lines

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.

Quoted 7 lines
Quoted 5 lines
Quoted 2 lines

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