linux-iio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jonathan Cameron <jic23@kernel.org>
To: linux-iio@vger.kernel.org
Cc: knaack.h@gmx.de, lars@metafoo.de, pmeerw@pmeerw.net,
	Jonathan Cameron <jic23@kernel.org>
Subject: [PATCH 11/18] staging:iio:accel:sca3000: Fix off by one error in axis due to IIO_NO_MOD
Date: Mon,  3 Oct 2016 20:26:55 +0100	[thread overview]
Message-ID: <20161003192702.24361-12-jic23@kernel.org> (raw)
In-Reply-To: <20161003192702.24361-1-jic23@kernel.org>

Given the introduction of IIO_NO_MOD was prior to the first submission
prior to IIO entering staging this has been broken for a while.

Signed-off-by: Jonathan Cameron <jic23@kernel.org>
---
 drivers/staging/iio/accel/sca3000.c | 21 +++++++++++----------
 1 file changed, 11 insertions(+), 10 deletions(-)

diff --git a/drivers/staging/iio/accel/sca3000.c b/drivers/staging/iio/accel/sca3000.c
index 24685a2f224e..e8f43df65142 100644
--- a/drivers/staging/iio/accel/sca3000.c
+++ b/drivers/staging/iio/accel/sca3000.c
@@ -933,16 +933,17 @@ static int sca3000_read_event_value(struct iio_dev *indio_dev,
 {
 	int ret, i;
 	struct sca3000_state *st = iio_priv(indio_dev);
-	int num = chan->channel2;
+
 	switch (info) {
 	case IIO_EV_INFO_VALUE:
 		mutex_lock(&st->lock);
-		ret = sca3000_read_ctrl_reg(st, sca3000_addresses[num][1]);
+		ret = sca3000_read_ctrl_reg(st,
+					    sca3000_addresses[chan->channel2 - IIO_MOD_X][1]);
 		mutex_unlock(&st->lock);
 		if (ret < 0)
 			return ret;
 		*val = 0;
-		if (num == 1)
+		if (chan->channel2 == IIO_MOD_Y)
 			for_each_set_bit(i, (unsigned long *)&ret,
 					 ARRAY_SIZE(st->info->mot_det_mult_y))
 				*val += st->info->mot_det_mult_y[i];
@@ -972,12 +973,11 @@ static int sca3000_write_event_value(struct iio_dev *indio_dev,
 				     int val, int val2)
 {
 	struct sca3000_state *st = iio_priv(indio_dev);
-	int num = chan->channel2;
 	int ret;
 	int i;
 	u8 nonlinear = 0;
 
-	if (num == IIO_MOD_Y) {
+	if (chan->channel2 == IIO_MOD_Y) {
 		i = ARRAY_SIZE(st->info->mot_det_mult_y);
 		while (i > 0)
 			if (val >= st->info->mot_det_mult_y[--i]) {
@@ -994,7 +994,9 @@ static int sca3000_write_event_value(struct iio_dev *indio_dev,
 	}
 
 	mutex_lock(&st->lock);
-	ret = sca3000_write_ctrl_reg(st, sca3000_addresses[num][1], nonlinear);
+	ret = sca3000_write_ctrl_reg(st,
+				     sca3000_addresses[chan->channel2 - IIO_MOD_X][1],
+				     nonlinear);
 	mutex_unlock(&st->lock);
 
 	return ret;
@@ -1160,8 +1162,6 @@ static int sca3000_read_event_config(struct iio_dev *indio_dev,
 {
 	struct sca3000_state *st = iio_priv(indio_dev);
 	int ret;
-	int num = chan->channel2;
-
 	/* read current value of mode register */
 	mutex_lock(&st->lock);
 
@@ -1189,7 +1189,7 @@ static int sca3000_read_event_config(struct iio_dev *indio_dev,
 			if (ret < 0)
 				goto error_ret;
 			/* only supporting logical or's for now */
-			ret = !!(ret & sca3000_addresses[num][2]);
+			ret = !!(ret & sca3000_addresses[chan->channel2 - IIO_MOD_X][2]);
 		}
 		break;
 	default:
@@ -1305,7 +1305,8 @@ static int sca3000_write_event_config(struct iio_dev *indio_dev,
 	case IIO_MOD_X:
 	case IIO_MOD_Y:
 	case IIO_MOD_Z:
-		ret = sca3000_motion_detect_set_state(indio_dev, chan->channel2,
+		ret = sca3000_motion_detect_set_state(indio_dev,
+						      chan->channel2 - IIO_MOD_X,
 						      state);
 		break;
 	default:
-- 
2.10.0


  parent reply	other threads:[~2016-10-03 19:27 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-10-03 19:26 [PATCH 00/18] staging:iio:accel rework driver and move out of staging Jonathan Cameron
2016-10-03 19:26 ` [PATCH 01/18] staging:iio:accel:sca3000 Fix a use before setting of the indio_dev->buffer pointer Jonathan Cameron
2016-10-03 19:26 ` [PATCH 02/18] staging:iio:accel:sca3000 merge files into one Jonathan Cameron
2016-10-04  8:46   ` Lars-Peter Clausen
2016-10-04 12:29     ` Jonathan Cameron
2016-10-03 19:26 ` [PATCH 03/18] staging:iio:accel:sca3000 drop sca3000_register_ring_funcs Jonathan Cameron
2016-10-03 19:26 ` [PATCH 04/18] staging:iio:accel:sca3000 Fix clearing of flag + setting of size of scan Jonathan Cameron
2016-10-04  8:59   ` Lars-Peter Clausen
2016-10-04 12:28     ` Jonathan Cameron
2016-10-03 19:26 ` [PATCH 05/18] staging:iio:accel:sca3000 Drop custom ABI for watersheds Jonathan Cameron
2016-10-03 19:26 ` [PATCH 06/18] staging:iio:accel:sca3000 move to hybrid hard / soft buffer design Jonathan Cameron
2016-10-03 19:26 ` [PATCH 07/18] staging:iio:accel:sca3000 drop some unused variables Jonathan Cameron
2016-10-03 19:26 ` [PATCH 08/18] staging:iio:accel:sca3000 use a 'fake' channel to handle freefall event registration Jonathan Cameron
2016-10-03 19:26 ` [PATCH 09/18] staging:iio:accel:sca3000 Clean up register defines Jonathan Cameron
2016-10-03 19:26 ` [PATCH 10/18] staging:iio:accel:sca3000 add readback of the 3db low pass filter frequency Jonathan Cameron
2016-10-03 19:26 ` Jonathan Cameron [this message]
2016-10-04  8:52   ` [PATCH 11/18] staging:iio:accel:sca3000: Fix off by one error in axis due to IIO_NO_MOD Lars-Peter Clausen
2016-10-08 16:59     ` Jonathan Cameron
2016-10-03 19:26 ` [PATCH 12/18] staging:iio:accel:sca3000 Add write support to the low pass filter control Jonathan Cameron
2016-10-03 19:26 ` [PATCH 13/18] staging:iio:accel:sca3000 Drop custom measurement mode attributes Jonathan Cameron
2016-10-03 19:26 ` [PATCH 14/18] staging:iio:accel:sca3000 replace non standard revision attr with dev_info on probe Jonathan Cameron
2016-10-03 19:26 ` [PATCH 15/18] staging:iio:accel:sca3000 Tidy up probe order to avoid a race Jonathan Cameron
2016-10-03 19:27 ` [PATCH 16/18] staging:iio:accel:sca3000 small checkpatch fixes (alignment etc) Jonathan Cameron
2016-10-03 19:27 ` [PATCH 17/18] staging:iio:accel:sca3000 kernel docify comments that were nearly kernel doc Jonathan Cameron
2016-10-03 20:07   ` Peter Meerwald-Stadler
2016-10-03 20:27     ` Jonathan Cameron
2016-10-03 19:27 ` [PATCH 18/18] staging:iio:accel:sca3000 Move out of staging Jonathan Cameron
  -- strict thread matches above, loose matches on Subject: below --
2016-10-08 16:39 [PATCH 00/18 V2] staging:iio:accel rework driver and move " Jonathan Cameron
2016-10-08 16:39 ` [PATCH 11/18] staging:iio:accel:sca3000: Fix off by one error in axis due to IIO_NO_MOD 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=20161003192702.24361-12-jic23@kernel.org \
    --to=jic23@kernel.org \
    --cc=knaack.h@gmx.de \
    --cc=lars@metafoo.de \
    --cc=linux-iio@vger.kernel.org \
    --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).