From: Jonathan Cameron <jic23@kernel.org>
To: Lars-Peter Clausen <lars@metafoo.de>
Cc: linux-iio@vger.kernel.org
Subject: Re: [PATCH v2 4/5] iio:buffer: Add proper locking for iio_update_buffers()
Date: Sat, 12 Oct 2013 12:07:31 +0100 [thread overview]
Message-ID: <52592D73.4080409@kernel.org> (raw)
In-Reply-To: <1380884822-17035-4-git-send-email-lars@metafoo.de>
On 10/04/13 12:07, Lars-Peter Clausen wrote:
> We need to make sure that in-kernel users of iio_update_buffers() do not race
> against each other or against unregistration of the device. So we need to take
> both the mlock and the info_exist_lock when calling iio_update_buffers() from a
> in-kernel consumer.
>
> Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
Applied to the togreg branch of iio.git
Thanks,
Jonathan
> ---
> No changes since v1
> ---
> drivers/iio/industrialio-buffer.c | 29 ++++++++++++++++++++++++++---
> 1 file changed, 26 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/iio/industrialio-buffer.c b/drivers/iio/industrialio-buffer.c
> index 5a46c57..d6a5455 100644
> --- a/drivers/iio/industrialio-buffer.c
> +++ b/drivers/iio/industrialio-buffer.c
> @@ -509,7 +509,7 @@ void iio_disable_all_buffers(struct iio_dev *indio_dev)
> indio_dev->setup_ops->postdisable(indio_dev);
> }
>
> -int iio_update_buffers(struct iio_dev *indio_dev,
> +static int __iio_update_buffers(struct iio_dev *indio_dev,
> struct iio_buffer *insert_buffer,
> struct iio_buffer *remove_buffer)
> {
> @@ -674,6 +674,29 @@ error_ret:
>
> return ret;
> }
> +
> +int iio_update_buffers(struct iio_dev *indio_dev,
> + struct iio_buffer *insert_buffer,
> + struct iio_buffer *remove_buffer)
> +{
> + int ret;
> +
> + mutex_lock(&indio_dev->info_exist_lock);
> + mutex_lock(&indio_dev->mlock);
> +
> + if (indio_dev->info == NULL) {
> + ret = -ENODEV;
> + goto out_unlock;
> + }
> +
> + ret = __iio_update_buffers(indio_dev, insert_buffer, remove_buffer);
> +
> +out_unlock:
> + mutex_unlock(&indio_dev->mlock);
> + mutex_unlock(&indio_dev->info_exist_lock);
> +
> + return ret;
> +}
> EXPORT_SYMBOL_GPL(iio_update_buffers);
>
> ssize_t iio_buffer_store_enable(struct device *dev,
> @@ -699,10 +722,10 @@ ssize_t iio_buffer_store_enable(struct device *dev,
> goto done;
>
> if (requested_state)
> - ret = iio_update_buffers(indio_dev,
> + ret = __iio_update_buffers(indio_dev,
> indio_dev->buffer, NULL);
> else
> - ret = iio_update_buffers(indio_dev,
> + ret = __iio_update_buffers(indio_dev,
> NULL, indio_dev->buffer);
>
> if (ret < 0)
>
next prev parent reply other threads:[~2013-10-12 10:07 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-10-04 11:06 [PATCH v2 1/5] iio: Add reference counting for buffers Lars-Peter Clausen
2013-10-04 11:06 ` [PATCH v2 2/5] iio: Return -ENODEV for file operations if the device has been unregistered Lars-Peter Clausen
2013-10-12 11:04 ` Jonathan Cameron
2013-10-04 11:07 ` [PATCH v2 3/5] iio: Wakeup poll and blocking reads when the device is unregistered Lars-Peter Clausen
2013-10-12 11:06 ` Jonathan Cameron
2013-10-04 11:07 ` [PATCH v2 4/5] iio:buffer: Add proper locking for iio_update_buffers() Lars-Peter Clausen
2013-10-12 11:07 ` Jonathan Cameron [this message]
2013-10-04 11:07 ` [PATCH v2 5/5] iio:buffer: Ignore noop requests " Lars-Peter Clausen
2013-10-12 11:10 ` Jonathan Cameron
2013-10-12 10:19 ` Lars-Peter Clausen
2013-10-12 12:06 ` Jonathan Cameron
2013-10-12 12:06 ` Jonathan Cameron
2013-10-12 11:00 ` [PATCH v2 1/5] iio: Add reference counting for buffers Jonathan Cameron
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=52592D73.4080409@kernel.org \
--to=jic23@kernel.org \
--cc=lars@metafoo.de \
--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).