pinctrl: sunxi: dt: do not accumulate npins across probe attempts
Subsystems (3)
PATCH 1/1 pinctrl: sunxi: dt: do not accumulate npins across probe attempts
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.
--- drivers/pinctrl/sunxi/pinctrl-sunxi-dt.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-)
drivers/pinctrl/sunxi/pinctrl-sunxi-dt.c +6 -4
@@ -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 );
Signature · 1 line
2.52.0
On Tue, 6 Oct 2026 22:03:13 +0100
Pablo Mazzini <[email protected]> wrote:
Hi Pablo,
Quoted 3 lines
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
Quoted 45 lines
Signed-off-by Pablo Mazzini <[email protected]>--- drivers/pinctrl/sunxi/pinctrl-sunxi-dt.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-)drivers/pinctrl/sunxi/pinctrl-sunxi-dt.c +6
-4@@ -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 );
Yes, that's simpler, thanks. Will do that in v2.
Quoted 62 lines · Andre Przywara
On Tue, 6 Oct 2026 22:03:13 +0100
Pablo Mazzini <[email protected]> wrote:Hi Pablo,
Quoted 3 lines
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->npinsto 0, at the beginning ofinit_pins_table? I think Sashiko suggested that even...Cheers,
AndreQuoted 45 lines
Signed-off-by Pablo Mazzini <[email protected]>--- drivers/pinctrl/sunxi/pinctrl-sunxi-dt.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-)drivers/pinctrl/sunxi/pinctrl-sunxi-dt.c +6
-4@@ -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 );