]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
pinctrl: starfive: jh7110: use struct_size
authorRosen Penev <rosenp@gmail.com>
Sat, 25 Apr 2026 01:40:29 +0000 (18:40 -0700)
committerLinus Walleij <linusw@kernel.org>
Tue, 28 Apr 2026 10:37:00 +0000 (12:37 +0200)
Instead of an extra kcalloc, Use a flexible array member to combine
allocations. Saves a pointer in the struct.

Signed-off-by: Rosen Penev <rosenp@gmail.com>
Acked-by: Hal Feng <hal.feng@starfivetech.com>
Signed-off-by: Linus Walleij <linusw@kernel.org>
drivers/pinctrl/starfive/pinctrl-starfive-jh7110.c
drivers/pinctrl/starfive/pinctrl-starfive-jh7110.h

index e44480e71ea8fd13e3d2f6f78086475608f64a2e..3572e8edd9f30410ca95e05e5600de025fa03a94 100644 (file)
@@ -857,17 +857,15 @@ 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
        if (!sfp)
                return -ENOMEM;
 
-#if IS_ENABLED(CONFIG_PM_SLEEP)
-       sfp->saved_regs = devm_kcalloc(dev, info->nsaved_regs,
-                                      sizeof(*sfp->saved_regs), GFP_KERNEL);
-       if (!sfp->saved_regs)
-               return -ENOMEM;
-#endif
-
        sfp->base = devm_platform_ioremap_resource(pdev, 0);
        if (IS_ERR(sfp->base))
                return PTR_ERR(sfp->base);
index 2da2d6858008ccc2e7b2dd9435062f1a7745b079..188fc9d96269d3df81eec8e51b5e2127ed489c80 100644 (file)
@@ -21,7 +21,7 @@ struct jh7110_pinctrl {
        /* register read/write mutex */
        struct mutex mutex;
        const struct jh7110_pinctrl_soc_info *info;
-       u32 *saved_regs;
+       u32 saved_regs[];
 };
 
 struct jh7110_gpio_irq_reg {