From: boris.brezillon@free-electrons.com (Boris Brezillon)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCHv4 2/3] USB: gadget: atmel_usba_udc: Enable Vbus signal IRQ in UDC start instead of UDC probe
Date: Wed, 21 Jan 2015 10:20:16 +0100 [thread overview]
Message-ID: <20150121102016.064a33ce@bbrezillon> (raw)
In-Reply-To: <1421789010-21900-3-git-send-email-sylvain.rochet@finsecur.com>
Hi Sylvain,
On Tue, 20 Jan 2015 22:23:29 +0100
Sylvain Rochet <sylvain.rochet@finsecur.com> wrote:
> Vbus IRQ handler needs a started UDC driver to work because it uses
> udc->driver, which is set by the UDC start handler. The previous way
> chosen was to return from interrupt if udc->driver is NULL using a
> spinlock.
>
> This patch now request the Vbus signal IRQ in UDC start instead of UDC
> probe and release the IRQ in UDC stop before udc->driver is set back to
> NULL. This way we don't need the check about udc->driver in interruption
> handler, therefore we don't need the spinlock as well anymore.
>
> This was chosen against using set_irq_flags() to request a not auto
> enabled IRQ (IRQF_NOAUTOEN flag) because set_irq_flags() can't change
> just one flag, therefore it must be called with all flags, without
> respecting what the AIC previously did. Naively copying IRQ flags
> currently set by the AIC looked like error-prone if defaults flags
> change at some point in the future.
>
> Signed-off-by: Sylvain Rochet <sylvain.rochet@finsecur.com>
> Suggested-by: Boris Brezillon <boris.brezillon@free-electrons.com>
> ---
> drivers/usb/gadget/udc/atmel_usba_udc.c | 64 ++++++++++++++++-----------------
> 1 file changed, 32 insertions(+), 32 deletions(-)
>
> diff --git a/drivers/usb/gadget/udc/atmel_usba_udc.c b/drivers/usb/gadget/udc/atmel_usba_udc.c
> index e207d75..546da63 100644
> --- a/drivers/usb/gadget/udc/atmel_usba_udc.c
> +++ b/drivers/usb/gadget/udc/atmel_usba_udc.c
> @@ -1729,10 +1729,6 @@ static irqreturn_t usba_vbus_irq(int irq, void *devid)
>
> spin_lock(&udc->lock);
>
> - /* May happen if Vbus pin toggles during probe() */
> - if (!udc->driver)
> - goto out;
> -
> vbus = vbus_is_present(udc);
> if (vbus != udc->vbus_prev) {
> if (vbus) {
> @@ -1753,7 +1749,6 @@ static irqreturn_t usba_vbus_irq(int irq, void *devid)
> udc->vbus_prev = vbus;
> }
>
> -out:
> spin_unlock(&udc->lock);
>
> return IRQ_HANDLED;
> @@ -1767,23 +1762,27 @@ static int atmel_usba_start(struct usb_gadget *gadget,
> unsigned long flags;
>
> spin_lock_irqsave(&udc->lock, flags);
> -
> udc->devstatus = 1 << USB_DEVICE_SELF_POWERED;
> udc->driver = driver;
> spin_unlock_irqrestore(&udc->lock, flags);
>
> ret = clk_prepare_enable(udc->pclk);
> if (ret)
> - return ret;
> + goto err_pclk;
> ret = clk_prepare_enable(udc->hclk);
> - if (ret) {
> - clk_disable_unprepare(udc->pclk);
> - return ret;
> - }
> + if (ret)
> + goto err_hclk;
>
> udc->vbus_prev = 0;
> - if (gpio_is_valid(udc->vbus_pin))
> - enable_irq(gpio_to_irq(udc->vbus_pin));
> + if (gpio_is_valid(udc->vbus_pin)) {
> + ret = request_irq(gpio_to_irq(udc->vbus_pin),
> + usba_vbus_irq, 0,
> + "atmel_usba_udc", udc);
> + if (ret) {
> + udc->vbus_pin = -ENODEV;
I guess you're trying to protect against free_irq by changing the
vbus_pin value (making it an invalid gpio id), but I think you should
leave it unchanged for two reasons:
1) If the request_irq call temporary fails (an ENOMEM for example) then
you should be able to retry later, and modifying the vbus_pin value
will prevent that.
2) atmel_usba_stop will never be called if the atmel_usba_start failed,
so there's no need to protect against this free_irq.
Best Regards,
Boris
--
Boris Brezillon, Free Electrons
Embedded Linux and Kernel engineering
http://free-electrons.com
next prev parent reply other threads:[~2015-01-21 9:20 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-01-20 21:23 [PATCHv4 0/3] USB: gadget: atmel_usba_udc: Start clocks on rising edge of the Vbus signal, stop clocks on falling edge of the Vbus signal Sylvain Rochet
2015-01-20 21:23 ` [PATCHv4 1/3] USB: gadget: atmel_usba_udc: Fixed vbus_prev initial state Sylvain Rochet
2015-01-20 21:23 ` [PATCHv4 2/3] USB: gadget: atmel_usba_udc: Enable Vbus signal IRQ in UDC start instead of UDC probe Sylvain Rochet
2015-01-21 9:20 ` Boris Brezillon [this message]
2015-01-21 13:18 ` Sylvain Rochet
2015-01-20 21:23 ` [PATCHv4 3/3] USB: gadget: atmel_usba_udc: Start clocks on rising edge of the Vbus signal, stop clocks on falling edge of the Vbus signal Sylvain Rochet
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=20150121102016.064a33ce@bbrezillon \
--to=boris.brezillon@free-electrons.com \
--cc=linux-arm-kernel@lists.infradead.org \
/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).