Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1698167

[PATCH 1/4] iio: trigger: stm32-timer: fix quadrature mode get routine

From Fabrice Gasnier <fabrice.gasnier@st.com>
Newsgroups linux.kernel
Subject [PATCH 1/4] iio: trigger: stm32-timer: fix quadrature mode get routine
Date 2017-07-27 18:30 +0200
Message-ID <u7TPI-8oO-9@gated-at.bofh.it> (permalink)
References <u7TPI-8oO-7@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


Fixes: 4adec7da0536 ("iio: stm32 trigger: Add quadrature encoder device")

SMS bitfiled is mode + 1. After reset, upon boot, SMS = 0. When reading
from sysfs, stm32_get_quadrature_mode() returns -1 (e.g. -EPERM) which is
wrong error code here. So, check SMS bitfiled matches valid encoder mode,
or return -EINVAL.

Signed-off-by: Fabrice Gasnier <fabrice.gasnier@st.com>
---
 drivers/iio/trigger/stm32-timer-trigger.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/drivers/iio/trigger/stm32-timer-trigger.c b/drivers/iio/trigger/stm32-timer-trigger.c
index d22bc56..6aa73d6 100644
--- a/drivers/iio/trigger/stm32-timer-trigger.c
+++ b/drivers/iio/trigger/stm32-timer-trigger.c
@@ -571,11 +571,14 @@ static int stm32_get_quadrature_mode(struct iio_dev *indio_dev,
 {
 	struct stm32_timer_trigger *priv = iio_priv(indio_dev);
 	u32 smcr;
+	int mode;
 
 	regmap_read(priv->regmap, TIM_SMCR, &smcr);
-	smcr &= TIM_SMCR_SMS;
+	mode = (smcr & TIM_SMCR_SMS) - 1;
+	if ((mode < 0) || (mode > ARRAY_SIZE(stm32_quadrature_modes)))
+		return -EINVAL;
 
-	return smcr - 1;
+	return mode;
 }
 
 static const struct iio_enum stm32_quadrature_mode_enum = {
-- 
1.9.1

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

[PATCH 0/4] iio: trigger: stm32-timer fixes Fabrice Gasnier <fabrice.gasnier@st.com> - 2017-07-27 18:30 +0200
  [PATCH 1/4] iio: trigger: stm32-timer: fix quadrature mode get routine Fabrice Gasnier <fabrice.gasnier@st.com> - 2017-07-27 18:30 +0200
    Re: [PATCH 1/4] iio: trigger: stm32-timer: fix quadrature mode get  routine Jonathan Cameron <jic23@kernel.org> - 2017-07-30 15:50 +0200
  [PATCH 3/4] iio: trigger: stm32-timer: fix get/set down count direction Fabrice Gasnier <fabrice.gasnier@st.com> - 2017-07-27 18:30 +0200
    Re: [PATCH 3/4] iio: trigger: stm32-timer: fix get/set down count  direction Jonathan Cameron <jic23@kernel.org> - 2017-07-30 15:50 +0200
  [PATCH 2/4] iio: trigger: stm32-timer: fix write_raw return value Fabrice Gasnier <fabrice.gasnier@st.com> - 2017-07-27 18:30 +0200
    Re: [PATCH 2/4] iio: trigger: stm32-timer: fix write_raw return  value Jonathan Cameron <jic23@kernel.org> - 2017-07-30 15:50 +0200
  [PATCH 4/4] iio: trigger: stm32-timer: add enable attribute Fabrice Gasnier <fabrice.gasnier@st.com> - 2017-07-27 18:30 +0200
    Re: [PATCH 4/4] iio: trigger: stm32-timer: add enable attribute Jonathan Cameron <jic23@kernel.org> - 2017-07-30 15:50 +0200
  Re: [PATCH 0/4] iio: trigger: stm32-timer fixes Benjamin Gaignard <benjamin.gaignard@linaro.org> - 2017-07-28 10:20 +0200

csiph-web