Re: [PATCH] pinctrl: sophgo: allocate power_cfg with priv

Linus Walleij <[email protected]> Tue, 5 May 2026 14:08:46 +0200
Newsgroups dev.linux.lists.sophgo,org.kernel.vger.linux-gpio,org.kernel.vger.linux-kernel
Message-ID <CAD++jLk10PN8854hqQbdy0A57UWiT2Pvmw3ew+vSVb5WBZZBxg@mail.gmail.com>
Hi Rosen,

thanks for your patch!

On Fri, May 1, 2026 at 12:04 AM Rosen Penev <[email protected]> wrote:

> Use a flexible array member to combine allocations and simplify code
> slightly.
>
> Signed-off-by: Rosen Penev <[email protected]>

I have applied the patch with the following augmentation:

iff --git a/drivers/pinctrl/sophgo/pinctrl-cv18xx.c
b/drivers/pinctrl/sophgo/pinctrl-cv18xx.c
index 154ba9a4f08c..59318a42690f 100644
--- a/drivers/pinctrl/sophgo/pinctrl-cv18xx.c
+++ b/drivers/pinctrl/sophgo/pinctrl-cv18xx.c
@@ -27,8 +27,9 @@
 #include "pinctrl-cv18xx.h"

 struct cv1800_priv {
-       void __iomem                            *regs[2];
-       u32                                     power_cfg[];
+       void __iomem    *regs[2];
+       unsigned int    num_power_cfg;
+       u32             power_cfg[] __counted_by(num_power_cfg);
 };

 static unsigned int cv1800_dt_get_pin_mux(u32 value)
@@ -421,6 +422,7 @@ static int cv1800_pinctrl_init(struct platform_device *pdev,
                        GFP_KERNEL);
        if (!priv)
                return -ENOMEM;
+       priv->num_power_cfg = pctrl_data->npds;

        priv->regs[0] = devm_platform_ioremap_resource_byname(pdev, "sys");
        if (IS_ERR(priv->regs[0]))

I think this has been mentioned before?

Including a counter for dynamic arrays makes it possible for the
compiler to insert runtime checks akin to those that are used for
Pascal or Rust arrays making it harder for the arrays to be indexed
out of range.

Yours,
Linus Walleij