sh-pfc: handle pin array holes in sh_pfc_map_pins()
PATCH 1/1 sh-pfc: handle pin array holes in sh_pfc_map_pins()
The pin array handled by sh_pfc_map_pins() may contain holes representing non- existing pins. We have to first count the valid pins in order to calculate the
size of the memory to be allocated, then to skip over the non-existing pins when initializing the allocated arrays, and then to return the number of valid pins from sh_pfc_map_pins() instead of 0 on success.
As we have to touch devm_kzalloc() calls anyway, use more fitting devm_kcalloc() instead which additionally checks the array size. And since PINMUX_TYPE_NONE is #define'd as 0, stop re-initializing already zeroed out 'pmx->configs' array.
---
The patch is against the 'devel' branch of Linus W.'s 'linux-pinctrl.git' repo. This patch should be applied before my R8A7794 PFC support patch and before Laurent's patches removing non-existent GPIOs for R8A779[01], otherwise they would cause the kernel to hang while booting!
drivers/pinctrl/sh-pfc/pinctrl.c | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-)
Index: linux-pinctrl/drivers/pinctrl/sh-pfc/pinctrl.c =================================--- linux-pinctrl.orig/drivers/pinctrl/sh-pfc/pinctrl.c +++ linux-pinctrl/drivers/pinctrl/sh-pfc/pinctrl.c
@@ -571,33 +571,39 @@ static const struct pinconf_ops sh_pfc_p
/* PFC ranges -> pinctrl pin descs */
static int sh_pfc_map_pins(struct sh_pfc *pfc, struct sh_pfc_pinctrl *pmx) {
- unsigned int i;
+ const struct sh_pfc_pin *info;
+ struct pinctrl_pin_desc *pin;
+ unsigned int i, n;
+
+ /* Count the valid pins. */
+ for (i = 0, info = pfc->info->pins, n = 0;
+ i < pfc->info->nr_pins; i++, info++) {
+ if (info->enum_id || info->configs)
+ n++;
+ }
/* Allocate and initialize the pins and configs arrays. */
- pmx->pins = devm_kzalloc(pfc->dev,
- sizeof(*pmx->pins) * pfc->info->nr_pins,
- GFP_KERNEL);
+ pmx->pins = devm_kcalloc(pfc->dev, n, sizeof(*pmx->pins), GFP_KERNEL);
if (unlikely(!pmx->pins))
return -ENOMEM;
- pmx->configs = devm_kzalloc(pfc->dev,
- sizeof(*pmx->configs) * pfc->info->nr_pins,
+ pmx->configs = devm_kcalloc(pfc->dev, n, sizeof(*pmx->configs),
GFP_KERNEL);
if (unlikely(!pmx->configs))
return -ENOMEM;
- for (i = 0; i < pfc->info->nr_pins; ++i) {
- const struct sh_pfc_pin *info = &pfc->info->pins[i];
- struct sh_pfc_pin_config *cfg = &pmx->configs[i];
- struct pinctrl_pin_desc *pin = &pmx->pins[i];
+ for (i = 0, info = pfc->info->pins, pin = pmx->pins;
+ i < pfc->info->nr_pins; i++, info++) {
+ if (!info->enum_id && !info->configs)
+ continue;
/* If the pin number is equal to -1 all pins are considered */ pin->number = info->pin != (u16)-1 ? info->pin : i; pin->name = info->name;
- cfg->type = PINMUX_TYPE_NONE;
+ pin++;
}
- return 0;
+ return n;
}
int sh_pfc_register_pinctrl(struct sh_pfc *pfc)
@@ -622,7 +628,7 @@ int sh_pfc_register_pinctrl(struct sh_pf
pmx->pctl_desc.pmxops = &sh_pfc_pinmux_ops; pmx->pctl_desc.confops = &sh_pfc_pinconf_ops; pmx->pctl_desc.pins = pmx->pins;
- pmx->pctl_desc.npins = pfc->info->nr_pins;
+ pmx->pctl_desc.npins = ret;
pmx->pctl = pinctrl_register(&pmx->pctl_desc, pfc->dev, pmx); if (pmx->pctl = NULL)
Hi Sergei,
Thank you for the patch.
Quoted 11 lines · On Saturday 28 February 2015 02:39:19 Sergei Shtylyov wrote:
The pin array handled by
sh_pfc_map_pins()may contain holes representing non- existing pins. We have to first count the valid pins in order to calculate the size of the memory to be allocated, then to skip over the non-existing pins when initializing the allocated arrays, and then to return the number of valid pins fromsh_pfc_map_pins()instead of 0 on success.As we have to touch
devm_kzalloc()calls anyway, use more fittingdevm_kcalloc()instead which additionally checks the array size. And sincePINMUX_TYPE_NONEis #define'd as 0, stop re-initializing already zeroed out 'pmx->configs' array.
I agree with this optimization, but I think it deserves a comment in the source code that explicitly mentions PINMUX_TYPE_NONE, to make sure any later rework changing the PINMUX_TYPE_NONE value would catch this.
Quoted 15 lines
Signed-off-by Sergei Shtylyov <[email protected]>---
The patch is against the 'devel' branch of Linus W.'s 'linux-pinctrl.git' repo. This patch should be applied before my R8A7794 PFC support patch and before Laurent's patches removing non-existent GPIOs for R8A779[01], otherwise they would cause the kernel to hang while booting!drivers/pinctrl/sh-pfc/pinctrl.c | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-)Index:
linux-pinctrl/drivers/pinctrl/sh-pfc/pinctrl.c=================================> ---linux-pinctrl.orig/drivers/pinctrl/sh-pfc/pinctrl.c+++linux-pinctrl/drivers/pinctrl/sh-pfc/pinctrl.c
Review static const struct pinconf_ops sh_pfc_p · line 576
Quoted 7 lines
(quoted diff) +3
-1@@ -571,33 +571,39 @@ static const struct pinconf_ops sh_pfc_p /* PFC ranges -> pinctrl pin descs */ static int sh_pfc_map_pins(struct sh_pfc *pfc, struct sh_pfc_pinctrl *pmx) { - unsigned int i; + const struct sh_pfc_pin *info; + struct pinctrl_pin_desc *pin; + unsigned int i, n;
Could you please rename n to num_pins, and declare it on its own line to match the coding style of the file ?
Review static const struct pinconf_ops sh_pfc_p · line 581
Quoted 5 lines
(quoted diff) +5
-0+ + /* Count the valid pins. */ + for (i = 0, info = pfc->info->pins, n = 0; + i < pfc->info->nr_pins; i++, info++) { + if (info->enum_id || info->configs)
Why do you need to test info->configs as well ? I thought enum_id = 0 is always reserved, am I getting it wrong ?
Quoted 14 lines
(quoted diff) +4
-5+ n++; + } /* Allocate and initialize the pins and configs arrays. */ - pmx->pins = devm_kzalloc(pfc->dev, - sizeof(*pmx->pins) * pfc->info->nr_pins, - GFP_KERNEL); + pmx->pins = devm_kcalloc(pfc->dev, n, sizeof(*pmx->pins), GFP_KERNEL); if (unlikely(!pmx->pins)) return -ENOMEM; - pmx->configs = devm_kzalloc(pfc->dev, - sizeof(*pmx->configs) * pfc->info->nr_pins, + pmx->configs = devm_kcalloc(pfc->dev, n, sizeof(*pmx->configs),
Review static const struct pinconf_ops sh_pfc_p · line 596
Quoted 10 lines
(quoted diff) +2
-4GFP_KERNEL); if (unlikely(!pmx->configs)) return -ENOMEM; - for (i = 0; i < pfc->info->nr_pins; ++i) { - const struct sh_pfc_pin *info = &pfc->info->pins[i]; - struct sh_pfc_pin_config *cfg = &pmx->configs[i]; - struct pinctrl_pin_desc *pin = &pmx->pins[i]; + for (i = 0, info = pfc->info->pins, pin = pmx->pins; + i < pfc->info->nr_pins; i++, info++) {
I would keep info as a local variable to avoid splitting the for () on multiple lines. Same comment for the counter loop above.
Quoted 16 lines
(quoted diff) +4
-2+ if (!info->enum_id && !info->configs) + continue; /* If the pin number is equal to -1 all pins are considered */ pin->number = info->pin != (u16)-1 ? info->pin : i; pin->name = info->name; - cfg->type = PINMUX_TYPE_NONE; + pin++; } - return 0; + return n; } int sh_pfc_register_pinctrl(struct sh_pfc *pfc)
Review int sh_pfc_register_pinctrl(struct sh_pf · line 634
Quoted 8 lines
(quoted diff) +1
-1@@ -622,7 +628,7 @@ int sh_pfc_register_pinctrl(struct sh_pf pmx->pctl_desc.pmxops = &sh_pfc_pinmux_ops; pmx->pctl_desc.confops = &sh_pfc_pinconf_ops; pmx->pctl_desc.pins = pmx->pins; - pmx->pctl_desc.npins = pfc->info->nr_pins; + pmx->pctl_desc.npins = ret; pmx->pctl = pinctrl_register(&pmx->pctl_desc, pfc->dev, pmx); if (pmx->pctl = NULL)
Shouldn't you also fix sh_pfc_init_ranges() ? It includes the following code that doesn't seem to handle holes properly.
for (i = 1, nr_ranges = 1; i < pfc->info->nr_pins; ++i) {
if (pfc->info->pins[i-1].pin != pfc->info->pins[i].pin - 1)
nr_ranges++;
}Please make sure that sh_pfc_get_pin_index() doesn't start blowing up afterwards though.
Signature · 3 lines
Regards, Laurent Pinchart
Quoted 10 lines · Sergei Shtylyov
The pin array handled by
sh_pfc_map_pins()may contain holes representing non- existing pins. We have to first count the valid pins in order to calculate thesize of the memory to be allocated, then to skip over the non-existing pins when initializing the allocated arrays, and then to return the number of valid pins from sh_pfc_map_pins() instead of 0 on success.As we have to touch
devm_kzalloc()calls anyway, use more fittingdevm_kcalloc()instead which additionally checks the array size. And sincePINMUX_TYPE_NONEis #define'd as 0, stop re-initializing already zeroed out 'pmx->configs' array.
Quoted 7 lines
Signed-off-by Sergei Shtylyov <[email protected]>---
The patch is against the 'devel' branch of Linus W.'s 'linux-pinctrl.git' repo. This patch should be applied before my R8A7794 PFC support patch and before Laurent's patches removing non-existent GPIOs for R8A779[01], otherwise they would cause the kernel to hang while booting!
OK not applying this until ACKed by Laurent,
and in the meantime I'm taking the three applied R8A7794 patches out of my tree again.
Can you please send these depending patches as a series with this patch as 1/4 and the three R8A7794 patches as 2,3,4/4? Thanks.
Yours,
Linus Walleij
Hi Linus,
Quoted 21 lines · On Friday 06 March 2015 11:43:45 Linus Walleij wrote:
Quoted 12 lines · Sergei Shtylyov
The pin array handled by
sh_pfc_map_pins()may contain holes representing non- existing pins. We have to first count the valid pins in order to calculate the size of the memory to be allocated, then to skip over the non-existing pins when initializing the allocated arrays, and then to return the number of valid pins fromsh_pfc_map_pins()instead of 0 on success.As we have to touch
devm_kzalloc()calls anyway, use more fittingdevm_kcalloc()instead which additionally checks the array size. And sincePINMUX_TYPE_NONEis #define'd as 0, stop re-initializing already zeroed out 'pmx->configs' array.Quoted 7 lines
Signed-off-by Sergei Shtylyov <[email protected]>---
The patch is against the 'devel' branch of Linus W.'s 'linux-pinctrl.git' repo. This patch should be applied before my R8A7794 PFC support patch and before Laurent's patches removing non-existent GPIOs for R8A779[01], otherwise they would cause the kernel to hang while booting!
Quoted 3 lines
OK not applying this until ACKed by Laurent,
and in the meantime I'm taking the three applied R8A7794 patches out of my tree again.
Could you also drop "pinctrl: sh-pfc: r8a7790: Remove non existing GPIO pins" and "pinctrl: sh-pfc: r8a7791: Remove non existing GPIO pins" for the same reason ? Sorry for the trouble.
Quoted 2 lines
Can you please send these depending patches as a series with this patch as 1/4 and the three R8A7794 patches as 2,3,4/4? Thanks.
Signature · 3 lines
Regards, Laurent Pinchart
Quoted 18 lines · Linus Walleij
Quoted 10 lines
The pin array handled by
sh_pfc_map_pins()may contain holes representing non- existing pins. We have to first count the valid pins in order to calculate thesize of the memory to be allocated, then to skip over the non-existing pins when initializing the allocated arrays, and then to return the number of valid pins from sh_pfc_map_pins() instead of 0 on success.As we have to touch
devm_kzalloc()calls anyway, use more fittingdevm_kcalloc()instead which additionally checks the array size. And sincePINMUX_TYPE_NONEis #define'd as 0, stop re-initializing already zeroed out 'pmx->configs' array.Quoted 7 lines
Signed-off-by Sergei Shtylyov <[email protected]>---
The patch is against the 'devel' branch of Linus W.'s 'linux-pinctrl.git' repo. This patch should be applied before my R8A7794 PFC support patch and before Laurent's patches removing non-existent GPIOs for R8A779[01], otherwise they would cause the kernel to hang while booting!
Quoted 3 lines
OK not applying this until ACKed by Laurent,
and in the meantime I'm taking the three applied R8A7794 patches out of my tree again.
Thanks!
Quoted 2 lines
Can you please send these depending patches as a series with this patch as 1/4 and the three R8A7794 patches as 2,3,4/4? Thanks.
OK, will try to remember. But what about Lauren't 2 patches also dependent
on this one?
Quoted 2 lines
Yours,
Linus Walleij
WBR, Sergei
Hi Sergei,
Quoted 25 lines · On Friday 06 March 2015 15:42:05 Sergei Shtylyov wrote:
Quoted 20 lines · Linus Walleij
Quoted 12 lines
The pin array handled by
sh_pfc_map_pins()may contain holes representing non- existing pins. We have to first count the valid pins in order to calculate the size of the memory to be allocated, then to skip over the non-existing pins when initializing the allocated arrays, and then to return the number of valid pins fromsh_pfc_map_pins()instead of 0 on success.As we have to touch
devm_kzalloc()calls anyway, use more fittingdevm_kcalloc()instead which additionally checks the array size. And sincePINMUX_TYPE_NONEis #define'd as 0, stop re-initializing already zeroed out 'pmx->configs' array.Quoted 7 lines
Signed-off-by Sergei Shtylyov <[email protected]>---
The patch is against the 'devel' branch of Linus W.'s 'linux-pinctrl.git' repo. This patch should be applied before my R8A7794 PFC support patch and before Laurent's patches removing non-existent GPIOs for R8A779[01], otherwise they would cause the kernel to hang while booting!Quoted 3 lines
OK not applying this until ACKed by Laurent,
and in the meantime I'm taking the three applied R8A7794 patches out of my tree again.
Quoted 7 lines
Thanks!
Quoted 2 lines
Can you please send these depending patches as a series with this patch as 1/4 and the three R8A7794 patches as 2,3,4/4? Thanks.
OK, will try to remember. But what about Lauren't 2 patches also dependent on this one?
If you don't mind, please also include them in your series.
Signature · 3 lines
Regards, Laurent Pinchart
Quoted 24 lines · Laurent Pinchart
Hi Linus,
Quoted 21 lines · On Friday 06 March 2015 11:43:45 Linus Walleij wrote:
Quoted 19 lines · Sergei Shtylyov
The pin array handled by
sh_pfc_map_pins()may contain holes representing non- existing pins. We have to first count the valid pins in order to calculate the size of the memory to be allocated, then to skip over the non-existing pins when initializing the allocated arrays, and then to return the number of valid pins fromsh_pfc_map_pins()instead of 0 on success.As we have to touch
devm_kzalloc()calls anyway, use more fittingdevm_kcalloc()instead which additionally checks the array size. And sincePINMUX_TYPE_NONEis #define'd as 0, stop re-initializing already zeroed out 'pmx->configs' array.Signed-off-by Sergei Shtylyov <[email protected]>---
The patch is against the 'devel' branch of Linus W.'s 'linux-pinctrl.git' repo. This patch should be applied before my R8A7794 PFC support patch and before Laurent's patches removing non-existent GPIOs for R8A779[01], otherwise they would cause the kernel to hang while booting!
Quoted 7 lines
Quoted 3 lines
OK not applying this until ACKed by Laurent,
and in the meantime I'm taking the three applied R8A7794 patches out of my tree again.Could you also drop "pinctrl: sh-pfc: r8a7790: Remove non existing GPIO pins" and "pinctrl: sh-pfc: r8a7791: Remove non existing GPIO pins" for the same reason ? Sorry for the trouble.
OK dropped them (rebased .... argh hope noone will kick my ass)
Yours,
Linus Walleij
Hello.
On 03/03/2015 03:24 AM, Laurent Pinchart wrote:
Sorry for the belated reply, I was switched to EtherAVB soon after posting
this patch. :-)
Quoted 7 lines
Quoted 6 lines
The pin array handled by
sh_pfc_map_pins()may contain holes representing non- existing pins. We have to first count the valid pins in order to calculate the size of the memory to be allocated, then to skip over the non-existing pins when initializing the allocated arrays, and then to return the number of valid pins fromsh_pfc_map_pins()instead of 0 on success.
Quoted 8 lines
Quoted 4 lines
As we have to touch
devm_kzalloc()calls anyway, use more fittingdevm_kcalloc()instead which additionally checks the array size. And sincePINMUX_TYPE_NONEis #define'd as 0, stop re-initializing already zeroed out 'pmx->configs' array.I agree with this optimization, but I think it deserves a comment in the source code that explicitly mentions
PINMUX_TYPE_NONE, to make sure any later rework changing thePINMUX_TYPE_NONEvalue would catch this.
OK, will do.
Quoted 11 lines
Quoted 10 lines
Signed-off-by Sergei Shtylyov <[email protected]>---
The patch is against the 'devel' branch of Linus W.'s 'linux-pinctrl.git' repo. This patch should be applied before my R8A7794 PFC support patch and before Laurent's patches removing non-existent GPIOs for R8A779[01], otherwise they would cause the kernel to hang while booting!drivers/pinctrl/sh-pfc/pinctrl.c | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-)
Quoted 15 lines
drivers/pinctrl/sh-pfc/pinctrl.c static const struct pinconf_ops sh_pfc_p · line 576
Quoted 12 lines
Index:
linux-pinctrl/drivers/pinctrl/sh-pfc/pinctrl.c
===================================================================drivers/pinctrl/sh-pfc/pinctrl.c +3
-1@@ -571,33 +571,39 @@ static const struct pinconf_ops sh_pfc_p/* PFC ranges -> pinctrl pin descs */ static int sh_pfc_map_pins (struct sh_pfc *pfc,struct sh_pfc_pinctrl *pmx) { -unsigned int i; +const struct sh_pfc_pin *info; +struct pinctrl_pin_desc *pin; +unsigned int i, n;Could you please rename n to
num_pins, and declare it on its own line to match the coding style of the file ?
Will do.
Quoted 8 lines
drivers/pinctrl/sh-pfc/pinctrl.c static const struct pinconf_ops sh_pfc_p · line 581
Quoted 5 lines
drivers/pinctrl/sh-pfc/pinctrl.c +5
-0+ +/* Count the valid pins. */ +for (i =0 , info = pfc->info->pins, n =0 ; + i < pfc->info->nr_pins; i++, info++) { +if (info->enum_id || info->configs)Why do you need to test
info->configsas well ? I thoughtenum_id== 0 is always reserved, am I getting it wrong ?
Look at SH_PFC_PIN_NAMED() and its users.
Quoted 18 lines
Quoted 18 lines
drivers/pinctrl/sh-pfc/pinctrl.c +4
-5+ n++; + }/* Allocate and initialize the pins and configs arrays. */ - pmx->pins =devm_kzalloc (pfc->dev, -sizeof (*pmx->pins) * pfc->info->nr_pins, -GFP_KERNEL ); + pmx->pins =devm_kcalloc (pfc->dev, n,sizeof (*pmx->pins),GFP_KERNEL );if (unlikely (!pmx->pins))return -ENOMEM ; - pmx->configs =devm_kzalloc (pfc->dev, -sizeof (*pmx->configs) * pfc->info->nr_pins, + pmx->configs =devm_kcalloc (pfc->dev, n,sizeof (*pmx->configs),GFP_KERNEL );if (unlikely (!pmx->configs))return -ENOMEM ;
Quoted 9 lines
drivers/pinctrl/sh-pfc/pinctrl.c static const struct pinconf_ops sh_pfc_p · line 596
Quoted 6 lines
drivers/pinctrl/sh-pfc/pinctrl.c +2
-4-for (i =0 ; i < pfc->info->nr_pins; ++i) { -const struct sh_pfc_pin *info = &pfc->info->pins[i]; -struct sh_pfc_pin_config *cfg = &pmx->configs[i]; -struct pinctrl_pin_desc *pin = &pmx->pins[i]; +for (i =0 , info = pfc->info->pins, pin = pmx->pins; + i < pfc->info->nr_pins; i++, info++) {I would keep info as a local variable to avoid splitting the for () on multiple lines. Same comment for the counter loop above.
I don't want to declare the same variable twice, so prefer doing gcc's
work of optimizing loop induction variable myself in this case. If you insist, this can be changed...
[...]
Quoted 13 lines
drivers/pinctrl/sh-pfc/pinctrl.c int sh_pfc_register_pinctrl(struct sh_pf · line 634
Quoted 9 lines
drivers/pinctrl/sh-pfc/pinctrl.c +1
-1@@ -622,7 +628,7 @@ int sh_pfc_register_pinctrl(struct sh_pf pmx->pctl_desc.pmxops = &sh_pfc_pinmux_ops; pmx->pctl_desc.confops = &sh_pfc_pinconf_ops; pmx->pctl_desc.pins = pmx->pins; - pmx->pctl_desc.npins = pfc->info->nr_pins; + pmx->pctl_desc.npins = ret; pmx->pctl =pinctrl_register (&pmx->pctl_desc, pfc->dev, pmx);if (pmx->pctl ==NULL )Shouldn't you also fix
sh_pfc_init_ranges()? It includes the following code that doesn't seem to handle holes properly.
Quoted 4 lines
for (i = 1, nr_ranges = 1; i < pfc->info->nr_pins; ++i) {
if (pfc->info->pins[i-1].pin != pfc->info->pins[i].pin - 1)
nr_ranges++;
}Sorry, missed it, will try to deal with this as well...
Quoted 2 lines
Please make sure that
sh_pfc_get_pin_index()doesn't start blowing up afterwards though.
Will do.
WBR, Sergei
Hello.
Quoted 7 lines · Laurent Pinchart
Quoted 7 lines
The pin array handled by
sh_pfc_map_pins()may contain holes representing non- existing pins. We have to first count the valid pins in order to calculate the size of the memory to be allocated, then to skip over the non-existing pins when initializing the allocated arrays, and then to return the number of valid pins fromsh_pfc_map_pins()instead of 0 on success.
Quoted 8 lines
Quoted 4 lines
As we have to touch
devm_kzalloc()calls anyway, use more fittingdevm_kcalloc()instead which additionally checks the array size. And sincePINMUX_TYPE_NONEis #define'd as 0, stop re-initializing already zeroed out 'pmx->configs' array.I agree with this optimization, but I think it deserves a comment in the source code that explicitly mentions
PINMUX_TYPE_NONE, to make sure any later rework changing thePINMUX_TYPE_NONEvalue would catch this.
Note that this is not just "drove by" optimization, I was trying to avoid
the very need to explicitly initialize 'pmx->configs' array to PINMUX_TYPE_NONE...
Quoted 1 line
Quoted 1 line
Signed-off-by Sergei Shtylyov <[email protected]>
[...]
Quoted 13 lines
Review int sh_pfc_register_pinctrl(struct sh_pf · line 634
Quoted 9 lines
(quoted diff) +1
-1@@ -622,7 +628,7 @@ int sh_pfc_register_pinctrl(struct sh_pf pmx->pctl_desc.pmxops = &sh_pfc_pinmux_ops; pmx->pctl_desc.confops = &sh_pfc_pinconf_ops; pmx->pctl_desc.pins = pmx->pins; - pmx->pctl_desc.npins = pfc->info->nr_pins; + pmx->pctl_desc.npins = ret; pmx->pctl = pinctrl_register(&pmx->pctl_desc, pfc->dev, pmx); if (pmx->pctl = NULL)Shouldn't you also fix
sh_pfc_init_ranges()? It includes the following code that doesn't seem to handle holes properly.
Quoted 7 lines
for (i = 1, nr_ranges = 1; i < pfc->info->nr_pins; ++i) { if (pfc->info->pins[i-1].pin != pfc->info->pins[i].pin - 1) nr_ranges++; }Please make sure that
sh_pfc_get_pin_index()doesn't start blowing up afterwards though.
I think I'm seeing a problem with this function (and it's not due to my
changes). Its result is often used to index 'pfc->info->pins' array. While this is working now, when the holes are not yet allowed, it's going to break when we start supporting the holes since that array couldn't be indexed this way anymore (via ranges). This function is good only for 'pmx->configs' and the like where we have already removed the holes. It looks like this holes thing is going to be too complex, so how about leaving things as they are? :-)
WBR, Sergei
Quoted 59 lines · Sergei Shtylyov
Quoted 16 lines · Laurent Pinchart
Quoted 8 lines
The pin array handled by
sh_pfc_map_pins()may contain holes representing
non- existing pins. We have to first count the valid pins in order to calculate the size of the memory to be allocated, then to skip over the non-existing pins when initializing the allocated arrays, and then to return the number of valid pins fromsh_pfc_map_pins()instead of 0 on success.Quoted 6 lines
As we have to touch
devm_kzalloc()calls anyway, use more fittingdevm_kcalloc()instead which additionally checks the array size. And sincePINMUX_TYPE_NONEis #define'd as 0, stop re-initializing already zeroed out
'pmx->configs' array.Quoted 4 lines
I agree with this optimization, but I think it deserves a comment in the source code that explicitly mentions
PINMUX_TYPE_NONE, to make sure any later
rework changing thePINMUX_TYPE_NONEvalue would catch this.Note that this is not just "drove by" optimization, I was trying to avoid
the very need to explicitly initialize 'pmx->configs' array toPINMUX_TYPE_NONE...Quoted 1 line
Quoted 1 line
Signed-off-by Sergei Shtylyov <[email protected]>[...]
Quoted 23 lines
Review int sh_pfc_register_pinctrl(struct sh_pf · line 634
Quoted 9 lines
(quoted diff) +1
-1@@ -622,7 +628,7 @@ int sh_pfc_register_pinctrl(struct sh_pf pmx->pctl_desc.pmxops = &sh_pfc_pinmux_ops; pmx->pctl_desc.confops = &sh_pfc_pinconf_ops; pmx->pctl_desc.pins = pmx->pins; - pmx->pctl_desc.npins = pfc->info->nr_pins; + pmx->pctl_desc.npins = ret; pmx->pctl = pinctrl_register(&pmx->pctl_desc, pfc->dev, pmx); if (pmx->pctl = NULL)Shouldn't you also fix
sh_pfc_init_ranges()? It includes the following code
that doesn't seem to handle holes properly.for (i = 1, nr_ranges = 1; i < pfc->info->nr_pins; ++i) { if (pfc->info->pins[i-1].pin != pfc->info->pins[i].pin - 1) nr_ranges++; }Quoted 2 lines
Please make sure that
sh_pfc_get_pin_index()doesn't start blowing up afterwards though.
Quoted 8 lines
I think I'm seeing a problem with this function (and it's not due to my
changes). Its result is often used to index 'pfc->info->pins' array. While this is working now, when the holes are not yet allowed, it's going to break when we start supporting the holes since that array couldn't be indexed this way anymore (via ranges). This function is good only for 'pmx->configs' and the like where we have already removed the holes. It looks like this holes thing is going to be too complex, so how about leaving things as they are? :-)
Any conclusion on this?
If yes, please resend, incl. the r8a7794 pfc patches that depend on it.
Thanks!
Gr{oetje,eeting}s,
Geert
--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]
In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds
Hello.
Quoted 59 lines · Geert Uytterhoeven
Quoted 50 lines
Quoted 14 lines
Quoted 8 lines
The pin array handled by
sh_pfc_map_pins()may contain holes representing
non- existing pins. We have to first count the valid pins in order to calculate the size of the memory to be allocated, then to skip over the non-existing pins when initializing the allocated arrays, and then to return the number of valid pins fromsh_pfc_map_pins()instead of 0 on success.Quoted 5 lines
As we have to touch
devm_kzalloc()calls anyway, use more fittingdevm_kcalloc()instead which additionally checks the array size. And sincePINMUX_TYPE_NONEis #define'd as 0, stop re-initializing already zeroed out 'pmx->configs' array.Quoted 4 lines
I agree with this optimization, but I think it deserves a comment in the source code that explicitly mentions
PINMUX_TYPE_NONE, to make sure any later
rework changing thePINMUX_TYPE_NONEvalue would catch this.Note that this is not just "drove by" optimization, I was trying to avoid
the very need to explicitly initialize 'pmx->configs' array toPINMUX_TYPE_NONE...Quoted 1 line
Quoted 1 line
Signed-off-by Sergei Shtylyov <[email protected]>[...]
Quoted 14 lines
Review int sh_pfc_register_pinctrl(struct sh_pf · line 634
Quoted 9 lines
(quoted diff) +1
-1@@ -622,7 +628,7 @@ int sh_pfc_register_pinctrl(struct sh_pf pmx->pctl_desc.pmxops = &sh_pfc_pinmux_ops; pmx->pctl_desc.confops = &sh_pfc_pinconf_ops; pmx->pctl_desc.pins = pmx->pins; - pmx->pctl_desc.npins = pfc->info->nr_pins; + pmx->pctl_desc.npins = ret; pmx->pctl = pinctrl_register(&pmx->pctl_desc, pfc->dev, pmx); if (pmx->pctl == NULL)Shouldn't you also fix
sh_pfc_init_ranges()? It includes the following code
that doesn't seem to handle holes properly.Quoted 8 lines
for (i = 1, nr_ranges = 1; i < pfc->info->nr_pins; ++i) { if (pfc->info->pins[i-1].pin != pfc->info->pins[i].pin - 1) nr_ranges++; }Please make sure that
sh_pfc_get_pin_index()doesn't start blowing up afterwards though.Quoted 8 lines
I think I'm seeing a problem with this function (and it's not due to my
changes). Its result is often used to index 'pfc->info->pins' array. While this is working now, when the holes are not yet allowed, it's going to break when we start supporting the holes since that array couldn't be indexed this way anymore (via ranges). This function is good only for 'pmx->configs' and the like where we have already removed the holes. It looks like this holes thing is going to be too complex, so how about leaving things as they are? :-)
Quoted 1 line
Any conclusion on this?
I did overestimate the complexity, it seems. :-) I have just removed the calls to sh_pfc_get_pin_index() on
'pfc->info->pins' and its alias.
Quoted 1 line
If yes, please resend, incl. the r8a7794 pfc patches that depend on it.
Will repost the patches RSN.
Quoted 2 lines
Gr{oetje,eeting}s,
Geert
WBR, Sergei