Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp822128pxk; Mon, 31 Aug 2020 01:53:10 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxNJuS+pJlDThlrdv4IrZxYKjkjvdngc2NcoOX4raZHzgWyJ/L8D/S8NziMpVH4uBsnubeJ X-Received: by 2002:a17:906:76c7:: with SMTP id q7mr140666ejn.541.1598863990535; Mon, 31 Aug 2020 01:53:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1598863990; cv=none; d=google.com; s=arc-20160816; b=D/0/DoFtrm3guAb1Nofp9ZjnT3NJeYjNH6asgqXsqhiP+DgLAw/Dw2pf7m8jgT/4m9 qJ2lVuquF7BWf0d4oX5mO2MFHM0U/vs56vceDwVaGNroT5f+UzJYAaNiAE9anpORrH7D rB3gCPzPmypmksO/5z6ggMMIxDYXdYgx+RUfWKKYUe9ACEZ1+JZj4Dv+/zBM/hR2DoUP Nfpe7VTnks21wdCkNVw7JTAVA4hgvLzwHjYp4e09nc/mdifRNuokCUuy6JpRWHIuOOXD 1ek3+XkZstap3amk53/2hCpus5nS75ldcce/mDbnOUvNznqR/IiK8/ccObSZ36y/m9Ko HaJw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from; bh=noOXv7Z/xj6hxkrWFKw3II9fXCy+rlJESkBiVrLLJts=; b=oR3ohiRdfSsIX18IDBOTgxFxqQEo3RQ3Hv8Vd57Y2WG8wvhOrxkc5FZL13YhE+2DdQ Nfn1ek8jEVs49dR37NTa7iRdlEHt/caslYvZgC7khKBWDYNX8qTBLLwW3PjGOZZ8Ewuo sNuF/ZC20/LzLL3bEqqEx4KH+mauMZyP/3JUos58TkD+1V+4UUH1jkrfS56hq4ywL3jy lZRKAWEwBcbyvrCCpuENS3tlNjzWeBjle/TmnCm7OWFXHvXkuqEGXXZKLfKsYfVIpy0g Yx728ZqGIPglSmu04LASuI8oP0wVqsjUd8VphTd6wdHvZ/W79Knz0wSBMcZykx8jASrQ fVIw== 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id si15si3828586ejb.246.2020.08.31.01.52.47; Mon, 31 Aug 2020 01:53:10 -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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727992AbgHaIuQ (ORCPT + 99 others); Mon, 31 Aug 2020 04:50:16 -0400 Received: from lucky1.263xmail.com ([211.157.147.134]:44674 "EHLO lucky1.263xmail.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726102AbgHaIuQ (ORCPT ); Mon, 31 Aug 2020 04:50:16 -0400 Received: from localhost (unknown [192.168.167.209]) by lucky1.263xmail.com (Postfix) with ESMTP id A81BAC0F5B; Mon, 31 Aug 2020 16:50:12 +0800 (CST) X-MAIL-GRAY: 0 X-MAIL-DELIVERY: 1 X-ADDR-CHECKED4: 1 X-ANTISPAM-LEVEL: 2 X-ABS-CHECKED: 0 Received: from localhost.localdomain (unknown [58.22.7.114]) by smtp.263.net (postfix) whith ESMTP id P26185T140085628864256S1598863812232994_; Mon, 31 Aug 2020 16:50:13 +0800 (CST) X-IP-DOMAINF: 1 X-UNIQUE-TAG: <38ace29fd866fc80b662033f1f02473c> X-RL-SENDER: jay.xu@rock-chips.com X-SENDER: xjq@rock-chips.com X-LOGIN-NAME: jay.xu@rock-chips.com X-FST-TO: linus.walleij@linaro.org X-SENDER-IP: 58.22.7.114 X-ATTACHMENT-NUM: 0 X-DNS-TYPE: 0 X-System-Flag: 0 From: Jianqun Xu To: linus.walleij@linaro.org, heiko@sntech.de Cc: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, linux-rockchip@lists.infradead.org, Jianqun Xu Subject: [PATCH 5/6] pinctrl: rockchip: fix crash caused by invalid gpio bank Date: Mon, 31 Aug 2020 16:50:10 +0800 Message-Id: <20200831085010.7235-1-jay.xu@rock-chips.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200831084753.7115-1-jay.xu@rock-chips.com> References: <20200831084753.7115-1-jay.xu@rock-chips.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add valid check for gpio bank. Change-Id: Ia4609c3045b5df7879beab3c15d791ff54a1f49b Signed-off-by: Jianqun Xu --- drivers/pinctrl/pinctrl-rockchip.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/drivers/pinctrl/pinctrl-rockchip.c b/drivers/pinctrl/pinctrl-rockchip.c index 6080573155f6..5b16b69e311f 100644 --- a/drivers/pinctrl/pinctrl-rockchip.c +++ b/drivers/pinctrl/pinctrl-rockchip.c @@ -2526,9 +2526,9 @@ static int rockchip_pmx_set(struct pinctrl_dev *pctldev, unsigned selector, break; } - if (ret) { + if (ret && cnt) { /* revert the already done pin settings */ - for (cnt--; cnt >= 0; cnt--) + for (cnt--; cnt >= 0 && !data[cnt].func; cnt--) rockchip_set_mux(bank, pins[cnt] - bank->pin_base, 0); return ret; @@ -2599,9 +2599,13 @@ static int rockchip_pmx_gpio_set_direction(struct pinctrl_dev *pctldev, unsigned offset, bool input) { struct rockchip_pinctrl *info = pinctrl_dev_get_drvdata(pctldev); + struct rockchip_pin_bank *bank = &info->ctrl->pin_banks[offset / 32]; struct gpio_chip *chip; int pin; + if (!bank || !bank->valid) + return 0; + chip = range->gc; pin = offset - chip->base; dev_dbg(info->dev, "gpio_direction for pin %u as %s-%d to %s\n", @@ -3022,6 +3026,8 @@ static int rockchip_pinctrl_register(struct platform_device *pdev, for (bank = 0; bank < info->ctrl->nr_banks; ++bank) { pin_bank = &info->ctrl->pin_banks[bank]; + if (!pin_bank->valid) + continue; pin_bank->grange.name = pin_bank->name; pin_bank->grange.id = bank; pin_bank->grange.pin_base = pin_bank->pin_base; -- 2.17.1