From patchwork Fri Feb 12 12:13:33 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: William Breathitt Gray X-Patchwork-Id: 12085175 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.7 required=3.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED,DKIM_SIGNED,DKIM_VALID,FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3A682C433E0 for ; Fri, 12 Feb 2021 12:17:26 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id F150564E13 for ; Fri, 12 Feb 2021 12:17:25 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org F150564E13 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To:Message-Id:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=d+3L47Gos9i0JuKH/fLsJ76oRwGRS+aYAWM/zdvnPDg=; b=xRViKsXleCkE5tGVk8uGrvdcE 6NGgeCtw1idoud3VImbgop14uz5QMBvw6V5o+IDXpfOygR8qcsrQQLpw6x5VmmQxZ0VPYt7couEd3 bTys/ygLvDQOFGJTH5f9Q4LlLGvD02AMSZpD2P+xdZPkunMFQ4sjsDdzlOernfw39KoViLG00JG/3 e9oI9xqLQEFJwih/p8HmRmXvqPt62EPDgEgk4WfGT4uVHD3iRaY78blntNFLQhhy7FlycnokPS75N p84IcHTQ4HXPIY3P8EtVWpm8QUE9yrRsUBVvwbhwwIGKhkP97REDrO/p8xsY1PHQQYBYZjjznmnPw 5mrFsMvJg==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1lAXMH-0006lC-42; Fri, 12 Feb 2021 12:15:39 +0000 Received: from mail-qt1-x835.google.com ([2607:f8b0:4864:20::835]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1lAXLZ-0006S8-Eg for linux-arm-kernel@lists.infradead.org; Fri, 12 Feb 2021 12:14:58 +0000 Received: by mail-qt1-x835.google.com with SMTP id h16so6451448qth.11 for ; Fri, 12 Feb 2021 04:14:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=ckwJFnHA3Ef54UBvumcIhohktCn1MgimffdexzCqvp8=; b=rID13hQE22qt9kcq+wLvY7Fe0EkTknHvuhduTdt/5CijZn42zVE6W2yBGpK5X/36w+ m17P0l7fxXZ3a189boYzBOGrvZsP9+/6W0Fc8KhvFqq2lpXCIjVD+u8sp2In6bOkOFuQ tDxesjYyKRpOclTKC4CWsFILYh1w6krnHWyDeDVMzG7LWke+CQUd2+0oZCxJjwYd7hgt apQt8lTpx8babc/c5f8XadWmQh+zcVwWexRzLedYpyn6rNJRVzO+NJw55QLynIg8bAWk Alkplvh+kP+5ClxDSAtQ/RHGp5BrBAew8TifCB1k5DHbJGE1FucPVtYZwckOF0oTm9E1 Mo+A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ckwJFnHA3Ef54UBvumcIhohktCn1MgimffdexzCqvp8=; b=g8aaab4vdBe09rmuekDZXzVnbS7aaCMFYJriVlioyjQT//84ZH8HEkvXwtsdKNcuNB IvH2Es/iR9ZIMGev1Lw/PKKCVm91BTlvCLp0vE1U5Za7oaF6OQIGra8JXjTedRjNnzhu yPmmdxaZWrE4nBYSbMn7H7dQpUWRyBbr3Dp+eOdoWxiCoZvqs92BwKaWaKgzWbbrkaCo AGv46odwfYfuolSySJsesE0v26p65W7N8JkU17SgI/UPq47lE6L3Z9k53oo1EYoawOkc qsDttP0E8nMKwqE6zhR9JI2S5TJWZrnb3Km2PgP5TbrofyYhNeF3BBpLlUHTA5rMpUvo ZGDQ== X-Gm-Message-State: AOAM5337elVJQGoxdfzjTkd8aTQepVomOtPTbjHjvZdlcIGbaX6vXNl9 uanZcVBItU48wDfcQ3T1AEk= X-Google-Smtp-Source: ABdhPJzPXPFhdl3w1dHI2M/nPQxpkVoxksZtolDQFvMNNntM0Z1oUbvll2KQyXp6re8HSM36Xkdm0A== X-Received: by 2002:aed:2e42:: with SMTP id j60mr2050905qtd.189.1613132091879; Fri, 12 Feb 2021 04:14:51 -0800 (PST) Received: from localhost.localdomain ([193.27.12.132]) by smtp.gmail.com with ESMTPSA id y135sm6278534qkb.14.2021.02.12.04.14.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Feb 2021 04:14:51 -0800 (PST) From: William Breathitt Gray To: jic23@kernel.org Subject: [PATCH v8 09/22] counter: Return error code on invalid modes Date: Fri, 12 Feb 2021 21:13:33 +0900 Message-Id: <58e7c59bb7c7bb94c8655903308842d9d9e9907a.1613131238.git.vilhelm.gray@gmail.com> X-Mailer: git-send-email 2.30.0 In-Reply-To: References: MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210212_071455_078637_BF5E090A X-CRM114-Status: GOOD ( 14.47 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kamel.bouhara@bootlin.com, gwendal@chromium.org, a.fatoum@pengutronix.de, david@lechnology.com, linux-iio@vger.kernel.org, patrick.havelange@essensium.com, alexandre.belloni@bootlin.com, mcoquelin.stm32@gmail.com, linux-kernel@vger.kernel.org, o.rempel@pengutronix.de, kernel@pengutronix.de, William Breathitt Gray , fabrice.gasnier@st.com, syednwaris@gmail.com, linux-stm32@st-md-mailman.stormreply.com, linux-arm-kernel@lists.infradead.org, alexandre.torgue@st.com Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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. 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 Reviewed-by: David Lechner --- 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;