From: Rosen Penev <rosenp@gmail.com>
To: linux-gpio@vger.kernel.org
Cc: Emil Renner Berthing <kernel@esmil.dk>,
Hal Feng <hal.feng@starfivetech.com>,
Linus Walleij <linusw@kernel.org>,
linux-kernel@vger.kernel.org (open list)
Subject: [PATCH] pinctrl: starfive: jh7110: use struct_size
Date: Fri, 24 Apr 2026 18:40:29 -0700 [thread overview]
Message-ID: <20260425014029.438186-1-rosenp@gmail.com> (raw)
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>
---
drivers/pinctrl/starfive/pinctrl-starfive-jh7110.c | 12 +++++-------
drivers/pinctrl/starfive/pinctrl-starfive-jh7110.h | 2 +-
2 files changed, 6 insertions(+), 8 deletions(-)
diff --git a/drivers/pinctrl/starfive/pinctrl-starfive-jh7110.c b/drivers/pinctrl/starfive/pinctrl-starfive-jh7110.c
index e44480e71ea8..3572e8edd9f3 100644
--- a/drivers/pinctrl/starfive/pinctrl-starfive-jh7110.c
+++ b/drivers/pinctrl/starfive/pinctrl-starfive-jh7110.c
@@ -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);
diff --git a/drivers/pinctrl/starfive/pinctrl-starfive-jh7110.h b/drivers/pinctrl/starfive/pinctrl-starfive-jh7110.h
index 2da2d6858008..188fc9d96269 100644
--- a/drivers/pinctrl/starfive/pinctrl-starfive-jh7110.h
+++ b/drivers/pinctrl/starfive/pinctrl-starfive-jh7110.h
@@ -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 {
--
2.54.0
next reply other threads:[~2026-04-25 1:40 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-25 1:40 Rosen Penev [this message]
2026-04-25 8:28 ` [PATCH] pinctrl: starfive: jh7110: use struct_size Hal Feng
2026-04-28 10:37 ` Linus Walleij
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260425014029.438186-1-rosenp@gmail.com \
--to=rosenp@gmail.com \
--cc=hal.feng@starfivetech.com \
--cc=kernel@esmil.dk \
--cc=linusw@kernel.org \
--cc=linux-gpio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox