linux-iio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Lars-Peter Clausen <lars@metafoo.de>
To: Jonathan Cameron <jic23@kernel.org>
Cc: linux-iio@vger.kernel.org, Lars-Peter Clausen <lars@metafoo.de>
Subject: [PATCH 01/10] iio: Stop sampling when the device is removed
Date: Wed, 18 Sep 2013 22:02:45 +0200	[thread overview]
Message-ID: <1379534574-11213-1-git-send-email-lars@metafoo.de> (raw)

Make sure to stop sampling when the device is removed, otherwise it will
continue to sample forever.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
---
 drivers/iio/iio_core.h            |  4 ++++
 drivers/iio/industrialio-buffer.c | 19 +++++++++++++++++++
 drivers/iio/industrialio-core.c   |  6 +++++-
 3 files changed, 28 insertions(+), 1 deletion(-)

diff --git a/drivers/iio/iio_core.h b/drivers/iio/iio_core.h
index 6be5ab8..9209f47 100644
--- a/drivers/iio/iio_core.h
+++ b/drivers/iio/iio_core.h
@@ -49,11 +49,15 @@ ssize_t iio_buffer_read_first_n_outer(struct file *filp, char __user *buf,
 #define iio_buffer_poll_addr (&iio_buffer_poll)
 #define iio_buffer_read_first_n_outer_addr (&iio_buffer_read_first_n_outer)
 
+void iio_disable_all_buffers(struct iio_dev *indio_dev);
+
 #else
 
 #define iio_buffer_poll_addr NULL
 #define iio_buffer_read_first_n_outer_addr NULL
 
+static inline void iio_disable_all_buffers(struct iio_dev *indio_dev) {}
+
 #endif
 
 int iio_device_register_eventset(struct iio_dev *indio_dev);
diff --git a/drivers/iio/industrialio-buffer.c b/drivers/iio/industrialio-buffer.c
index a7ac4b5..379721a 100644
--- a/drivers/iio/industrialio-buffer.c
+++ b/drivers/iio/industrialio-buffer.c
@@ -452,6 +452,25 @@ static int iio_compute_scan_bytes(struct iio_dev *indio_dev, const long *mask,
 	return bytes;
 }
 
+void iio_disable_all_buffers(struct iio_dev *indio_dev)
+{
+	struct iio_buffer *buffer, *_buffer;
+
+	if (list_empty(&indio_dev->buffer_list))
+		return;
+
+	if (indio_dev->setup_ops->predisable)
+		indio_dev->setup_ops->predisable(indio_dev);
+
+	list_for_each_entry_safe(buffer, _buffer,
+			&indio_dev->buffer_list, buffer_list)
+		list_del_init(&buffer->buffer_list);
+
+	indio_dev->currentmode = INDIO_DIRECT_MODE;
+	if (indio_dev->setup_ops->postdisable)
+		indio_dev->setup_ops->postdisable(indio_dev);
+}
+
 int iio_update_buffers(struct iio_dev *indio_dev,
 		       struct iio_buffer *insert_buffer,
 		       struct iio_buffer *remove_buffer)
diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-core.c
index 24db185..96b35f0 100644
--- a/drivers/iio/industrialio-core.c
+++ b/drivers/iio/industrialio-core.c
@@ -1120,9 +1120,13 @@ EXPORT_SYMBOL(iio_device_register);
 void iio_device_unregister(struct iio_dev *indio_dev)
 {
 	mutex_lock(&indio_dev->info_exist_lock);
+
+	device_del(&indio_dev->dev);
+
+	iio_disable_all_buffers(indio_dev);
+
 	indio_dev->info = NULL;
 	mutex_unlock(&indio_dev->info_exist_lock);
-	device_del(&indio_dev->dev);
 }
 EXPORT_SYMBOL(iio_device_unregister);
 subsys_initcall(iio_init);
-- 
1.8.0

             reply	other threads:[~2013-09-18 20:02 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-09-18 20:02 Lars-Peter Clausen [this message]
2013-09-18 20:02 ` [PATCH 02/10] iio: Keep a reference to the IIO device for open file descriptors Lars-Peter Clausen
2013-09-21 11:44   ` Jonathan Cameron
2013-09-21 11:48   ` Jonathan Cameron
2013-09-18 20:02 ` [PATCH 03/10] iio: Set the IIO device as the parent for the character device Lars-Peter Clausen
2013-09-21 11:52   ` Jonathan Cameron
2013-09-18 20:02 ` [PATCH 04/10] iio:buffer_cb: Add missing iio_buffer_init() Lars-Peter Clausen
2013-09-21 11:53   ` Jonathan Cameron
2013-09-18 20:02 ` [PATCH 05/10] iio: Add reference counting for buffers Lars-Peter Clausen
2013-09-18 20:02 ` [PATCH 06/10] iio: Remove debugfs entries in iio_device_unregister() Lars-Peter Clausen
2013-09-18 20:02 ` [PATCH 07/10] iio: Return -ENODEV for file operations if the device has been unregistered Lars-Peter Clausen
2013-09-18 20:02 ` [PATCH 08/10] iio: Wakeup poll and blocking reads when the device is unregistered Lars-Peter Clausen
2013-09-21 11:56   ` Jonathan Cameron
2013-09-21 11:43     ` Lars-Peter Clausen
2013-09-21 12:45       ` Jonathan Cameron
2013-09-21 15:16         ` Lars-Peter Clausen
2013-09-21 18:18           ` Jonathan Cameron
2013-09-18 20:02 ` [PATCH 09/10] iio:buffer: Add proper locking for iio_update_buffers() Lars-Peter Clausen
2013-09-18 20:27   ` Lars-Peter Clausen
2013-09-21 11:59     ` Jonathan Cameron
2013-09-21 11:05       ` Lars-Peter Clausen
2013-09-21 12:09         ` Jonathan Cameron
2013-09-18 20:02 ` [PATCH 10/10] iio:buffer: Ignore noop requests " Lars-Peter Clausen
2013-09-21 11:57   ` Jonathan Cameron
2013-09-18 22:00 ` [PATCH 01/10] iio: Stop sampling when the device is removed Jonathan Cameron
2013-09-18 21:08   ` Lars-Peter Clausen
2013-09-18 22:11     ` Jonathan Cameron
2013-09-21 11:36 ` Jonathan Cameron
2013-09-21 10:45   ` 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=1379534574-11213-1-git-send-email-lars@metafoo.de \
    --to=lars@metafoo.de \
    --cc=jic23@kernel.org \
    --cc=linux-iio@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;
as well as URLs for NNTP newsgroup(s).