Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754145AbdG3Nn4 (ORCPT ); Sun, 30 Jul 2017 09:43:56 -0400 Received: from mail.kernel.org ([198.145.29.99]:39298 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751360AbdG3Nnz (ORCPT ); Sun, 30 Jul 2017 09:43:55 -0400 DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org B315C22BE3 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=jic23@kernel.org Date: Sun, 30 Jul 2017 14:43:50 +0100 From: Jonathan Cameron To: Fabrice Gasnier Cc: , , , , , , , , , Subject: Re: [PATCH 1/4] iio: trigger: stm32-timer: fix quadrature mode get routine Message-ID: <20170730144350.17095cf1@kernel.org> In-Reply-To: <1501172340-8448-2-git-send-email-fabrice.gasnier@st.com> References: <1501172340-8448-1-git-send-email-fabrice.gasnier@st.com> <1501172340-8448-2-git-send-email-fabrice.gasnier@st.com> X-Mailer: Claws Mail 3.15.0-dirty (GTK+ 2.24.31; x86_64-unknown-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1386 Lines: 41 On Thu, 27 Jul 2017 18:18:57 +0200 Fabrice Gasnier wrote: > 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 Applied to the fixes-togreg branch of iio.git. Thanks, Jonathan > --- > 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 = {