linux-usb.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Robert Jarzmik <robert.jarzmik@free.fr>
To: Felipe Balbi <balbi@kernel.org>
Cc: Jia-Ju Bai <baijiaju1990@gmail.com>,
	gregkh@linuxfoundation.org, nicolas.ferre@microchip.com,
	keescook@chromium.org, allen.lkml@gmail.com,
	linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [1/2] usb: gadget: r8a66597: Fix two possible sleep-in-atomic-context bugs in init_controller()
Date: Fri, 29 Jun 2018 13:04:58 +0200	[thread overview]
Message-ID: <87a7rdlup1.fsf@belgarion.home> (raw)

Felipe Balbi <balbi@kernel.org> writes:

> Hi,
>
> Robert Jarzmik <robert.jarzmik@free.fr> writes:
>>>>> The driver may sleep with holding a spinlock.
>>>>> The function call paths (from bottom to top) in Linux-4.16.7 are:
>>>>>
>>>>> [FUNC] msleep
>>>>> drivers/usb/gadget/udc/r8a66597-udc.c, 839: 
>>>>> 		msleep in init_controller
>>>>> drivers/usb/gadget/udc/r8a66597-udc.c, 96: 
>>>>> 		init_controller in r8a66597_usb_disconnect
>>>>> drivers/usb/gadget/udc/r8a66597-udc.c, 93: 
>>>>> 		spin_lock in r8a66597_usb_disconnect
>>>>
>>>> That should not happen...
>>>>
>>>> If think the issue you have is that your usb_connect() and usb_disconnect() are
>>>> called from interrupt context. I think the proper fix, as what is done in most
>>>> udc phys, is to schedule a workqueue, see drivers/usb/phy/phy-gpio-vbus-usb.c,
>>>> gpio_vbus_data.vbus.
>>>
>>> argh, no. No workqueues needed here. Sorry
>> Technically why ?
>
> well, strictly technically there's nothing wrong. But it opens a can of
> worms. We've seen time and time again drivers growing into
> unmaintainable mess because of workqueues being fired in several places.
I see.

>>
>> And as bonus question, why is it better to have mdelay() calls in the driver ?
>
> As a bugfix, it's the smallest fix possible, right? Ideally, we wouldn't
> need either of them. Perhaps there's a bit which can be polled instead?
Ideally yes. Do you remember if a "threaded interrupt" might use msleep() ? I
seem to remember that they can, so won't that be another alternative ?

Cheers.

             reply	other threads:[~2018-06-29 11:04 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-06-29 11:04 Robert Jarzmik [this message]
  -- strict thread matches above, loose matches on Subject: below --
2018-06-29 13:21 [1/2] usb: gadget: r8a66597: Fix two possible sleep-in-atomic-context bugs in init_controller() Robert Jarzmik
2018-06-29 11:15 Felipe Balbi
2018-06-29 10:25 Felipe Balbi
2018-06-29  6:48 Robert Jarzmik
2018-06-29  6:35 Felipe Balbi
2018-06-21  9:06 Robert Jarzmik
2018-06-20  3:54 Jia-Ju Bai

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=87a7rdlup1.fsf@belgarion.home \
    --to=robert.jarzmik@free.fr \
    --cc=allen.lkml@gmail.com \
    --cc=baijiaju1990@gmail.com \
    --cc=balbi@kernel.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=keescook@chromium.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=nicolas.ferre@microchip.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).