mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Peter Mamonov <pmamonov@gmail.com>
To: barebox@lists.infradead.org
Cc: Peter Mamonov <pmamonov@gmail.com>
Subject: [PATCH 2/2] usb: core: return -EAGAIN on usb_* functions reentrance
Date: Wed, 14 Oct 2015 13:15:49 +0300	[thread overview]
Message-ID: <1444817749-20766-3-git-send-email-pmamonov@gmail.com> (raw)
In-Reply-To: <1444817749-20766-1-git-send-email-pmamonov@gmail.com>

Signed-off-by: Peter Mamonov <pmamonov@gmail.com>
---
 drivers/usb/core/usb.c | 40 +++++++++++++++++++++++++++++++++++++++-
 include/usb/usb.h      |  1 +
 2 files changed, 40 insertions(+), 1 deletion(-)

diff --git a/drivers/usb/core/usb.c b/drivers/usb/core/usb.c
index a3fb1e8..ce229f2 100644
--- a/drivers/usb/core/usb.c
+++ b/drivers/usb/core/usb.c
@@ -84,10 +84,25 @@ static void print_usb_device(struct usb_device *dev)
 
 static int host_busnum = 1;
 
+static inline int usb_host_acquire(struct usb_host *host)
+{
+	if (host->sem)
+		return -EAGAIN;
+	host->sem++;
+	return 0;
+}
+
+static inline void usb_host_release(struct usb_host *host)
+{
+	if (host->sem > 0)
+		host->sem--;
+}
+
 int usb_register_host(struct usb_host *host)
 {
 	list_add_tail(&host->list, &host_list);
 	host->busnum = host_busnum++;
+	host->sem = 0;
 	asynch_allowed = 1;
 	return 0;
 }
@@ -563,8 +578,17 @@ int usb_submit_int_msg(struct usb_device *dev, unsigned long pipe,
 			void *buffer, int transfer_len, int interval)
 {
 	struct usb_host *host = dev->host;
+	int ret;
+
+	ret = usb_host_acquire(host);
+	if (ret)
+		return ret;
+
+	ret = host->submit_int_msg(dev, pipe, buffer, transfer_len, interval);
 
-	return host->submit_int_msg(dev, pipe, buffer, transfer_len, interval);
+	usb_host_release(host);
+
+	return ret;
 }
 
 /*
@@ -590,6 +614,10 @@ int usb_control_msg(struct usb_device *dev, unsigned int pipe,
 		return -1;
 	}
 
+	ret = usb_host_acquire(host);
+	if (ret)
+		return ret;
+
 	/* set setup command */
 	setup_packet->requesttype = requesttype;
 	setup_packet->request = request;
@@ -603,6 +631,9 @@ int usb_control_msg(struct usb_device *dev, unsigned int pipe,
 
 	ret = host->submit_control_msg(dev, pipe, data, size, setup_packet,
 			timeout);
+
+	usb_host_release(host);
+
 	if (ret)
 		return ret;
 
@@ -623,8 +654,15 @@ int usb_bulk_msg(struct usb_device *dev, unsigned int pipe,
 	if (len < 0)
 		return -1;
 
+	ret = usb_host_acquire(host);
+	if (ret)
+		return ret;
+
 	dev->status = USB_ST_NOT_PROC; /* not yet processed */
 	ret = host->submit_bulk_msg(dev, pipe, data, len, timeout);
+
+	usb_host_release(host);
+
 	if (ret)
 		return ret;
 
diff --git a/include/usb/usb.h b/include/usb/usb.h
index 8f3ce2a..aedc527 100644
--- a/include/usb/usb.h
+++ b/include/usb/usb.h
@@ -152,6 +152,7 @@ struct usb_host {
 	struct device_d *hw_dev;
 	int busnum;
 	struct usb_device *root_dev;
+	int sem;
 };
 
 int usb_register_host(struct usb_host *);
-- 
2.1.4


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

  parent reply	other threads:[~2015-10-14 10:14 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-10-14 10:15 [PATCH 0/2] " Peter Mamonov
2015-10-14 10:15 ` [PATCH 1/2] input: usb_kbd: skip poll on -EAGAIN error Peter Mamonov
2015-10-14 10:15 ` Peter Mamonov [this message]
2015-10-14 14:09 ` [PATCH 0/2] usb: core: return -EAGAIN on usb_* functions reentrance Sascha Hauer
2015-10-15 12:38   ` Peter Mamonov

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=1444817749-20766-3-git-send-email-pmamonov@gmail.com \
    --to=pmamonov@gmail.com \
    --cc=barebox@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