pinctrl: starfive: Fix some jh7110 issues found in late review
Subsystems (3)
Linus Walleij
maintainercover pinctrl: starfive: Fix some jh7110 issues found in late review
Found a counted_by() issue and implemented a suggestion from Geert.
---
Linus Walleij (2):
pinctrl: starfive: jh7110: Use __counted_by() flexarray
pinctrl: starfive: jh7110: Avoid ifdeffery
drivers/pinctrl/starfive/pinctrl-starfive-jh7110.c | 11 +++++------ drivers/pinctrl/starfive/pinctrl-starfive-jh7110.h | 3 ++- 2 files changed, 7 insertions(+), 7 deletions(-)
---
base-commit: 42ec31ec8df4675af621ec686db7410153beebfd
change-id: 20260518-jh7110-66ec4fa3b3db
Best regards,
Signature · 1 line
Linus Walleij <[email protected]>
Linus Walleij
maintainerPATCH 1/2 pinctrl: starfive: jh7110: Use __counted_by() flexarray
Flexible arrays should use __counted_by() to be able to do runtime checks that the array does not go out of range.
--- drivers/pinctrl/starfive/pinctrl-starfive-jh7110.c | 1 + drivers/pinctrl/starfive/pinctrl-starfive-jh7110.h | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-)
drivers/pinctrl/starfive/pinctrl-starfive-jh7110.c +1 -0
@@ -865,6 +865,7 @@ int jh7110_pinctrl_probe(struct platform_device *pdev)#endif if (!sfp)return -ENOMEM ; + sfp->num_saved_regs = info->nsaved_regs; sfp->base =devm_platform_ioremap_resource (pdev,0 );if (IS_ERR (sfp->base))
drivers/pinctrl/starfive/pinctrl-starfive-jh7110.h +2 -1
@@ -21,7 +21,8 @@ struct jh7110_pinctrl {/* register read/write mutex */ struct mutex mutex;const struct jh7110_pinctrl_soc_info *info; -u32 saved_regs[]; +unsigned int num_saved_regs; + u32 saved_regs[] __counted_by(num_saved_regs); };struct jh7110_gpio_irq_reg {
Signature · 1 line
2.54.0
Linus Walleij
maintainerPATCH 2/2 pinctrl: starfive: jh7110: Avoid ifdeffery
In reply to Linus WalleijUse IS_ENABLED() inline assigning a variable instead of ifdeffery.
--- drivers/pinctrl/starfive/pinctrl-starfive-jh7110.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-)
drivers/pinctrl/starfive/pinctrl-starfive-jh7110.c +5 -7
@@ -845,6 +845,7 @@ int jh7110_pinctrl_probe(struct platform_device *pdev)struct jh7110_pinctrl *sfp;struct pinctrl_desc *jh7110_pinctrl_desc;struct reset_control *rst; +unsigned int num_saved_regs;struct clk *clk;int ret;
@@ -857,15 +858,12 @@ int jh7110_pinctrl_probe(struct platform_device *pdev)return -EINVAL ; } -#if IS_ENABLED (CONFIG_PM_SLEEP ) - sfp =devm_kzalloc (dev,struct_size (sfp, saved_regs, info->nsaved_regs), -GFP_KERNEL ); -#else - sfp =devm_kzalloc (dev,sizeof (*sfp),GFP_KERNEL ); -#endif + num_saved_regs =IS_ENABLED (CONFIG_PM_SLEEP ) ? info->nsaved_regs :0 ; + sfp =devm_kzalloc (dev,struct_size (sfp, saved_regs, num_saved_regs), +GFP_KERNEL );if (!sfp)return -ENOMEM ; - sfp->num_saved_regs = info->nsaved_regs; + sfp->num_saved_regs = num_saved_regs; sfp->base =devm_platform_ioremap_resource (pdev,0 );if (IS_ERR (sfp->base))
Signature · 1 line
2.54.0
Re: [PATCH 2/2] pinctrl: starfive: jh7110: Avoid ifdeffery
Quoted 30 lines · Linus Walleij
Use
IS_ENABLED()inline assigning a variable instead of ifdeffery.Cc Rosen Penev <[email protected]>Suggested-by Geert Uytterhoeven <[email protected]>Link https://lore.kernel.org/linux-gpio/CAMuHMdX7t7VHTzybjYo3s8SU3XLEH9GKsxmLBbh7p4D1CT3H_Q@mail.gmail.com/ open hereSigned-off-by Linus Walleij <[email protected]>--- drivers/pinctrl/starfive/pinctrl-starfive-jh7110.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-)drivers/pinctrl/starfive/pinctrl-starfive-jh7110.c +1
-3@@ -845,6 +845,7 @@ int jh7110_pinctrl_probe(struct platform_device *pdev)struct jh7110_pinctrl *sfp;struct pinctrl_desc *jh7110_pinctrl_desc;struct reset_control *rst; +unsigned int num_saved_regs;struct clk *clk;int ret;@@ -857,15 +858,12 @@ int jh7110_pinctrl_probe(struct platform_device *pdev)return -EINVAL ; } -#if IS_ENABLED (CONFIG_PM_SLEEP ) - sfp =devm_kzalloc (dev,struct_size (sfp, saved_regs, info->nsaved_regs), -GFP_KERNEL );
drivers/pinctrl/starfive/pinctrl-starfive-jh7110.c int jh7110_pinctrl_probe(struct platform_device *pdev) · line 866
Quoted 10 lines
drivers/pinctrl/starfive/pinctrl-starfive-jh7110.c +4
-4-#else - sfp =devm_kzalloc (dev,sizeof (*sfp),GFP_KERNEL ); -#endif + num_saved_regs =IS_ENABLED (CONFIG_PM_SLEEP ) ? info->nsaved_regs :0 ; + sfp =devm_kzalloc (dev,struct_size (sfp, saved_regs, num_saved_regs), +GFP_KERNEL );if (!sfp)return -ENOMEM ; - sfp->num_saved_regs = info->nsaved_regs; + sfp->num_saved_regs = num_saved_regs;
yeah and this is used absolutely nowhere. Both for loops are of the form
for (i = 0 ; i < sfp->info->nsaved_regs ; i++)
I really don't think __counted_by is worth it here.
Quoted 7 lines
drivers/pinctrl/starfive/pinctrl-starfive-jh7110.c +0
-1sfp->base =devm_platform_ioremap_resource (pdev,0 );if (IS_ERR (sfp->base)) --2.54.0
Linus Walleij
maintainerRe: [PATCH 2/2] pinctrl: starfive: jh7110: Avoid ifdeffery
Quoted 8 lines · Rosen Penev
drivers/pinctrl/starfive/pinctrl-starfive-jh7110.c int jh7110_pinctrl_probe(struct platform_device *pdev) · line 866
Quoted 2 lines
drivers/pinctrl/starfive/pinctrl-starfive-jh7110.c +1
-1- sfp->num_saved_regs = info->nsaved_regs; + sfp->num_saved_regs = num_saved_regs;yeah and this is used absolutely nowhere. Both for loops are of the form
for (i = 0 ; i <
sfp->info->nsaved_regs; i++)I really don't think
__counted_byis worth it here.
__counted_by() is used by compiler instrumentation, i.e. by hardening code that is not visible directly in the driver.
During compilation, code will be inserted that checks boundaries of the array at runtime.
Yours,
Linus Walleij