From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.167.49 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796479337; b=22G5wRcCNfLAjjgK7kJVW5W+TAvHicQxTXOR+jhYEaiz1vkdJMJLn0sAVVKWIjJfNQTo L8YvMIhfeD/3uJQ2KYC77YloXajDv5GPDYmU4T6VUDsRqEowdWkHM64WjGUkWem7uKzoO HT8UXpueAx5qcy+C2FKdRJIkDGFnS7/9GlBgcwKL2vPFh9zjRcen+FaEJdIdt+j+JP5xx bwYRO2CAzLP8WZrDFGzHEcPZE7bX8lBLNy6FQB63SNjQ/Gi4yVYFz92CDZypP0hSnat6t di0aisrWpWSpT9HH6x7Q8NuLDv82dD3jhxRSgaVW+zrEOZcI/CzmmUbbyVeFMPYRIKg== 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=zLvPwanQGh15WsDrMhwB6SDphVIp3KiUONYCQfHUwhQxLU+5bhc1QOogVOCSGdDw+P3r aX+Ftaf70A+gCvVVnlCXr+eQakVoSorsh+aHSryqfpIc8zCs2qgInfl/05Xd9XpbAg85+ pD814CBJnyjNr3YByaanlszbVgbd+eJqdQ7wJmGZkc5aJzNg6lueAhstq4AxPM4IDemDG UHLf/+mI1zJA0DMKUhn2U5w4+L8/mbN+McgiHw1vlGOOjm00sOdsfmC+oAPT5WQ/d4vJP exHOpZ+YEFlMbPGQRsh4obkNlytXGxqeqncNvtzyLoPYVY14oAziQliQP+WYEmZwqIA== 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.167.49 Received: from mail-lf1-f49.google.com (mail-lf1-f49.google.com [209.85.167.49]) (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 BFC5B606A32F for ; Sat, 5 Dec 2026 14:02:16 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org BFC5B606A32F 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-lf1-f49.google.com with SMTP id 2adb3069b0e04-5c1479a959aso1600263e87.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=dK5XoXFf7OM4LlEyUqt2cCeoKl31EBsoXcba+i1J9f2xGOc1I71bpnHeqIJDs9P0Wq FjsqboLxX+Wc/Zl3hSGHiLZn2TkyEiY3pU53uP7ttHEZholeHJojve74E2Q6vO+SIMmL tic9Q69KWL18MxfHhK/jQ2IUuT805IiZRsWJbQF5dybYoRyc+QJU/Eu3LXzuW4ToNEaK g3sXHTtA7E8tnwMSrjTWutY9u08mLLx/0CQooBCWHbpGBC2FllVkOR8kZG5jTA+EVC7s 8Pu8pL5puaiZL1u75R6N1vzhniy3gA07z2PUCtHN/OwxtJxVN7JskPD3Rc39PEkWyR4T y8Dg== X-Forwarded-Encrypted: i=1; AL+hErGi5H8LnlH7sYyo0OtXG3AjNfv90AXNyBIJ7KkTWNDKWzhi17ILLnhJkhlfy6ak0ssYwiqshRbX/upB22lM@vger.kernel.org X-Gm-Message-State: AB4q+uHb+/5+2I8IJnZandq+2e1lDczTimHtqdLUStdxTGWm/e/gtRia YqxZ4KBOoleuGnnXnVumptY6+5MWSO8SGDM0/tDNJJVf7x4YOmA4eBDi X-Gm-Gg: AZFdTZdtBnz0+HsaJb6gHbRdpkTYfIUMOBAry1/2WGKJGJWlrXMHE+RSiUK9dGYdK+D bl77pq/pJMIveURu/xh6Zq42cW89u5erH6WTcABftxMzyadb2zf+gPzWwhUki7Ui6XrlGJSe+rZ uzrtDSi8H8eS5GhK4tSpfWR4Xt26DvoXyVuyQXcfL9kSo4yl9R0XZjCGnQTJY6wH37ehCekeShr jNrx0+vxhHTPYL3CDMzxEIXw8BDwt9wqnVNfrClUCrP0HCeCxeJxR3W26mLe1HLXSFgP+gxnpqd NC9dKLxC5fyLb45l0oh29Bb3mZ8y0K4+h9EbkyN0xp3gtOXhkN/sWz+4uCb/Nh4ROd7pRJq4g21 mQcxORThf9qwChZVKfDJNgoj2fPXhHSriC4QZe5ToBGwfjw+jaKLXZzYVQVctN95RrYc4QwjcM9 GhV4o35O1WiWsFlZzOp86J9WsGq+31i8p4ovuhJwkZOuiooz7a3ua8ftUw1sCFqpM7y26Ggl9gc CCbmyVq99suJZsYmRtIVzWIRqzpUwcxnwhxkUBbTf51Vpx3zrP25SZirpgayJqiV4SGJI5qhv0m YnjhJsglxzTbiXtqHDZdCp8vYwVhfw03jdqAUeQev6/o1Lr4isU17DTWAJDJUc+ieL4gl3l2i5m Q5OhUzqW86+813EB25ZD52XfkDj7eY7JtDzcXEOl8knYMkgfA+bdXZ/cQCluAR3ZEHylhjJUkv4 1Y3To9MlBGD42voBrOawYS8Dh5CzPUOCk= 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-arm-msm@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