From: Jonathan Cameron <jic23@kernel.org>
To: Alison Schofield <amsfield22@gmail.com>,
outreachy-kernel@googlegroups.com
Cc: knaack.h@gmx.de, lars@metafoo.de, pmeerw@pmeerw.net,
linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org,
Michael.Hennerich@analog.com, gregkh@linuxfoundation.org,
devel@driverdev.osuosl.org
Subject: Re: [RFC PATCH v2 1/2] iio: core: implement iio_device_{claim|release}_direct_mode()
Date: Sat, 12 Mar 2016 11:18:22 +0000 [thread overview]
Message-ID: <56E3FAFE.2040108@kernel.org> (raw)
In-Reply-To: <a9ed1d7bec5e0692bfd6b0e897d408fc265d4be8.1457549841.git.amsfield22@gmail.com>
On 09/03/16 19:30, Alison Schofield wrote:
> It is often the case that the driver wants to be sure a device stays
> in direct mode while it is executing a task or series of tasks. To
> accomplish this today, the driver performs this sequence: 1) take the
> device state lock, 2) verify it is not in a buffered mode, 3) execute
> some tasks, and 4) release that lock.
>
> This patch introduces a pair of helper functions that simplify these
> steps and make it more semantically expressive.
>
> iio_device_claim_direct_mode()
> If the device is not in any buffered mode it is guaranteed
> to stay that way until iio_release_direct_mode() is called.
>
> iio_device_release_direct_mode()
> Release the claim. Device is no longer guaranteed to stay
> in direct mode.
>
> Signed-off-by: Alison Schofield <amsfield22@gmail.com>
I like change. Nice and clean and should help reduce 'misuse' of this
lock by making it more focused in the long run.
Applied to the togreg branch of iio.git - initially pushed out as testing
for the autobuilders to play with it.
> ---
> drivers/iio/industrialio-core.c | 39 +++++++++++++++++++++++++++++++++++++++
> include/linux/iio/iio.h | 2 ++
> 2 files changed, 41 insertions(+)
>
> diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-core.c
> index 70cb7eb..2e768bc 100644
> --- a/drivers/iio/industrialio-core.c
> +++ b/drivers/iio/industrialio-core.c
> @@ -25,6 +25,7 @@
> #include <linux/slab.h>
> #include <linux/anon_inodes.h>
> #include <linux/debugfs.h>
> +#include <linux/mutex.h>
> #include <linux/iio/iio.h>
> #include "iio_core.h"
> #include "iio_core_trigger.h"
> @@ -1375,6 +1376,44 @@ void devm_iio_device_unregister(struct device *dev, struct iio_dev *indio_dev)
> }
> EXPORT_SYMBOL_GPL(devm_iio_device_unregister);
>
> +/**
> + * iio_device_claim_direct_mode - Keep device in direct mode
> + * @indio_dev: the iio_dev associated with the device
> + *
> + * If the device is in direct mode it is guaranteed to stay
> + * that way until iio_device_release_direct_mode() is called.
> + *
> + * Use with iio_device_release_direct_mode()
> + *
> + * Returns: 0 on success, -EBUSY on failure
> + */
> +int iio_device_claim_direct_mode(struct iio_dev *indio_dev)
> +{
> + mutex_lock(&indio_dev->mlock);
> +
> + if (iio_buffer_enabled(indio_dev)) {
> + mutex_unlock(&indio_dev->mlock);
> + return -EBUSY;
> + }
> + return 0;
> +}
> +EXPORT_SYMBOL_GPL(iio_device_claim_direct_mode);
> +
> +/**
> + * iio_device_release_direct_mode - releases claim on direct mode
> + * @indio_dev: the iio_dev associated with the device
> + *
> + * Release the claim. Device is no longer guaranteed to stay
> + * in direct mode.
> + *
> + * Use with iio_device_claim_direct_mode()
> + */
> +void iio_device_release_direct_mode(struct iio_dev *indio_dev)
> +{
> + mutex_unlock(&indio_dev->mlock);
> +}
> +EXPORT_SYMBOL_GPL(iio_device_release_direct_mode);
> +
> subsys_initcall(iio_init);
> module_exit(iio_exit);
>
> diff --git a/include/linux/iio/iio.h b/include/linux/iio/iio.h
> index b2b1677..0b2773a 100644
> --- a/include/linux/iio/iio.h
> +++ b/include/linux/iio/iio.h
> @@ -527,6 +527,8 @@ void iio_device_unregister(struct iio_dev *indio_dev);
> int devm_iio_device_register(struct device *dev, struct iio_dev *indio_dev);
> void devm_iio_device_unregister(struct device *dev, struct iio_dev *indio_dev);
> int iio_push_event(struct iio_dev *indio_dev, u64 ev_code, s64 timestamp);
> +int iio_device_claim_direct_mode(struct iio_dev *indio_dev);
> +void iio_device_release_direct_mode(struct iio_dev *indio_dev);
>
> extern struct bus_type iio_bus_type;
>
>
next prev parent reply other threads:[~2016-03-12 11:18 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-03-01 18:58 [RFC PATCH 0/2] iio: introduce iio_{claim|release}_direct_mode() Alison Schofield
2016-03-01 19:02 ` [RFC PATCH 1/2] iio: core: implement iio_{claim|release}_direct_mode() Alison Schofield
2016-03-02 13:28 ` Lars-Peter Clausen
2016-03-05 18:02 ` Jonathan Cameron
2016-03-09 20:06 ` Alison Schofield
2016-03-09 20:23 ` Jonathan Cameron
2016-03-01 19:03 ` [RFC PATCH 2/2] staging: iio: adc7192: use iio_{claim|release}_direct_mode() Alison Schofield
2016-03-09 19:25 ` [RFC PATCH v2 0/2] iio: introduce iio_device_{claim|release}_direct_mode() Alison Schofield
2016-03-09 19:30 ` [RFC PATCH v2 1/2] iio: core: implement iio_device_{claim|release}_direct_mode() Alison Schofield
2016-03-12 11:18 ` Jonathan Cameron [this message]
2016-03-09 19:30 ` [RFC PATCH v2 2/2] staging: iio: ad7192: use iio_device_{claim|release}_direct_mode() Alison Schofield
2016-03-12 11:21 ` Jonathan Cameron
2016-03-12 11:25 ` Jonathan Cameron
2016-03-12 11:16 ` [RFC PATCH v2 0/2] iio: introduce iio_device_{claim|release}_direct_mode() 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=56E3FAFE.2040108@kernel.org \
--to=jic23@kernel.org \
--cc=Michael.Hennerich@analog.com \
--cc=amsfield22@gmail.com \
--cc=devel@driverdev.osuosl.org \
--cc=gregkh@linuxfoundation.org \
--cc=knaack.h@gmx.de \
--cc=lars@metafoo.de \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=outreachy-kernel@googlegroups.com \
--cc=pmeerw@pmeerw.net \
/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).