Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1607287
| Path | csiph.com!news.redatomik.org!aioe.org!bofh.it!news.nic.it!robomod |
|---|---|
| From | simran singhal <singhalsimran0@gmail.com> |
| Newsgroups | linux.kernel |
| Subject | [PATCH v9] staging: iio: adis16060: Remove iio_dev mlock and refactor code |
| Date | Thu, 23 Mar 2017 10:30:01 +0100 |
| Message-ID | <to7e9-eW-7@gated-at.bofh.it> (permalink) |
| X-Original-To | lars@metafoo.de |
| Dkim-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:mime-version:content-disposition :user-agent; bh=qJp1Ya3FxDcTfPYo7A3knJWm7Z8Hyu47IXU36JMIi8I=; b=AdpwZIq/KHOpTEKsn8RcLD8h5vIcXPfkZlDFpLnd2IYPDqsyOic9oMz+U0vipFl/uP /qQdXwbPhy30CR3PPJPjjS9DtZv0T17pqYhBNDOglFjegr2S/wfPkEVeG4lr2c4eZHxM L+/trVk/d9mW4NUx3OXpYmrGzn8kk2mM/0FhYhz7NKk24pxlfiSjKzZFCRMwGU5TAC5s V3FrBg3gfNC+3A0ord2Cslq/0+zUKTjNIDS6pGcwGV/NE9VE0sncqPJSTuVqIBpsg6Qb YgqLSmo7MsfW636qakGv091bujhxGteCCkYcBguB3VF2BRwtTGtCGIDolr/E2U+HxeAJ S7ng== |
| X-Google-Dkim-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:mime-version :content-disposition:user-agent; bh=qJp1Ya3FxDcTfPYo7A3knJWm7Z8Hyu47IXU36JMIi8I=; b=f8ae5XYXQ78ipHqvoA9z9xpXFry23nxJeUcFhMZQVEeZ7rDx6ud/kdZ3yoBloFg+rX i4MKrc+vhqTt8gAiJZ/IAPHQu521zgvmAvZa01SH6h28XZQZH3Yma+2bROsTlSeVWMRY 5uTR2CtLWTNHENg4CNwyM6fZtLX0dZrdII8j14R44UEy1xS7/tXTx3lH+8aRt9snXMK0 goyXyLJODJfDQcqnANoF5XlN9RZq5hLB/czPdRivCkbQ06W9cXHr+tMOpX+AZBzzewWz CcbGxH5GzSP0BRg+rMF+2H2O4lqKJYLJA7UnfCL4uy9azMvJThRHZGuMOQUIBia4p4ks YzBg== |
| X-Gm-Message-State | AFeK/H3olt7gyOIbutx4VXl9OP5+QrLcHE0td0ke0rLMyTFItv0SUhJQ1B1VKEvHLt651g== |
| X-Received | by 10.98.223.76 with SMTP id u73mr1788320pfg.147.1490260850927; Thu, 23 Mar 2017 02:20:50 -0700 (PDT) |
| MIME-Version | 1.0 |
| Content-Type | text/plain; charset=us-ascii |
| Content-Disposition | inline |
| User-Agent | Mutt/1.5.24 (2015-08-30) |
| Sender | robomod@news.nic.it |
| List-ID | <linux-kernel.vger.kernel.org> |
| X-Mailing-List | linux-kernel@vger.kernel.org |
| Approved | robomod@news.nic.it |
| Lines | 95 |
| Organization | linux.* mail to news gateway |
| X-Original-Cc | Michael.Hennerich@analog.com, jic23@kernel.org, Hartmut Knaack <knaack.h@gmx.de>, Peter Meerwald-Stadler <pmeerw@pmeerw.net>, Greg Kroah-Hartman <gregkh@linuxfoundation.org>, linux-iio@vger.kernel.org, devel@driverdev.osuosl.org, linux-kernel@vger.kernel.org, outreachy-kernel@googlegroups.com |
| X-Original-Date | Thu, 23 Mar 2017 14:50:48 +0530 |
| X-Original-Message-ID | <20170323092048.GA25470@singhal-Inspiron-5558> |
| X-Original-Sender | linux-kernel-owner@vger.kernel.org |
| Xref | csiph.com linux.kernel:1607287 |
Show key headers only | View raw
The IIO subsystem is redefining iio_dev->mlock to be used by
the IIO core only for protecting device operating mode changes.
ie. Changes between INDIO_DIRECT_MODE, INDIO_BUFFER_* modes.
In this driver, mlock was being used to protect hardware state changes.
In the driver, buf_lock protects both the adis16060_spi_write() and
adis16060_spi_read() functions and both are always called in pair.
First write, then read. Refactor the code to have one single function
adis16060_spi_write_then_read() protected by the buf_lock. This removes
the need for additional locking via mlock, so this locking is removed.
Signed-off-by: simran singhal <singhalsimran0@gmail.com>
---
v9:
-Change the name of function from adis16060_spi_write_than_read()
to adis16060_spi_write_then_read(). change "than" to "then" as
its time depended.
-Add mutex_unlock
drivers/staging/iio/gyro/adis16060_core.c | 35 +++++++++----------------------
1 file changed, 10 insertions(+), 25 deletions(-)
diff --git a/drivers/staging/iio/gyro/adis16060_core.c b/drivers/staging/iio/gyro/adis16060_core.c
index c9d46e7..9675245 100644
--- a/drivers/staging/iio/gyro/adis16060_core.c
+++ b/drivers/staging/iio/gyro/adis16060_core.c
@@ -40,25 +40,20 @@ struct adis16060_state {
static struct iio_dev *adis16060_iio_dev;
-static int adis16060_spi_write(struct iio_dev *indio_dev, u8 val)
+static int adis16060_spi_write_then_read(struct iio_dev *indio_dev,
+ u8 conf, u16 *val)
{
int ret;
struct adis16060_state *st = iio_priv(indio_dev);
mutex_lock(&st->buf_lock);
- st->buf[2] = val; /* The last 8 bits clocked in are latched */
+ st->buf[2] = conf; /* The last 8 bits clocked in are latched */
ret = spi_write(st->us_w, st->buf, 3);
- mutex_unlock(&st->buf_lock);
-
- return ret;
-}
-
-static int adis16060_spi_read(struct iio_dev *indio_dev, u16 *val)
-{
- int ret;
- struct adis16060_state *st = iio_priv(indio_dev);
- mutex_lock(&st->buf_lock);
+ if (ret < 0) {
+ mutex_unlock(&st->buf_lock);
+ return ret;
+ }
ret = spi_read(st->us_r, st->buf, 3);
@@ -86,17 +81,11 @@ static int adis16060_read_raw(struct iio_dev *indio_dev,
switch (mask) {
case IIO_CHAN_INFO_RAW:
- /* Take the iio_dev status lock */
- mutex_lock(&indio_dev->mlock);
- ret = adis16060_spi_write(indio_dev, chan->address);
+ ret = adis16060_spi_write_then_read(indio_dev,
+ chan->address, &tval);
if (ret < 0)
- goto out_unlock;
+ return ret;
- ret = adis16060_spi_read(indio_dev, &tval);
- if (ret < 0)
- goto out_unlock;
-
- mutex_unlock(&indio_dev->mlock);
*val = tval;
return IIO_VAL_INT;
case IIO_CHAN_INFO_OFFSET:
@@ -110,10 +99,6 @@ static int adis16060_read_raw(struct iio_dev *indio_dev,
}
return -EINVAL;
-
-out_unlock:
- mutex_unlock(&indio_dev->mlock);
- return ret;
}
static const struct iio_info adis16060_info = {
--
2.7.4
Back to linux.kernel | Previous | Next — Next in thread | Find similar | Unroll thread
[PATCH v9] staging: iio: adis16060: Remove iio_dev mlock and refactor code simran singhal <singhalsimran0@gmail.com> - 2017-03-23 10:30 +0100
Re: [PATCH v9] staging: iio: adis16060: Remove iio_dev mlock and refactor code Jonathan Cameron <jic23@kernel.org> - 2017-03-25 18:50 +0100
Re: [PATCH v9] staging: iio: adis16060: Remove iio_dev mlock and refactor code SIMRAN SINGHAL <singhalsimran0@gmail.com> - 2017-03-25 19:30 +0100
csiph-web