linux-iio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Lars-Peter Clausen <lars@metafoo.de>
To: Jonathan Cameron <jic23@cam.ac.uk>
Cc: Michael Hennerich <michael.hennerich@analog.com>,
	<linux-iio@vger.kernel.org>,
	<device-drivers-devel@blackfin.uclinux.org>, <drivers@analog.com>,
	Lars-Peter Clausen <lars@metafoo.de>
Subject: [PATCH 4/8] staging:iio: Make sure a device is only opened once at a time
Date: Fri, 16 Dec 2011 11:19:47 +0100	[thread overview]
Message-ID: <1324030791-17983-4-git-send-email-lars@metafoo.de> (raw)
In-Reply-To: <1324030791-17983-1-git-send-email-lars@metafoo.de>

Our buffer implementation does not support multiple concurrent readers. So we
have to ensure that a device is only opened once at a time. So do the same thing
we do for the event fd and introduce a per device busy flag. The flag gets set
when opening the device and gets cleared when closing the device. If a open is
attempted while the busy flag is set we return -EBUSY.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
---
 drivers/staging/iio/iio.h               |    3 +++
 drivers/staging/iio/industrialio-core.c |   17 ++++++++++++++---
 2 files changed, 17 insertions(+), 3 deletions(-)

diff --git a/drivers/staging/iio/iio.h b/drivers/staging/iio/iio.h
index 6b57a79..3be99fd 100644
--- a/drivers/staging/iio/iio.h
+++ b/drivers/staging/iio/iio.h
@@ -318,6 +318,7 @@ struct iio_buffer_setup_ops {
  * @chrdev:		[INTERN] associated character device
  * @groups:		[INTERN] attribute groups
  * @groupcounter:	[INTERN] index of next attribute group
+ * @flags:		[INTERN] file ops related flags including busy flag.
  **/
 struct iio_dev {
 	int				id;
@@ -349,6 +350,8 @@ struct iio_dev {
 #define IIO_MAX_GROUPS 6
 	const struct attribute_group	*groups[IIO_MAX_GROUPS + 1];
 	int				groupcounter;
+
+	unsigned long			flags;
 };
 
 /**
diff --git a/drivers/staging/iio/industrialio-core.c b/drivers/staging/iio/industrialio-core.c
index 2eef85f..12d1576 100644
--- a/drivers/staging/iio/industrialio-core.c
+++ b/drivers/staging/iio/industrialio-core.c
@@ -1083,9 +1083,18 @@ static int iio_chrdev_open(struct inode *inode, struct file *filp)
 {
 	struct iio_dev *indio_dev = container_of(inode->i_cdev,
 						struct iio_dev, chrdev);
+	unsigned int ret;
+
+	if (test_and_set_bit(IIO_BUSY_BIT_POS, &indio_dev->flags))
+		return -EBUSY;
+
 	filp->private_data = indio_dev;
 
-	return iio_chrdev_buffer_open(indio_dev);
+	ret = iio_chrdev_buffer_open(indio_dev);
+	if (ret < 0)
+		clear_bit(IIO_BUSY_BIT_POS, &indio_dev->flags);
+
+	return ret;
 }
 
 /**
@@ -1093,8 +1102,10 @@ static int iio_chrdev_open(struct inode *inode, struct file *filp)
  **/
 static int iio_chrdev_release(struct inode *inode, struct file *filp)
 {
-	iio_chrdev_buffer_release(container_of(inode->i_cdev,
-					     struct iio_dev, chrdev));
+	struct iio_dev *indio_dev = container_of(inode->i_cdev,
+						struct iio_dev, chrdev);
+	iio_chrdev_buffer_release(indio_dev);
+	clear_bit(IIO_BUSY_BIT_POS, &indio_dev->flags);
 	return 0;
 }
 
-- 
1.7.7.3

  parent reply	other threads:[~2011-12-16 10:19 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-12-16 10:19 [PATCH 1/8] staging:iio: Use iio_buffer_enabled instead of open coding it Lars-Peter Clausen
2011-12-16 10:19 ` [PATCH 2/8] staging:iio: Disallow changing scan elements in all buffered modes Lars-Peter Clausen
2011-12-16 10:19 ` [PATCH 3/8] staging:iio: Disallow modifying buffer size when buffer is enabled Lars-Peter Clausen
2011-12-16 10:19 ` Lars-Peter Clausen [this message]
2011-12-16 10:19 ` [PATCH 5/8] staging:iio: Drop buffer busy flag Lars-Peter Clausen
2011-12-16 10:19 ` [PATCH 6/8] staging:iio: Drop buffer mark_param_change callback Lars-Peter Clausen
2011-12-16 10:19 ` [PATCH 7/8] staging:iio: Drop the unused buffer enable() and is_enabled() callbacks Lars-Peter Clausen
2011-12-16 10:19 ` [PATCH 8/8] iio:staging: Drop {mark,unmark}_in_use callbacks Lars-Peter Clausen
2011-12-16 19:43 ` [PATCH 1/8] staging:iio: Use iio_buffer_enabled instead of open coding it Jonathan Cameron
  -- strict thread matches above, loose matches on Subject: below --
2011-12-19 14:23 Lars-Peter Clausen
2011-12-19 14:23 ` [PATCH 4/8] staging:iio: Make sure a device is only opened once at a time Lars-Peter Clausen

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=1324030791-17983-4-git-send-email-lars@metafoo.de \
    --to=lars@metafoo.de \
    --cc=device-drivers-devel@blackfin.uclinux.org \
    --cc=drivers@analog.com \
    --cc=jic23@cam.ac.uk \
    --cc=linux-iio@vger.kernel.org \
    --cc=michael.hennerich@analog.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).