mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Oliver Neukum <oliver@neukum.org>
To: greg@kroah.com
Cc: linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org,
	Brian Merrell <bgmerrell@novell.com>,
	Takahiro Hirofuchi <hirofuchi@users.sourceforge.net>,
	gregkh@suse.de
Subject: Re: [patch 02/03] USB: USB/IP: add client driver
Date: Fri, 29 Aug 2008 10:23:26 +0200	[thread overview]
Message-ID: <200808291023.27132.oliver@neukum.org> (raw)
In-Reply-To: <20080828230035.GC15014@kroah.com>

Am Freitag 29 August 2008 01:00:35 schrieb greg@kroah.com:
> From: Takahiro Hirofuchi <hirofuchi@users.sourceforge.net>

> +			dum->port_status[rhport] |=
> +					(1 << USB_PORT_FEAT_C_SUSPEND);
> +			dum->port_status[rhport] &=
> +					~(1 << USB_PORT_FEAT_SUSPEND);
> +			dum->resuming = 0;
> +			dum->re_timeout = 0;
> +			/* if (dum->driver && dum->driver->resume) {
> +			 *	spin_unlock (&dum->lock);

I realise it is commented out, but still.

The resume method may sleep. It is documented as such. Thus it can
reenable interrupts. Therefore you can deadlock if you don't use irqrestore.


> +static void vhci_tx_urb(struct urb *urb)
> +{
> +	struct vhci_device *vdev = get_vdev(urb->dev);
> +	struct vhci_priv *priv;
> +	unsigned long flag;
> +
> +	if (!vdev) {
> +		err("could not get virtual device");
> +		/* BUG(); */
> +		return;
> +	}
> +
> +	spin_lock_irqsave(&vdev->priv_lock, flag);
> +
> +	priv = kzalloc(sizeof(struct vhci_priv), GFP_ATOMIC);

There's no reason to hold the lock longer than necessary by
allocating memory in the lock section.

[..]
> +	wake_up(&vdev->waitq_tx);
> +	spin_unlock_irqrestore(&vdev->priv_lock, flag);

again

> +static int vhci_urb_enqueue(struct usb_hcd *hcd, struct urb *urb,
> +			    gfp_t mem_flags)
> +{

This is called in the context of usb_submit_urb()

[..]
> +	ret = usb_hcd_link_urb_to_ep(hcd, urb);

This can fail for any urb due to urb->reject

> +	if (ret)
> +		goto no_need_unlink;

The branch would be taken

[..]
> +no_need_unlink:
> +	spin_unlock_irqrestore(&the_controller->lock, flags);
> +
> +	usb_hcd_giveback_urb(vhci_to_hcd(the_controller), urb, urb->status);

This calls urb->complete. If the completion handler takes a spinlock
which is held when usb_submit_urb() was called, you deadlock.

> +static int vhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)

[..]
> +		spin_unlock_irqrestore(&the_controller->lock, flags);
> +		usb_hcd_giveback_urb(vhci_to_hcd(the_controller), urb,
> +								urb->status);

This must be called with interrupts disabled.

> +		spin_lock_irqsave(&the_controller->lock, flags);
> +	}
> +
> +	spin_unlock_irqrestore(&the_controller->lock, flags);
> +
> +	dbg_vhci_hc("leave\n");
> +	return 0;
> +}

	Regards
		Oliver

  reply	other threads:[~2008-08-29  8:22 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20080828225248.758800945@mini.kroah.org>
2008-08-28 23:00 ` [patch 00/03] USB-IP patches greg
2008-08-28 23:00   ` [patch 01/03] USB: USB/IP: add common functions needed greg
2008-08-29  7:29     ` Oliver Neukum
2008-08-29  7:52     ` Alexander E. Patrakov
2008-08-29 14:32       ` Greg KH
2008-08-30  0:14     ` Andrew Morton
2008-08-28 23:00   ` [patch 02/03] USB: USB/IP: add client driver greg
2008-08-29  8:23     ` Oliver Neukum [this message]
2008-08-29 16:02     ` Alan Stern
2008-08-28 23:00   ` [patch 03/03] USB: USB/IP: add host driver greg
2008-08-29  5:43     ` Willy Tarreau
2008-08-28 23:06   ` [patch 00/03] USB-IP patches Arnaldo Carvalho de Melo
2008-08-30  5:50   ` Brian G. Merrell
2008-09-02 17:12     ` Greg KH
2008-09-24  1:28       ` Brian G. Merrell

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=200808291023.27132.oliver@neukum.org \
    --to=oliver@neukum.org \
    --cc=bgmerrell@novell.com \
    --cc=greg@kroah.com \
    --cc=gregkh@suse.de \
    --cc=hirofuchi@users.sourceforge.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.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

all inboxes | Powered by JetHome®