[PATCH] pinctrl: sunxi: dt: do not accumulate npins across probe attempts

Andre Przywara andre.przywara at arm.com
Tue Oct 6 16:23:37 PDT 2026


On Tue,  6 Oct 2026 22:03:13 +0100
Pablo Mazzini <pmazzini at gmail.com> wrote:

Hi Pablo,

> init_pins_table() adds to npins in the driver's static descriptor, so
> after a probe deferral the count doubles and the next probe fails with
> "pin 0 already registered". Count into a local instead.

Can't we just initialise desc->npins to 0, at the beginning of
init_pins_table? I think Sashiko suggested that even...

Cheers,
Andre

> 
> Signed-off-by: Pablo Mazzini <pmazzini at gmail.com>
> ---
>  drivers/pinctrl/sunxi/pinctrl-sunxi-dt.c | 10 ++++++----
>  1 file changed, 6 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/pinctrl/sunxi/pinctrl-sunxi-dt.c b/drivers/pinctrl/sunxi/pinctrl-sunxi-dt.c
> index 50a16f3bd131..1c1888394cf1 100644
> --- a/drivers/pinctrl/sunxi/pinctrl-sunxi-dt.c
> +++ b/drivers/pinctrl/sunxi/pinctrl-sunxi-dt.c
> @@ -75,7 +75,7 @@ static struct sunxi_desc_pin *init_pins_table(struct device *dev,
>  					      struct sunxi_pinctrl_desc *desc)
>  {
>  	struct sunxi_desc_pin *pins, *cur_pin;
> -	int name_size = 0;
> +	int name_size = 0, npins = 0;
>  	int port_base = desc->pin_base / PINS_PER_BANK;
>  	char *pin_names, *cur_name;
>  	int i, j;
> @@ -85,7 +85,7 @@ static struct sunxi_desc_pin *init_pins_table(struct device *dev,
>  	 * Also work out how much memory we need to store all the pin names.
>  	 */
>  	for (i = 0; i < SUNXI_PINCTRL_MAX_BANKS; i++) {
> -		desc->npins += pins_per_bank[i];
> +		npins += pins_per_bank[i];
>  		if (pins_per_bank[i] < 10) {
>  			/* 4 bytes for "PXy\0" */
>  			name_size += pins_per_bank[i] * 4;
> @@ -98,12 +98,14 @@ static struct sunxi_desc_pin *init_pins_table(struct device *dev,
>  		}
>  	}
>  
> -	if (desc->npins == 0) {
> +	if (npins == 0) {
>  		dev_err(dev, "no ports defined\n");
>  		return ERR_PTR(-EINVAL);
>  	}
>  
> -	pins = devm_kcalloc(dev, desc->npins, sizeof(*pins), GFP_KERNEL);
> +	desc->npins = npins;
> +
> +	pins = devm_kcalloc(dev, npins, sizeof(*pins), GFP_KERNEL);
>  	if (!pins)
>  		return ERR_PTR(-ENOMEM);
>  




More information about the linux-arm-kernel mailing list