Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp4404694pxb; Sun, 14 Feb 2021 09:11:00 -0800 (PST) X-Google-Smtp-Source: ABdhPJxgFCOpVyx+AgZCnhKJ2x+BkFDWi3w5ht4cYI1SsDd5ZWmsS13en2fRe1eKsdFRxTwKSyS+ X-Received: by 2002:aa7:c0d9:: with SMTP id j25mr10106350edp.266.1613322660355; Sun, 14 Feb 2021 09:11:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1613322660; cv=none; d=google.com; s=arc-20160816; b=0Fkx8GRlgUp8cVxtvzNVyZhZumMH1JwnDBZ178vME9OnSKovYT2UyFoSWMgOn3AhpR yOVf84LFoXayF1izZqPc2G9R3heuaoBUPD1u39CbbJ7gYrCkrv0cC8+5d8KaS5SIP3jz 6mhc/TBN+gWTvtKeg7E9dNgGl7lZzSKCY1ctc8IchPUnGYc9pUqwSkGTp2xaZHDgGVTM 1Kc4XH0aifDOlEUhEkOv0yFIn0w4y9RW+pSCtPlo35QhFLaDCEBlXYpIiDQx26mQvtHR mh0xjIwwHAuWa0e2BAlP48Tn5Ge4rN3N60PdYHkR+A5MDMdu6b73n+pDtrl7KuOzmcSD hxzg== 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=GfF32KXBEbE+u1icvhQjPow/TD4POhfUMIci9I+N98g=; b=ffvdbVGh7WNrvgYiqxSdxHoGRAWPPDBz3s00uG7z35DK9lg9aIL7xdjB76udJp0VZ4 N0/nFgHex4lmFxurSTbVsw4Vv3INkvJqMn1sqT5FHY2zHR4b0IlvR5gfB50mjFL9julA 1ygl4H5fgbqihsSc3Zh0ULmgvF+j6JxRTYhkGZ6mvzjW4rqzMNyCTUf/xJS9SrpvvMfW 1gctCFjoTrdIfbCcbJ7+byaksBGPyuqxBppMMug89ifMD4Jsp5RjqJF5dRtWEFXG1KTQ 1a4I+qUm9fEWiioUrNL1JKousSQEgXn+SCuiGslCXfWQ5m+uKuusUlDF+neS1k75TOUw wW6Q== 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 jg13si12508650ejc.126.2021.02.14.09.10.37; Sun, 14 Feb 2021 09:11:00 -0800 (PST) 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 S229818AbhBNRIc (ORCPT + 99 others); Sun, 14 Feb 2021 12:08:32 -0500 Received: from mail.kernel.org ([198.145.29.99]:48164 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229758AbhBNRIc (ORCPT ); Sun, 14 Feb 2021 12:08:32 -0500 Received: from archlinux (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 05ECA64DBA; Sun, 14 Feb 2021 17:07:47 +0000 (UTC) Date: Sun, 14 Feb 2021 17:07:43 +0000 From: Jonathan Cameron To: William Breathitt Gray Cc: kernel@pengutronix.de, linux-stm32@st-md-mailman.stormreply.com, 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 Subject: Re: [PATCH v8 09/22] counter: Return error code on invalid modes Message-ID: <20210214170743.090e8b60@archlinux> In-Reply-To: <58e7c59bb7c7bb94c8655903308842d9d9e9907a.1613131238.git.vilhelm.gray@gmail.com> References: <58e7c59bb7c7bb94c8655903308842d9d9e9907a.1613131238.git.vilhelm.gray@gmail.com> X-Mailer: Claws Mail 3.17.8 (GTK+ 2.24.33; 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 Fri, 12 Feb 2021 21:13:33 +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 cases for the sake of making the > intent of the code clear. In many of these cases it may make sense to also return early in the good paths rather than share a return 0 at the end of the function? > > Cc: Syed Nayyar Waris > Cc: Kamel Bouhara > Cc: Fabrice Gasnier > Cc: Maxime Coquelin > Cc: Alexandre Torgue > Cc: David Lechner > Signed-off-by: William Breathitt Gray > --- > drivers/counter/104-quad-8.c | 10 ++++++++++ > drivers/counter/microchip-tcb-capture.c | 6 ++++++ > drivers/counter/stm32-lptimer-cnt.c | 10 ++++++---- > drivers/counter/stm32-timer-cnt.c | 3 +++ > drivers/counter/ti-eqep.c | 3 +++ > 5 files changed, 28 insertions(+), 4 deletions(-) > > diff --git a/drivers/counter/104-quad-8.c b/drivers/counter/104-quad-8.c > index 9a96296b0625..674263b4d2c4 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; > } > } > > @@ -367,6 +371,9 @@ static int quad8_action_get(struct counter_device *counter, > case QUAD8_COUNT_FUNCTION_QUADRATURE_X4: > *action = QUAD8_SYNAPSE_ACTION_BOTH_EDGES; > break; > + default: > + /* should never reach this path */ > + return -EINVAL; > } > > return 0; > @@ -529,6 +536,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 710acc0a3704..ee979b011012 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 937439635d53..daf988e7b208 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/stm32-timer-cnt.c b/drivers/counter/stm32-timer-cnt.c > index ef2a974a2f10..431a3d08ed6c 100644 > --- a/drivers/counter/stm32-timer-cnt.c > +++ b/drivers/counter/stm32-timer-cnt.c > @@ -296,6 +296,9 @@ static int stm32_action_get(struct counter_device *counter, > /* counts up/down on both TI1FP1 and TI2FP2 edges */ > *action = STM32_SYNAPSE_ACTION_BOTH_EDGES; > break; > + default: > + /* should never reach this path */ > + return -EINVAL; > } > > return 0; > diff --git a/drivers/counter/ti-eqep.c b/drivers/counter/ti-eqep.c > index a60aee1a1a29..7844fdf78a97 100644 > --- a/drivers/counter/ti-eqep.c > +++ b/drivers/counter/ti-eqep.c > @@ -192,6 +192,9 @@ static int ti_eqep_action_get(struct counter_device *counter, > break; > } > break; > + default: > + /* should never reach this path */ > + return -EINVAL; > } > > return 0;