Received: by 2002:a05:6a10:c604:0:0:0:0 with SMTP id y4csp2060962pxt; Sun, 8 Aug 2021 10:08:30 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxe6KDgj/U9LHpm3pMFHIcnDTXHTlEikyVZx9kfq7tvrAyMtPNlHk0FOMELe7jMfBjkeajQ X-Received: by 2002:a05:6402:3193:: with SMTP id di19mr6658261edb.183.1628442510332; Sun, 08 Aug 2021 10:08:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1628442510; cv=none; d=google.com; s=arc-20160816; b=bUt27CMEEtOzkRZAwIrz175ZcaX+SsR6pwE26QU2HeEmIGuSxWunrULu8/jnQGxJYp bkeGqAzbil2c6IVf/IR+T3AwKAk/bNV8TjyiEaBFmtkE3mB7H6/FDFiRn0Rp/xZ/Z0wl 6Pu3pYM8e3YkhCSuIDT1Qnk5dYPIE/LDB3/u3GLBvcfeamekbYg1wO9IimEK0Dpe39PE e6B4T8EfArtRSjCioE4fkPioS3WkgPz6UFELx9fauYtGnttx83H4RrQShrCwssIoW2W2 BIUiat+tOqiui+lPaKbSCneJxUga4R0RVfIqS6VpupdgR+/oORTclEtfZnoeTNFkl99O aG2g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date; bh=lVHx+UIZTx24gEiSsOswnss0QYLkT0+N2rUgfGXM9eY=; b=TnUlICqtA2qgEdwpbWwYjpxWMJ5DFmjEn+ak9+N7c9xyd3ERYfzvGAvdj3JcrnDnWS Ir/ZSbS/AZdnKLK7ZLuB/eaagZxGuuYm2cIyFKclYM62fAZyPcZ4jnb8gUw6kw++YbMA M+KR8Bqw5KgBHtpjHo3uw+eaqIlyySk4ux2bt4sQ+JWQSo69x/1pehybtHH12A5SDyW1 MgBUv4PzxoUdIXea6vFasC0ypHOm2BlEZ7hFDIm/U6XabUjFLyEroInd37YFFgLgMhWg ujkKjUjQJLjAjwPHGZUr3bFcKWwQzqxd3847f0D/bhvCRdy5jJCEqrk+afDLokC5dKqo Xq2w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id sb6si14160010ejb.100.2021.08.08.10.08.07; Sun, 08 Aug 2021 10:08:30 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231967AbhHHREp (ORCPT + 99 others); Sun, 8 Aug 2021 13:04:45 -0400 Received: from mail.kernel.org ([198.145.29.99]:39036 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230169AbhHHREp (ORCPT ); Sun, 8 Aug 2021 13:04:45 -0400 Received: from jic23-huawei (cpc108967-cmbg20-2-0-cust86.5-4.cable.virginm.net [81.101.6.87]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 7863E60E93; Sun, 8 Aug 2021 17:04:21 +0000 (UTC) Date: Sun, 8 Aug 2021 18:07:11 +0100 From: Jonathan Cameron To: William Breathitt Gray Cc: linux-stm32@st-md-mailman.stormreply.com, kernel@pengutronix.de, a.fatoum@pengutronix.de, kamel.bouhara@bootlin.com, gwendal@chromium.org, alexandre.belloni@bootlin.com, david@lechnology.com, linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, syednwaris@gmail.com, patrick.havelange@essensium.com, fabrice.gasnier@st.com, mcoquelin.stm32@gmail.com, alexandre.torgue@st.com, o.rempel@pengutronix.de, jarkko.nikula@linux.intel.com, Fabrice Gasnier Subject: Re: [PATCH v14 02/17] counter: Return error code on invalid modes Message-ID: <20210808180711.0b359e79@jic23-huawei> In-Reply-To: <7af82d4e39610da11edce0ee370285fe1cb1eac8.1627990337.git.vilhelm.gray@gmail.com> References: <7af82d4e39610da11edce0ee370285fe1cb1eac8.1627990337.git.vilhelm.gray@gmail.com> X-Mailer: Claws Mail 4.0.0 (GTK+ 3.24.30; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, 3 Aug 2021 21:06:12 +0900 William Breathitt Gray wrote: > Only a select set of modes (function, action, etc.) are valid for a > given device configuration. This patch ensures that invalid modes result > in a return -EINVAL. Such a situation should never occur in reality, but > it's good to define a default switch case for the sake of making the > intent of the code clear. > > Cc: Kamel Bouhara > Cc: Maxime Coquelin > Cc: Alexandre Torgue > Acked-by: David Lechner > Acked-by: Syed Nayyar Waris > Reviewed-by: Fabrice Gasnier > Signed-off-by: William Breathitt Gray Applied, Thanks, > --- > drivers/counter/104-quad-8.c | 20 ++++++++++++------ > drivers/counter/microchip-tcb-capture.c | 6 ++++++ > drivers/counter/stm32-lptimer-cnt.c | 10 +++++---- > drivers/counter/ti-eqep.c | 27 +++++++++++++++---------- > 4 files changed, 42 insertions(+), 21 deletions(-) > > diff --git a/drivers/counter/104-quad-8.c b/drivers/counter/104-quad-8.c > index 81f9642777fb..b358b2b2b883 100644 > --- a/drivers/counter/104-quad-8.c > +++ b/drivers/counter/104-quad-8.c > @@ -273,6 +273,10 @@ static int quad8_function_set(struct counter_device *counter, > *scale = 2; > mode_cfg |= QUAD8_CMR_QUADRATURE_X4; > break; > + default: > + /* should never reach this path */ > + mutex_unlock(&priv->lock); > + return -EINVAL; > } > } > > @@ -349,7 +353,7 @@ static int quad8_action_get(struct counter_device *counter, > case QUAD8_COUNT_FUNCTION_PULSE_DIRECTION: > if (synapse->signal->id == signal_a_id) > *action = QUAD8_SYNAPSE_ACTION_RISING_EDGE; > - break; > + return 0; > case QUAD8_COUNT_FUNCTION_QUADRATURE_X1: > if (synapse->signal->id == signal_a_id) { > quad8_direction_get(counter, count, &direction); > @@ -359,17 +363,18 @@ static int quad8_action_get(struct counter_device *counter, > else > *action = QUAD8_SYNAPSE_ACTION_FALLING_EDGE; > } > - break; > + return 0; > case QUAD8_COUNT_FUNCTION_QUADRATURE_X2: > if (synapse->signal->id == signal_a_id) > *action = QUAD8_SYNAPSE_ACTION_BOTH_EDGES; > - break; > + return 0; > case QUAD8_COUNT_FUNCTION_QUADRATURE_X4: > *action = QUAD8_SYNAPSE_ACTION_BOTH_EDGES; > - break; > + return 0; > + default: > + /* should never reach this path */ > + return -EINVAL; > } > - > - return 0; > } > > static const struct counter_ops quad8_ops = { > @@ -529,6 +534,9 @@ static int quad8_count_mode_set(struct counter_device *counter, > case COUNTER_COUNT_MODE_MODULO_N: > cnt_mode = 3; > break; > + default: > + /* should never reach this path */ > + return -EINVAL; > } > > mutex_lock(&priv->lock); > diff --git a/drivers/counter/microchip-tcb-capture.c b/drivers/counter/microchip-tcb-capture.c > index 51b8af80f98b..0c9a61962911 100644 > --- a/drivers/counter/microchip-tcb-capture.c > +++ b/drivers/counter/microchip-tcb-capture.c > @@ -133,6 +133,9 @@ static int mchp_tc_count_function_set(struct counter_device *counter, > bmr |= ATMEL_TC_QDEN | ATMEL_TC_POSEN; > cmr |= ATMEL_TC_ETRGEDG_RISING | ATMEL_TC_ABETRG | ATMEL_TC_XC0; > break; > + default: > + /* should never reach this path */ > + return -EINVAL; > } > > regmap_write(priv->regmap, ATMEL_TC_BMR, bmr); > @@ -226,6 +229,9 @@ static int mchp_tc_count_action_set(struct counter_device *counter, > case MCHP_TC_SYNAPSE_ACTION_BOTH_EDGE: > edge = ATMEL_TC_ETRGEDG_BOTH; > break; > + default: > + /* should never reach this path */ > + return -EINVAL; > } > > return regmap_write_bits(priv->regmap, > diff --git a/drivers/counter/stm32-lptimer-cnt.c b/drivers/counter/stm32-lptimer-cnt.c > index c19d998df5ba..78f383b77bd2 100644 > --- a/drivers/counter/stm32-lptimer-cnt.c > +++ b/drivers/counter/stm32-lptimer-cnt.c > @@ -206,9 +206,10 @@ static int stm32_lptim_cnt_function_set(struct counter_device *counter, > priv->quadrature_mode = 1; > priv->polarity = STM32_LPTIM_SYNAPSE_ACTION_BOTH_EDGES; > return 0; > + default: > + /* should never reach this path */ > + return -EINVAL; > } > - > - return -EINVAL; > } > > static ssize_t stm32_lptim_cnt_enable_read(struct counter_device *counter, > @@ -326,9 +327,10 @@ static int stm32_lptim_cnt_action_get(struct counter_device *counter, > case STM32_LPTIM_ENCODER_BOTH_EDGE: > *action = priv->polarity; > return 0; > + default: > + /* should never reach this path */ > + return -EINVAL; > } > - > - return -EINVAL; > } > > static int stm32_lptim_cnt_action_set(struct counter_device *counter, > diff --git a/drivers/counter/ti-eqep.c b/drivers/counter/ti-eqep.c > index 65df9ef5b5bc..c303eb17c111 100644 > --- a/drivers/counter/ti-eqep.c > +++ b/drivers/counter/ti-eqep.c > @@ -157,7 +157,7 @@ static int ti_eqep_action_get(struct counter_device *counter, > * QEPA and QEPB trigger QCLK. > */ > *action = TI_EQEP_SYNAPSE_ACTION_BOTH_EDGES; > - break; > + return 0; > case TI_EQEP_COUNT_FUNC_DIR_COUNT: > /* In direction-count mode only rising edge of QEPA is counted > * and QEPB gives direction. > @@ -165,12 +165,14 @@ static int ti_eqep_action_get(struct counter_device *counter, > switch (synapse->signal->id) { > case TI_EQEP_SIGNAL_QEPA: > *action = TI_EQEP_SYNAPSE_ACTION_RISING_EDGE; > - break; > - default: > + return 0; > + case TI_EQEP_SIGNAL_QEPB: > *action = TI_EQEP_SYNAPSE_ACTION_NONE; > - break; > + return 0; > + default: > + /* should never reach this path */ > + return -EINVAL; > } > - break; > case TI_EQEP_COUNT_FUNC_UP_COUNT: > case TI_EQEP_COUNT_FUNC_DOWN_COUNT: > /* In up/down-count modes only QEPA is counted and QEPB is not > @@ -186,15 +188,18 @@ static int ti_eqep_action_get(struct counter_device *counter, > *action = TI_EQEP_SYNAPSE_ACTION_BOTH_EDGES; > else > *action = TI_EQEP_SYNAPSE_ACTION_RISING_EDGE; > - break; > - default: > + return 0; > + case TI_EQEP_SIGNAL_QEPB: > *action = TI_EQEP_SYNAPSE_ACTION_NONE; > - break; > + return 0; > + default: > + /* should never reach this path */ > + return -EINVAL; > } > - break; > + default: > + /* should never reach this path */ > + return -EINVAL; > } > - > - return 0; > } > > static const struct counter_ops ti_eqep_counter_ops = {