Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp2578884pxb; Tue, 24 Aug 2021 02:30:08 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy20sK6iwUvB+CFZOJXydGRSA6hLkiyM1oGSmuEhMZa0hoxnr78nehnAleVdvGHtkpLILb+ X-Received: by 2002:a5e:8e4c:: with SMTP id r12mr30436871ioo.73.1629797408127; Tue, 24 Aug 2021 02:30:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1629797408; cv=none; d=google.com; s=arc-20160816; b=V3m5iCbYnq8zyiNAQ/ia10F88XL2vhXCRTZ0ySriyo/lfn1G/Zpnmov2UUGQ1IPYae S4ZNWfp70z6jxesiQHhtc6Pt/KLSw/ZGusxd6OuhfTQ6EwzyUstaSek+f6nSXE7Rhznf ZrLBJ701nNhnbPB/YPQvHMEDrCLV3Z41XIbMLTt1Dh0zVoKeA0Z+FXRNfXiSAoFSHgZM HgXQEe55nHAMRTJ0H0OZWW8W6W4WsBAi2jj+q6bhwAQU3gzVY7Acg5bTy0DXZFFhBN4Y vie/PtVLbuUklQjhQkq3Pl52rLlPImkqM8MFuK7LaY9GY85BGzhpYcVEIjEKI3y34mfx idqg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:message-id:date:subject:cc:to:from; bh=y7BNRyByVzTUHEMPoRolFIv3opgDCZNn9B9BvCs9TAE=; b=uMIerxnPNHfLBxhjehSUt3QySfeMOTbY7hsbQdHk8Y6DvN12KEe9T0rJIjO58UKaOF vcc6FriiUDhhQXKQz7twXt11M5YBUPuQqvACa5y+Q9qEUmcNhwgELW40lfZv8saf8lyR wXMoB69RulyvrSUKFQrB0OEtRqA5eVn5FQehiaMiIMdQW0xd2AF3vKcDHMlf7Mxe41ZJ v9vTQO6bYyjCf+4hqgpVQdlWHoXbFtxPfuY0mIQYO902AX8IeatlacI922H71xeK/Kqo RSGE1oqklx56po4f6TRfNYMQM+bKiXQi904vWz0jgMtejZzyK9jGFpvNwnzSI07tz1lI 6RJA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=mediatek.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id c1si19217588ilo.83.2021.08.24.02.29.46; Tue, 24 Aug 2021 02:30:08 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-crypto-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-crypto-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=mediatek.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235778AbhHXJaG (ORCPT + 99 others); Tue, 24 Aug 2021 05:30:06 -0400 Received: from mailgw02.mediatek.com ([210.61.82.184]:51962 "EHLO mailgw02.mediatek.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S235642AbhHXJaF (ORCPT ); Tue, 24 Aug 2021 05:30:05 -0400 X-UUID: 7e43988e7f59449eaada16ee93508e5c-20210824 X-UUID: 7e43988e7f59449eaada16ee93508e5c-20210824 Received: from mtkcas11.mediatek.inc [(172.21.101.40)] by mailgw02.mediatek.com (envelope-from ) (Generic MTA with TLSv1.2 ECDHE-RSA-AES256-SHA384 256/256) with ESMTP id 19402614; Tue, 24 Aug 2021 17:29:17 +0800 Received: from mtkcas07.mediatek.inc (172.21.101.84) by mtkmbs06n1.mediatek.inc (172.21.101.129) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Tue, 24 Aug 2021 17:29:15 +0800 Received: from mtksdccf07.mediatek.inc (172.21.84.99) by mtkcas07.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Tue, 24 Aug 2021 17:29:15 +0800 From: Sam Shih To: Rob Herring , Sean Wang , Linus Walleij , Matthias Brugger , Matt Mackall , Herbert Xu , Greg Kroah-Hartman , Wim Van Sebroeck , Guenter Roeck , Michael Turquette , Stephen Boyd , Hsin-Yi Wang , Enric Balletbo i Serra , Fabien Parent , Seiya Wang , , , , , , , , , CC: John Crispin , Ryder Lee , Sam Shih Subject: [v3,04/12] pinctrl: mediatek: moore: check if pin_desc is valid before use Date: Tue, 24 Aug 2021 17:29:03 +0800 Message-ID: <20210824092904.25439-1-sam.shih@mediatek.com> X-Mailer: git-send-email 2.18.0 MIME-Version: 1.0 Content-Type: text/plain X-MTK: N Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org Certain SoC are missing the middle part gpios in consecutive pins, it's better to check if mtk_pin_desc is a valid pin for the extensibility Signed-off-by: Sam Shih Acked-by: Sean Wang --- v3: added an Acked-by tag. v2: applied the comment suggested by reviewers: - for the pins not ballout, we can fill .name in struct mtk_pin_desc as NULL and return -ENOTSUPP in gpio/pinconf ops. --- drivers/pinctrl/mediatek/pinctrl-moore.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/drivers/pinctrl/mediatek/pinctrl-moore.c b/drivers/pinctrl/mediatek/pinctrl-moore.c index 3a4a23c40a71..ad3b67163973 100644 --- a/drivers/pinctrl/mediatek/pinctrl-moore.c +++ b/drivers/pinctrl/mediatek/pinctrl-moore.c @@ -60,6 +60,8 @@ static int mtk_pinmux_set_mux(struct pinctrl_dev *pctldev, int pin = grp->pins[i]; desc = (const struct mtk_pin_desc *)&hw->soc->pins[pin]; + if (!desc->name) + return -ENOTSUPP; mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_MODE, pin_modes[i]); @@ -76,6 +78,8 @@ static int mtk_pinmux_gpio_request_enable(struct pinctrl_dev *pctldev, const struct mtk_pin_desc *desc; desc = (const struct mtk_pin_desc *)&hw->soc->pins[pin]; + if (!desc->name) + return -ENOTSUPP; return mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_MODE, hw->soc->gpio_m); @@ -89,6 +93,8 @@ static int mtk_pinmux_gpio_set_direction(struct pinctrl_dev *pctldev, const struct mtk_pin_desc *desc; desc = (const struct mtk_pin_desc *)&hw->soc->pins[pin]; + if (!desc->name) + return -ENOTSUPP; /* hardware would take 0 as input direction */ return mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_DIR, !input); @@ -103,6 +109,8 @@ static int mtk_pinconf_get(struct pinctrl_dev *pctldev, const struct mtk_pin_desc *desc; desc = (const struct mtk_pin_desc *)&hw->soc->pins[pin]; + if (!desc->name) + return -ENOTSUPP; switch (param) { case PIN_CONFIG_BIAS_DISABLE: @@ -218,6 +226,8 @@ static int mtk_pinconf_set(struct pinctrl_dev *pctldev, unsigned int pin, int cfg, err = 0; desc = (const struct mtk_pin_desc *)&hw->soc->pins[pin]; + if (!desc->name) + return -ENOTSUPP; for (cfg = 0; cfg < num_configs; cfg++) { param = pinconf_to_config_param(configs[cfg]); @@ -435,6 +445,8 @@ static int mtk_gpio_get(struct gpio_chip *chip, unsigned int gpio) int value, err; desc = (const struct mtk_pin_desc *)&hw->soc->pins[gpio]; + if (!desc->name) + return -ENOTSUPP; err = mtk_hw_get_value(hw, desc, PINCTRL_PIN_REG_DI, &value); if (err) @@ -449,6 +461,10 @@ static void mtk_gpio_set(struct gpio_chip *chip, unsigned int gpio, int value) const struct mtk_pin_desc *desc; desc = (const struct mtk_pin_desc *)&hw->soc->pins[gpio]; + if (!desc->name) { + dev_err(hw->dev, "Failed to set gpio %d\n", gpio); + return; + } mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_DO, !!value); } @@ -490,6 +506,8 @@ static int mtk_gpio_set_config(struct gpio_chip *chip, unsigned int offset, u32 debounce; desc = (const struct mtk_pin_desc *)&hw->soc->pins[offset]; + if (!desc->name) + return -ENOTSUPP; if (!hw->eint || pinconf_to_config_param(config) != PIN_CONFIG_INPUT_DEBOUNCE || -- 2.29.2