Devicetree
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Fenglin Wu" <fenglin.wu@oss.qualcomm.com>
Cc: devicetree@vger.kernel.org, robh@kernel.org, conor+dt@kernel.org
Subject: Re: [PATCH v2 4/4] pinctrl: qcom: spmi-gpio: Add level-shifter function support
Date: Fri, 29 May 2026 03:15:29 +0000	[thread overview]
Message-ID: <20260529031530.676FF1F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260528-pinctrl-level-shifter-v2-4-3a6a025392bf@oss.qualcomm.com>

Thank you for your contribution! Sashiko AI review found 5 potential issue(s) to consider:
- [High] Writing the software-defined `LEVEL_SHIFTER` function index to hardware registers causes register corruption.
- [High] Out-of-bounds array access when displaying pinconf debugfs for a level-shifter pin.
- [High] Use-After-Free of level shifter resources during driver unbind due to reversed devm initialization order.
- [High] Failure to enforce mutual exclusivity between the bidirectional level shifter and physical GPIO functions.
- [Medium] Missing GET support for the newly added `qcom,1p2v-1p8v-ls-en` pin configuration.
--

commit febef2022fa1d171b552bf56874bdc04c2cb463b
Author: Fenglin Wu <fenglin.wu@oss.qualcomm.com>

pinctrl: qcom: spmi-gpio: Add level-shifter function support

This commit introduces bidirectional level shifter support for open-drain
signals. It adds a level-shifter function to the SPMI GPIO driver for specific
GPIO pairs managed via RPMh.

> diff --git a/drivers/pinctrl/qcom/pinctrl-spmi-gpio.c b/drivers/pinctrl/qcom/pinctrl-spmi-gpio.c
> index 268cfae706a82..741795ae261ef 100644
> --- a/drivers/pinctrl/qcom/pinctrl-spmi-gpio.c
> +++ b/drivers/pinctrl/qcom/pinctrl-spmi-gpio.c
> @@ -137,6 +144,7 @@ enum pmic_gpio_func_index {
>  	PMIC_GPIO_FUNC_INDEX_DTEST2,
>  	PMIC_GPIO_FUNC_INDEX_DTEST3,
>  	PMIC_GPIO_FUNC_INDEX_DTEST4,
> +	PMIC_GPIO_FUNC_INDEX_LEVEL_SHIFTER,
>  };

[ ... ]

> @@ -183,25 +191,86 @@ struct pmic_gpio_state {
>  	{"qcom,analog-pass",		PMIC_GPIO_CONF_ANALOG_PASS,	0},
> -	{"qcom,dtest-buffer",           PMIC_GPIO_CONF_DTEST_BUFFER,    0},
> +	{"qcom,dtest-buffer",		PMIC_GPIO_CONF_DTEST_BUFFER,	0},
> +	{"qcom,1p2v-1p8v-ls-en",	PMIC_GPIO_CONF_LS_ENABLE,	0},
>  };

[Severity: Medium]
Since this commit adds the PMIC_GPIO_CONF_LS_ENABLE property and handles it
in pmic_gpio_pinconf_group_set(), does it also need corresponding read
support?

The driver uses generic pinconf dumps but lacks a pin_config_group_get
implementation, and pmic_gpio_pinconf_pin_get() lacks a case for the new
parameter. This appears to break the symmetry of the pinctrl API, which
might cause programmatic reads of this configuration to fail with -EINVAL.

[ ... ]

> @@ -214,16 +283,16 @@ static const char *const pmic_gpio_groups[] = {
>  };
>  
>  static const char *const pmic_gpio_functions[] = {
> -	[PMIC_GPIO_FUNC_INDEX_NORMAL]	= PMIC_GPIO_FUNC_NORMAL,
> -	[PMIC_GPIO_FUNC_INDEX_PAIRED]	= PMIC_GPIO_FUNC_PAIRED,
> -	[PMIC_GPIO_FUNC_INDEX_FUNC1]	= PMIC_GPIO_FUNC_FUNC1,
> -	[PMIC_GPIO_FUNC_INDEX_FUNC2]	= PMIC_GPIO_FUNC_FUNC2,
> -	[PMIC_GPIO_FUNC_INDEX_FUNC3]	= PMIC_GPIO_FUNC_FUNC3,
> -	[PMIC_GPIO_FUNC_INDEX_FUNC4]	= PMIC_GPIO_FUNC_FUNC4,
> -	[PMIC_GPIO_FUNC_INDEX_DTEST1]	= PMIC_GPIO_FUNC_DTEST1,
> -	[PMIC_GPIO_FUNC_INDEX_DTEST2]	= PMIC_GPIO_FUNC_DTEST2,
> -	[PMIC_GPIO_FUNC_INDEX_DTEST3]	= PMIC_GPIO_FUNC_DTEST3,
> -	[PMIC_GPIO_FUNC_INDEX_DTEST4]	= PMIC_GPIO_FUNC_DTEST4,
> +	[PMIC_GPIO_FUNC_INDEX_NORMAL]		= PMIC_GPIO_FUNC_NORMAL,
> +	[PMIC_GPIO_FUNC_INDEX_PAIRED]		= PMIC_GPIO_FUNC_PAIRED,
> +	[PMIC_GPIO_FUNC_INDEX_FUNC1]		= PMIC_GPIO_FUNC_FUNC1,
> +	[PMIC_GPIO_FUNC_INDEX_FUNC2]		= PMIC_GPIO_FUNC_FUNC2,
> +	[PMIC_GPIO_FUNC_INDEX_FUNC3]		= PMIC_GPIO_FUNC_FUNC3,
> +	[PMIC_GPIO_FUNC_INDEX_FUNC4]		= PMIC_GPIO_FUNC_FUNC4,
> +	[PMIC_GPIO_FUNC_INDEX_DTEST1]		= PMIC_GPIO_FUNC_DTEST1,
> +	[PMIC_GPIO_FUNC_INDEX_DTEST2]		= PMIC_GPIO_FUNC_DTEST2,
> +	[PMIC_GPIO_FUNC_INDEX_DTEST3]		= PMIC_GPIO_FUNC_DTEST3,
> +	[PMIC_GPIO_FUNC_INDEX_DTEST4]		= PMIC_GPIO_FUNC_DTEST4,
>  };

[Severity: High]
Should PMIC_GPIO_FUNC_INDEX_LEVEL_SHIFTER be added to this array?

If pmic_gpio_pinconf_pin_dbg_show() formats the status of a level-shifter
pin, it dereferences pmic_gpio_functions[function]. For a level-shifter
pin, this would be index 10 (or potentially 12 for non-LV/MV pins), while
the array only has 10 elements.

Could this cause an out-of-bounds memory access that crashes the kernel when
reading pinctrl debugfs?

[ ... ]

> @@ -513,7 +639,8 @@ static int pmic_gpio_pinconf_pin_set(struct pinctrl_dev *pctldev,
>  
>  	pad = pctldev->desc->pins[pin].drv_data;
>  
> -	pad->is_enabled = true;
> +	if (pad->function != PMIC_GPIO_FUNC_INDEX_LEVEL_SHIFTER)
> +		pad->is_enabled = true;

[Severity: High]
The commit message states that the level shifter must be mutually exclusive
with all existing functions and configurations. However, does this code
enforce that exclusivity?

If a device tree simultaneously assigns a normal function to a pin and
enables the level shifter on its associated group, pad->function will be
NORMAL.

Since the check above will pass, it will set pad->is_enabled = true,
potentially causing both the physical GPIO output buffer and the external
level shifter to drive the pin concurrently. Could this result in
electrical overstress?

[Severity: High]
Is there a risk of corrupting hardware registers with the LEVEL_SHIFTER
index?

When setting PMIC_GPIO_REG_MODE_CTL for non-LV/MV pins later in
pmic_gpio_pinconf_pin_set(), the driver does this:

        val = val << PMIC_GPIO_REG_MODE_DIR_SHIFT;
        val |= pad->function << PMIC_GPIO_REG_MODE_FUNCTION_SHIFT;

If pad->function is PMIC_GPIO_FUNC_INDEX_LEVEL_SHIFTER (10, 0b1010),
shifting it by 1 results in 20 (0x14). Since the hardware function field is
only 3 bits, this overflows and overwrites bit 4
(PMIC_GPIO_REG_MODE_DIR_SHIFT).

Since LEVEL_SHIFTER is a software-defined pseudo-function that physically
operates by keeping the pad disabled, should the driver explicitly bypass
hardware register writes for level-shifter pins?

[ ... ]

> @@ -1285,6 +1545,15 @@ static int pmic_gpio_probe(struct platform_device *pdev)
>  		}
>  	}
>  
> +	/* Register level-shifter groups and function if hardware and DT both opt in */
> +	if (hw_data->ls_config && hw_data->num_ls &&
> +	    of_property_present(dev->of_node, "qcom,rpmh") &&
> +	    of_property_present(dev->of_node, "qcom,pmic-id")) {
> +		ret = pmic_gpio_register_level_shifters(state, hw_data);
> +		if (ret < 0)
> +			return ret;
> +	}

[Severity: High]
Will this devres allocation order cause a Use-After-Free during driver
unbind?

Earlier in pmic_gpio_probe(), devm_pinctrl_register_and_init() is called to
register the pinctrl device. Then, pmic_gpio_register_level_shifters()
allocates the level shifter resources (ls_group_data, ls_group_names) using
devm_kcalloc and devm_kzalloc.

Because devres releases resources in LIFO order, the level shifter memory
will be freed before the pinctrl device is unregistered. Does this leave a
window where the pinctrl device remains active and exposed to userspace
(e.g. sysfs/debugfs) while its registered groups and functions point to
freed memory?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260528-pinctrl-level-shifter-v2-0-3a6a025392bf@oss.qualcomm.com?part=4

  reply	other threads:[~2026-05-29  3:15 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-29  1:05 [PATCH v2 0/4] pinctrl: qcom: spmi-gpio: Add bidirectional level-shifter function support Fenglin Wu
2026-05-29  1:05 ` [PATCH v2 1/4] soc: qcom: rpmh: Allow non-child devices to issue write commands Fenglin Wu
2026-05-29  1:45   ` sashiko-bot
2026-05-29  1:05 ` [PATCH v2 2/4] dt-bindings: pinctrl: qcom,pmic-gpio: Add level-shifter function Fenglin Wu
2026-05-29  2:01   ` sashiko-bot
2026-05-29  1:05 ` [PATCH v2 3/4] pinctrl: qcom: spmi-gpio: Rearchitect for flexible group support Fenglin Wu
2026-05-29  1:05 ` [PATCH v2 4/4] pinctrl: qcom: spmi-gpio: Add level-shifter function support Fenglin Wu
2026-05-29  3:15   ` sashiko-bot [this message]
2026-05-29 20:25 ` [PATCH v2 0/4] pinctrl: qcom: spmi-gpio: Add bidirectional " Linus Walleij

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260529031530.676FF1F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=fenglin.wu@oss.qualcomm.com \
    --cc=robh@kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox