From: "Bjørn Mork" <bjorn@mork.no>
To: Oliver Neukum <oneukum@suse.com>
Cc: syzbot <syzbot+d232cca6ec42c2edb3fc@syzkaller.appspotmail.com>,
gustavo@embeddedor.com, andreyknvl@google.com,
syzkaller-bugs@googlegroups.com, gregkh@linuxfoundation.org,
linux-usb@vger.kernel.org
Subject: Re: WARNING in wdm_write/usb_submit_urb
Date: Tue, 20 Aug 2019 12:44:20 +0200 [thread overview]
Message-ID: <87sgpw5d6j.fsf@miraculix.mork.no> (raw)
In-Reply-To: <1566297095.11678.11.camel@suse.com> (Oliver Neukum's message of "Tue, 20 Aug 2019 12:31:35 +0200")
Oliver Neukum <oneukum@suse.com> writes:
> diff --git a/drivers/usb/class/cdc-wdm.c b/drivers/usb/class/cdc-wdm.c
> index 1656f5155ab8..a341081a5f47 100644
> --- a/drivers/usb/class/cdc-wdm.c
> +++ b/drivers/usb/class/cdc-wdm.c
> @@ -588,14 +588,24 @@ static int wdm_flush(struct file *file, fl_owner_t id)
> {
> struct wdm_device *desc = file->private_data;
>
> - wait_event(desc->wait, !test_bit(WDM_IN_USE, &desc->flags));
> + wait_event(desc->wait,
> + /*
> + * needs both flags. We cannot do with one
> + * because resetting it would cause a race
> + * with write() yet we need to signal
> + * a disconnect
> + */
> + !test_bit(WDM_IN_USE, &desc->flags) &&
> + !test_bit(WDM_DISCONNECTING, &desc->flags));
Makes sense. But isn't the WDM_DISCONNECTING test inverted?
> /* cannot dereference desc->intf if WDM_DISCONNECTING */
> if (desc->werr < 0 && !test_bit(WDM_DISCONNECTING, &desc->flags))
> dev_err(&desc->intf->dev, "Error in flush path: %d\n",
> desc->werr);
>
> - return usb_translate_errors(desc->werr);
> + return test_bit(WDM_DISCONNECTING, &desc->flags) ?
> + -ENODEV :
> + usb_translate_errors(desc->werr);
> }
Minor detail, but there's an awful lot of test_bit(WDM_DISCONNECTING)
here. How about
if (test_bit(WDM_DISCONNECTING, &desc->flags))
return -ENODEV;
if (desc->werr < 0)
dev_err(&desc->intf->dev, "Error in flush path: %d\n", desc->werr);
return usb_translate_errors(desc->werr);
> static __poll_t wdm_poll(struct file *file, struct poll_table_struct *wait)
> @@ -975,8 +985,6 @@ static void wdm_disconnect(struct usb_interface *intf)
> spin_lock_irqsave(&desc->iuspin, flags);
> set_bit(WDM_DISCONNECTING, &desc->flags);
> set_bit(WDM_READ, &desc->flags);
> - /* to terminate pending flushes */
> - clear_bit(WDM_IN_USE, &desc->flags);
> spin_unlock_irqrestore(&desc->iuspin, flags);
> wake_up_all(&desc->wait);
> mutex_lock(&desc->rlock);
Yes, this looks much better.
Bjørn
next prev parent reply other threads:[~2019-08-20 10:56 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-08-19 14:48 WARNING in wdm_write/usb_submit_urb syzbot
2019-08-20 0:50 ` syzbot
2019-08-20 10:31 ` Oliver Neukum
2019-08-20 10:44 ` Bjørn Mork [this message]
2019-08-20 12:27 ` Oliver Neukum
2019-08-20 10:45 ` syzbot
2019-08-20 10:59 ` Oliver Neukum
2019-08-20 11:18 ` syzbot
2019-08-20 12:28 ` Oliver Neukum
2019-08-20 12:48 ` syzbot
2019-08-20 13:13 ` Bjørn Mork
2019-08-20 13:40 ` Oliver Neukum
2019-08-20 13:41 ` Oliver Neukum
2019-08-20 14:00 ` syzbot
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=87sgpw5d6j.fsf@miraculix.mork.no \
--to=bjorn@mork.no \
--cc=andreyknvl@google.com \
--cc=gregkh@linuxfoundation.org \
--cc=gustavo@embeddedor.com \
--cc=linux-usb@vger.kernel.org \
--cc=oneukum@suse.com \
--cc=syzbot+d232cca6ec42c2edb3fc@syzkaller.appspotmail.com \
--cc=syzkaller-bugs@googlegroups.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 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).