From: stefani@seibold.net
To: linux-kernel@vger.kernel.org, gregkh@linuxfoundation.org,
oneukum@suse.de
Cc: linux-usb@vger.kernel.org, Stefani Seibold <stefani@seibold.net>
Subject: [PATCH 12/13] Introduce single user mode
Date: Thu, 7 Jun 2012 10:20:42 +0200 [thread overview]
Message-ID: <1339057243-10029-13-git-send-email-stefani@seibold.net> (raw)
In-Reply-To: <1339057243-10029-1-git-send-email-stefani@seibold.net>
From: Stefani Seibold <stefani@seibold.net>
Most USB devices can only used in a single usage mode. This patch prevents a
reopening on an already opened device.
Signed-off-by: Stefani Seibold <stefani@seibold.net>
---
drivers/usb/usb-skeleton.c | 16 +++++++++++++++-
1 files changed, 15 insertions(+), 1 deletions(-)
diff --git a/drivers/usb/usb-skeleton.c b/drivers/usb/usb-skeleton.c
index 551fb51..456c9a8 100644
--- a/drivers/usb/usb-skeleton.c
+++ b/drivers/usb/usb-skeleton.c
@@ -59,6 +59,7 @@ struct usb_skel {
__u8 bulk_out_endpointAddr; /* the address of the bulk out endpoint */
int errors; /* the last request tanked */
bool ongoing_read; /* a read is going on */
+ bool in_use; /* in use flag */
spinlock_t err_lock; /* lock for errors */
struct kref kref;
struct mutex io_mutex; /* synchronize I/O with disconnect */
@@ -92,17 +93,28 @@ static int skel_open(struct inode *inode, struct file *file)
if (!dev)
return -ENODEV;
+ mutex_lock(&dev->io_mutex);
+ if (dev->in_use) {
+ mutex_unlock(&dev->io_mutex);
+ return -EBUSY;
+ }
+
/*
* must be not locked since a disconnect waits in usb_deregister_dev()
* due the already locked minor_rwsem in the usb_open() function
*/
retval = usb_autopm_get_interface(interface);
- if (!retval)
+ if (!retval) {
+ mutex_unlock(&dev->io_mutex);
return retval;
+ }
/* increment our usage count for the device */
kref_get(&dev->kref);
+ dev->in_use = true;
+ mutex_unlock(&dev->io_mutex);
+
/* save our object in the file's private structure */
file->private_data = dev;
@@ -117,6 +129,7 @@ static int skel_release(struct inode *inode, struct file *file)
mutex_lock(&dev->io_mutex);
if (dev->interface)
usb_autopm_put_interface(dev->interface);
+ dev->in_use = false;
mutex_unlock(&dev->io_mutex);
/* decrement the count on our device */
@@ -517,6 +530,7 @@ static int skel_probe(struct usb_interface *interface,
dev->udev = usb_get_dev(interface_to_usbdev(interface));
dev->interface = interface;
+ dev->in_use = false;
/* set up the endpoint information */
/* use only the first bulk-in and bulk-out endpoints */
--
1.7.8.6
next prev parent reply other threads:[~2012-06-07 8:31 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-06-07 8:20 [PATCH] fix usb skeleton driver stefani
2012-06-07 8:20 ` [PATCH 01/13] fix wrong label in skel_open stefani
2012-06-13 1:03 ` Greg KH
2012-06-07 8:20 ` [PATCH 02/13] code cleanup stefani
2012-06-07 9:06 ` Bjørn Mork
2012-06-07 9:21 ` Stefani Seibold
2012-06-07 10:49 ` Bjørn Mork
2012-06-13 1:03 ` Greg KH
2012-06-13 1:02 ` Greg KH
2012-06-13 18:00 ` Stefani Seibold
2012-06-07 8:20 ` [PATCH 03/13] remove dead code stefani
2012-06-07 15:04 ` Oliver Neukum
2012-06-07 19:40 ` Stefani Seibold
2012-06-07 8:20 ` [PATCH 04/13] remove unneeded forward declaration stefani
2012-06-07 8:20 ` [PATCH 05/13] remove pr_err() noise in skel_open stefani
2012-06-07 8:20 ` [PATCH 06/13] Handle a non blocking read without blocking stefani
2012-06-07 8:20 ` [PATCH 07/13] fix flush function stefani
2012-06-07 8:20 ` [PATCH 08/13] add fsync function stefani
2012-06-07 8:20 ` [PATCH 09/13] remove unneeded lock in skel_open stefani
2012-06-07 8:20 ` [PATCH 10/13] fix race in skel_write stefani
2012-06-07 8:20 ` [PATCH 11/13] fix kref usage in skel_open stefani
2012-06-07 8:20 ` stefani [this message]
2012-06-13 1:05 ` [PATCH 12/13] Introduce single user mode Greg KH
2012-06-07 8:20 ` [PATCH 13/13] Bump version number and add aditional author stefani
2012-06-07 9:09 ` Bjørn Mork
2012-06-13 1:00 ` Greg KH
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=1339057243-10029-13-git-send-email-stefani@seibold.net \
--to=stefani@seibold.net \
--cc=gregkh@linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
--cc=oneukum@suse.de \
/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®