From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.208.172 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796479337; b=3ZOBGw1AsX5Q5hUYi4XInlcCTXC50IdodgQeYdt6lINYg++A77Ndonzc5uvS9s02NEj1 GdLEmI44Knor1m2l0SlFZgJoB4m1wIUZSM4N16Rq0NSPqiGUe2si3LtALpb0bA4mztBcN 5XZWQrA+UodkmTkY9eveN0pYlznSF4vu07PIl/OGuDmhj6kSqXhKWhJM/GK8Sy1F4lAqu OppolzTUy9mD/p0bKV0PnrAGk0AYQzBaZXUXOD+u4uFd4K524E0ZJi6P/l6ZMUcVEaEnb zG6ZVY+wCcSz60IUyLxq5ySR7xiEGBTiM1PoDNeDPSlfVV4DMf8EZuV1cVNIC1bVJ9g== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796479337; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: From:To:Cc:Subject:Date:Message-ID:X-Mailer:MIME-Version: Content-Transfer-Encoding; bh=+42IFKvBPtWmX1d2jHsRZZp7NiH4I3hS2WqrUTbGVD4=; b=k2LmuGcDRO/jTETTtJkfiwGS+Ve7HHDzN64R6FlXXm/I12M7xlQHH+5DTvEqlsjVdmzZ CPBUi69VrBHS5RX7PPt5cpWutgKmQTXnkEWbZ4VYRT13fOi0yrmkAJccTIBhinGzsH9pu euuYxkTIaFrP+Ma9WwOFuIMyObpanPiaIa1eNYiih9HkG3AeQtUKMBxf3g0cjfkXJ606D 8cPWkCEHI4nzVqAqXKwXrZ79cy6eH+vRhE1Noq3PudYIhX05SH+vN6ileZDPyTt0tlZIK XJZN5vDJtYtAzjxcnl/xgSG9ux7jGaUGs0Rc8km8KZiHBIT4bXBChb7xla5bWHRnluQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=P4kogHam; arc=none smtp.remote-ip=209.85.208.172 Received: from mail-lj1-f172.google.com (mail-lj1-f172.google.com [209.85.208.172]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D1F58606A330 for ; Sat, 5 Dec 2026 14:02:16 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org D1F58606A330 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=P4kogHam Received: by mail-lj1-f172.google.com with SMTP id 38308e7fff4ca-3ad5529ae64so14492991fa.2 for ; Sat, 05 Dec 2026 06:02:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796479335; x=1797084135; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to:content-type; bh=+42IFKvBPtWmX1d2jHsRZZp7NiH4I3hS2WqrUTbGVD4=; b=P4kogHamyHWYQuyHOA60r+ek+GUg2xpasD0rD2AsXbcYn25P8KXq4uUYWoWoXaPNUO ryYuhprlsCVclsq5z7G/Mjj6yfr3QcEBIUkKAXs7dwroGTW8nxXbaGDs7/4B7t+yfsql EjyrX0bwMGSTHRxVHsi0LKeKYxaOC7iPzYEsLG5BcmAAGcYqyrRJjL3A3vMfzmXeOM8B zyv9diCKSGtbKkh0wQOgRhUM36t6lefyEdthPi8A3EUF1v9pucLV2ymB2S3Fnd42Ajc9 FFjNxhTQ4aOLvHYhtB5GrDZXmPwTpjnneIGw580Ezrffk539e6r7NOUkkON98np64XfY PcAQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796479335; x=1797084135; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=+42IFKvBPtWmX1d2jHsRZZp7NiH4I3hS2WqrUTbGVD4=; b=HV7Cqddtfcev8p5mSqzo/b1sptydAMMDVcIglsY5iuAgboq64zgbPOoyMSrm8/vOeu 4F4szsJmw1U7d32+ocqE+ngycBqLns86bJr1hk6NFO/40IoZzT1BtU07iWowpntEofmh NWfpQABiW107QozW4WIxqMGDajvnXOagZ4eOm310E9bOeYeTebU7BXux8N3LK1YDmLXP qSoxqslVAQyIi5g5+T5LmiELtgBsmmUwTTIf9dSpoIr+UQz564XIR/Bk681TS8yhLAiz esuOaX7u1qqg9GNgFcpHWXi9t+hOnIn9wVsTTQY1nMfblgKu1kU7V77FYMls6uAkWDdf eAaQ== X-Forwarded-Encrypted: i=1; AL+hErFsob1tYmqRsePwQW+VwtgdRXuKOl4bDa8sUOKPObUSNUhdqoljviNepnNMbgJikEBUYJR1GK8KLQ7O@vger.kernel.org X-Gm-Message-State: AB4q+uHaoyXsTjbmnpYlR6r+6GvPGxotpppd2bEYCDnthhxi6WARQfio JaoM2hPOaIV7cjuz10EpzsjzYkGVAU+2+Kcnr1JmDBgexGdzrfzXEMlx X-Gm-Gg: AZFdTZfAuNBnvhKl7tqQplcKadjBxSwXq2jdiqjiim7zuzMHhEL7Kp/Kl1t6SZDWMFz o5+zsrTGIWzfXdJ2dv7yud+zKUC8v/1TXxN938SftrVk4PcIrysSqTg9Rh2LDIkpQuOnzVWYKly wt+/QrOhk1z2bZ0mOmmqHdZt8acayjo3ce82uCDFgiPR3dfBLvMZxu7JT0puiFtGSrtiBtQU8um SIYBX0gusZ6JbeaPpjeAhIXOsn+Wr6FJpwU88cXkASUYcheoXhxX07qRP8XkyEBX18f2F9MWDcF iM230lM0CQtgERw5izIZM2frul5AtKUuhlzGz4BkpY6Fi/HLtOqbvZXellCJwM6HmDDRAH2qVNu +olC4qaC1OgEKIy8esSAv0+P26qZPle0UQllTOyxy2MDeiuLDiVCFy7bE/SSPst7sliKuPRMsgO XMmU0G3d2+UBIr1GoSA11aWdJXGiW/6h8GpfHjO0di3F1YeAzVaDFrU2Rqgp9LXLwxkXS1qm1W9 ldJ+W+upZIbWFHtrhXeOHo7GrvMJ9M1SsAbfOhp45Q5sOp7ayGdVqxaUazE5es8EXkoPqkb0jak tDfpK0Y2rAcfAC5d2iHTOlIVx9j5jRTZzKVJjODl8hCErYWiJn9wDen0WEbwIw39tSklLkLM8fo myBmAK5B5ft8djkbZKu6S8c4ji9sNXR0smNEz9DBISGdCkD+a5OpXAaq76Tt3FzeUNg3Fwbtm4S wM9EobONptn+5vH6yVewfRm5IQ1UXLzVk= X-Received: by 2002:ac2:4c47:0:b0:5c3:3b88:33bb with SMTP id 2adb3069b0e04-5c385f30fedmr1439742e87.4.1796479334659; Sat, 05 Dec 2026 06:02:14 -0800 (PST) Received: from kompukter-Systems ([193.25.177.41]) by smtp.gmail.com with ESMTPSA id 38308e7fff4ca-3b0192ee960sm2346211fa.16.2026.12.05.06.02.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 05 Dec 2026 06:02:13 -0800 (PST) From: Andrey Derkach To: Bjorn Andersson , Bartosz Golaszewski , Linus Walleij Cc: Richard Acayan , linux-arm-msm@vger.kernel.org, linux-gpio@vger.kernel.org Subject: [PATCH v2] pinctrl: qcom: lpass-lpi: Don't touch reserved pins Date: Sat, 5 Dec 2026 16:02:00 +0200 Message-ID: <20261205140200.1120850-1-gabin278@gmail.com> X-Mailer: git-send-email 2.53.0 X-Mailing-List: linux-gpio@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Since commit a22d2598a563 ("dt-bindings: qcom: lpass-lpi-common: add reserved GPIOs property") an LPI pin controller can have gpio-reserved-ranges. On SDM670 phones such as the Pixel 3a these are the sensor pins, which the firmware protects: reading their registers hangs the bus and freezes the SoC. gpiolib leaves reserved lines alone, but the LPI driver still reads them from the GPIO debugfs dump and from the pinconf-groups debugfs file, and pinmux does not refuse to mux them. Do what pinctrl-msm does since commit 691bf5d5a7bf ("pinctrl: qcom: Don't allow protected pins to be requested") and commit 27030ff78772 ("pinctrl: qcom: fail to retrieve configuration from invalid pin groups"): refuse pinmux requests for reserved pins, fail pinconf reads of them and leave them out of the GPIO debugfs dump. Unlike pinctrl-msm, keep the reserved pins in a bitmap of the driver's own, filled from gpio-reserved-ranges before the pin controller is registered. The pin controller is registered before the GPIO chip is added and unregistered after it is removed. Before the GPIO chip is added, gpiochip_line_is_valid() treats every pin as valid, and after it is removed it uses the freed GPIO device. Tested on the Xiaomi Mi 9 SE (SDM712), which reserves <0 18>, <26 6>: without this change reading /sys/kernel/debug/gpio freezes the SoC; with it the dump lists only GPIOs 18-25, and pinconf-groups shows the reserved groups without configs. Signed-off-by: Andrey Derkach --- Changes in v2: - Keep the reserved pins in a bitmap of the driver's own instead of calling gpiochip_line_is_valid(), which does not cover the pin controller before the GPIO chip is added or after it is removed. - Link to v1: https://patchwork.kernel.org/series/1232885/ Writing the pinctrl "pinmux-select" debugfs file calls .set_mux without .request, so it can still mux a reserved group. pinctrl-msm has the same gap; this patch leaves it alone. drivers/pinctrl/qcom/pinctrl-lpass-lpi.c | 58 ++++++++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/drivers/pinctrl/qcom/pinctrl-lpass-lpi.c b/drivers/pinctrl/qcom/pinctrl-lpass-lpi.c index f693e5101a7b..e93a5a48c43e 100644 --- a/drivers/pinctrl/qcom/pinctrl-lpass-lpi.c +++ b/drivers/pinctrl/qcom/pinctrl-lpass-lpi.c @@ -10,6 +10,7 @@ #include #include #include +#include #include #include @@ -36,6 +37,8 @@ struct lpi_pinctrl { /* Protects from concurrent register updates */ struct mutex lock; DECLARE_BITMAP(ever_gpio, MAX_NR_GPIO); + /* Pins in gpio-reserved-ranges, possibly protected by the firmware */ + DECLARE_BITMAP(reserved, MAX_NR_GPIO); const struct lpi_pinctrl_variant_data *data; }; @@ -171,7 +174,15 @@ static int lpi_gpio_set_mux(struct pinctrl_dev *pctldev, unsigned int function, return 0; } +static int lpi_gpio_request(struct pinctrl_dev *pctldev, unsigned int offset) +{ + struct lpi_pinctrl *pctrl = pinctrl_dev_get_drvdata(pctldev); + + return test_bit(offset, pctrl->reserved) ? -EINVAL : 0; +} + static const struct pinmux_ops lpi_gpio_pinmux_ops = { + .request = lpi_gpio_request, .get_functions_count = lpi_gpio_get_functions_count, .get_function_name = lpi_gpio_get_function_name, .get_function_groups = lpi_gpio_get_function_groups, @@ -189,6 +200,10 @@ static int lpi_config_get(struct pinctrl_dev *pctldev, int pull; int ret; + /* Reserved pins may be protected, reading them can hang the bus */ + if (test_bit(pin, state->reserved)) + return -EINVAL; + ret = lpi_gpio_read(state, pin, LPI_GPIO_CFG_REG, &ctl_reg); if (ret) return ret; @@ -462,10 +477,14 @@ static void lpi_gpio_dbg_show_one(struct seq_file *s, static void lpi_gpio_dbg_show(struct seq_file *s, struct gpio_chip *chip) { + struct lpi_pinctrl *pctrl = gpiochip_get_data(chip); unsigned int gpio = chip->base; unsigned int i; for (i = 0; i < chip->ngpio; i++, gpio++) { + if (test_bit(i, pctrl->reserved)) + continue; + lpi_gpio_dbg_show_one(s, NULL, chip, i, gpio); seq_puts(s, "\n"); } @@ -486,6 +505,41 @@ static const struct gpio_chip lpi_gpio_template = { .dbg_show = lpi_gpio_dbg_show, }; +/* + * gpiolib applies gpio-reserved-ranges to the GPIO chip's valid mask, but + * the GPIO chip is added after the pin controller is registered and + * removed before it is unregistered, so keep a copy for the pin controller. + */ +static int lpi_init_reserved_pins(struct lpi_pinctrl *pctrl) +{ + unsigned int npins = pctrl->data->npins; + int count, i, ret; + + count = device_property_count_u32(pctrl->dev, "gpio-reserved-ranges"); + if (count <= 0 || count % 2) + return 0; + + u32 *ranges __free(kfree) = kcalloc(count, sizeof(*ranges), GFP_KERNEL); + if (!ranges) + return -ENOMEM; + + ret = device_property_read_u32_array(pctrl->dev, "gpio-reserved-ranges", + ranges, count); + if (ret) + return ret; + + for (i = 0; i < count; i += 2) { + u32 start = ranges[i], len = ranges[i + 1]; + + if (start >= npins || len > npins - start) + continue; + + bitmap_set(pctrl->reserved, start, len); + } + + return 0; +} + static int lpi_build_pin_desc_groups(struct lpi_pinctrl *pctrl) { int i, ret; @@ -531,6 +585,10 @@ int lpi_pinctrl_probe(struct platform_device *pdev) pctrl->data = data; pctrl->dev = &pdev->dev; + ret = lpi_init_reserved_pins(pctrl); + if (ret) + return ret; + pctrl->tlmm_base = devm_platform_ioremap_resource(pdev, 0); if (IS_ERR(pctrl->tlmm_base)) return dev_err_probe(dev, PTR_ERR(pctrl->tlmm_base), base-commit: 29beb21c21ada7207692b2d69fc58dcd15dab6e9 -- 2.53.0