All of lore.kernel.org
 help / color / mirror / Atom feed
From: Robert Hodaszi <robert.hodaszi@digi.com>
To: "Oliver Neukum" <oneukum@suse.com>,
	"linux-usb@vger.kernel.org" <linux-usb@vger.kernel.org>,
	"Bjørn Mork" <bjorn@mork.no>
Subject: Re: Handling incoming ZLP in cdc-wdm
Date: Wed, 2 Apr 2025 17:01:12 +0200	[thread overview]
Message-ID: <8de930f3-2e87-443d-9e8f-9d6f16f7a399@digi.com> (raw)
In-Reply-To: <28a5c207-6c2e-42e1-9568-2f949554026e@suse.com>

>
> Hi,
>
> I see what you mean, but I am afraid this introduces an error case.
>
> Suppose we have the following scenario with your patch applied:
>
> wdm_in_callback() gets a ZLP -> we schedule service_interrupt_work()
> service_interrupt_work() calls service_outstanding_interrupt()
> service_outstanding_interrupt() decrements resp_count to zero
> service_interrupt_work() sets WDM_READ and wakes the waiting task
>
> wdm_read() is woken up and finds an empty buffer
> If reslength == 0 all is well and it returns -EAGAIN to user space
> If reslength != 0 it will return EOF
>
> We must not return EOF.
> Hence the longer I think about it it seems to me that
>
> 1. reslength is necessary
> 2. You must set reslength to 0 whenever you get a ZLP
>
>        Regards
>                Oliver
>
That's a good point! So that's the case, when we receive only a single 
ZLP, and nothing else.

But we cannot return with -EAGAIN. If we do that, we're back to sqrt(1), 
and get stuck again.

So what about modifying the service_interrupt_work to no simply set 
WDM_READ if resp_count is 0, but instead to check if there's any real 
message in the buffer, to not confuse consumers. Something like this:

    diff --git a/drivers/usb/class/cdc-wdm.c b/drivers/usb/class/cdc-wdm.c
    index 37873acd18f4..9037379f3603 100644
    --- a/drivers/usb/class/cdc-wdm.c
    +++ b/drivers/usb/class/cdc-wdm.c
    @@ -1010,7 +1010,7 @@ static void service_interrupt_work(struct
    work_struct *work)

             spin_lock_irq(&desc->iuspin);
             service_outstanding_interrupt(desc);
    -       if (!desc->resp_count) {
    +       if (!desc->resp_count && (desc->length || desc->rerr)) {
                     set_bit(WDM_READ, &desc->flags);
                     wake_up(&desc->wait);
             }


Best regards,
Robert


  reply	other threads:[~2025-04-02 15:01 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-03-26 16:03 Handling incoming ZLP in cdc-wdm Hodaszi, Robert
2025-03-27 13:01 ` Robert Hodaszi
2025-03-27 13:24   ` Oliver Neukum
2025-03-27 15:27     ` Robert Hodaszi
2025-03-31  9:59       ` Oliver Neukum
2025-04-02 11:57         ` Robert Hodaszi
2025-04-02 14:01           ` Oliver Neukum
2025-04-02 15:01             ` Robert Hodaszi [this message]
2025-04-02 19:13               ` Oliver Neukum
2025-04-03 12:25                 ` Robert Hodaszi
     [not found]                 ` <898977f7-3882-4ffe-8833-c44f06914337@digi.com>
2025-04-03 12:58                   ` Oliver Neukum
2025-04-03 14:42                     ` Robert Hodaszi
  -- strict thread matches above, loose matches on Subject: below --
2025-03-26 15:50 Robert Hodaszi
2025-03-27 13:21 ` Oliver Neukum
2025-03-27 15:23   ` Robert Hodaszi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=8de930f3-2e87-443d-9e8f-9d6f16f7a399@digi.com \
    --to=robert.hodaszi@digi.com \
    --cc=bjorn@mork.no \
    --cc=linux-usb@vger.kernel.org \
    --cc=oneukum@suse.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.