From: Rosen Penev <rosenp@gmail.com>
To: linux-gpio@vger.kernel.org
Cc: Geert Uytterhoeven <geert+renesas@glider.be>,
Linus Walleij <linusw@kernel.org>, Kees Cook <kees@kernel.org>,
"Gustavo A. R. Silva" <gustavoars@kernel.org>,
linux-renesas-soc@vger.kernel.org (open list:PIN CONTROLLER -
RENESAS), linux-kernel@vger.kernel.org (open list),
linux-hardening@vger.kernel.org (open list:KERNEL HARDENING (not
covered by other areas):Keyword:\b__counted_by(_le|_be|_ptr)?\b)
Subject: [PATCHv2] pinctrl: rza2: embed pins in the priv struct
Date: Wed, 27 May 2026 13:23:17 -0700 [thread overview]
Message-ID: <20260527202317.5347-1-rosenp@gmail.com> (raw)
Turn the separately allocated pinctrl_pin_desc array into a flexible
array member of struct rza2_pinctrl_priv, annotated with
__counted_by(npins). The pin count is now computed before allocation so
struct_size() can size the combined object, collapsing two allocations
into one.
Change npins to unsigned int to avoid potential overflow/underflow
errors.
Assisted-by: Claude:Opus-4.7
Signed-off-by: Rosen Penev <rosenp@gmail.com>
---
v2: use unsigned inr
drivers/pinctrl/renesas/pinctrl-rza2.c | 28 ++++++++++++--------------
1 file changed, 13 insertions(+), 15 deletions(-)
diff --git a/drivers/pinctrl/renesas/pinctrl-rza2.c b/drivers/pinctrl/renesas/pinctrl-rza2.c
index 8618f32ed26a..15ae5a88d705 100644
--- a/drivers/pinctrl/renesas/pinctrl-rza2.c
+++ b/drivers/pinctrl/renesas/pinctrl-rza2.c
@@ -44,12 +44,12 @@ struct rza2_pinctrl_priv {
struct device *dev;
void __iomem *base;
- struct pinctrl_pin_desc *pins;
struct pinctrl_desc desc;
struct pinctrl_dev *pctl;
struct pinctrl_gpio_range gpio_range;
- int npins;
+ unsigned int npins;
struct mutex mutex; /* serialize adding groups and functions */
+ struct pinctrl_pin_desc pins[] __counted_by(npins);
};
#define RZA2_PDR(port) (0x0000 + (port) * 2) /* Direction 16-bit */
@@ -289,21 +289,17 @@ static int rza2_gpio_register(struct rza2_pinctrl_priv *priv)
static int rza2_pinctrl_register(struct rza2_pinctrl_priv *priv)
{
- struct pinctrl_pin_desc *pins;
+ struct pinctrl_pin_desc *pin;
unsigned int i;
int ret;
- pins = devm_kcalloc(priv->dev, priv->npins, sizeof(*pins), GFP_KERNEL);
- if (!pins)
- return -ENOMEM;
-
- priv->pins = pins;
- priv->desc.pins = pins;
+ priv->desc.pins = priv->pins;
priv->desc.npins = priv->npins;
for (i = 0; i < priv->npins; i++) {
- pins[i].number = i;
- pins[i].name = rza2_gpio_names[i];
+ pin = &priv->pins[i];
+ pin->number = i;
+ pin->name = rza2_gpio_names[i];
}
ret = devm_pinctrl_register_and_init(priv->dev, &priv->desc, priv,
@@ -482,12 +478,17 @@ static const struct pinmux_ops rza2_pinmux_ops = {
static int rza2_pinctrl_probe(struct platform_device *pdev)
{
struct rza2_pinctrl_priv *priv;
+ unsigned int npins;
int ret;
- priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL);
+ npins = (uintptr_t)of_device_get_match_data(&pdev->dev) *
+ RZA2_PINS_PER_PORT;
+
+ priv = devm_kzalloc(&pdev->dev, struct_size(priv, pins, npins), GFP_KERNEL);
if (!priv)
return -ENOMEM;
+ priv->npins = npins;
priv->dev = &pdev->dev;
priv->base = devm_platform_ioremap_resource(pdev, 0);
@@ -498,9 +499,6 @@ static int rza2_pinctrl_probe(struct platform_device *pdev)
platform_set_drvdata(pdev, priv);
- priv->npins = (int)(uintptr_t)of_device_get_match_data(&pdev->dev) *
- RZA2_PINS_PER_PORT;
-
priv->desc.name = DRIVER_NAME;
priv->desc.pctlops = &rza2_pinctrl_ops;
priv->desc.pmxops = &rza2_pinmux_ops;
--
2.54.0
next reply other threads:[~2026-05-27 20:23 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-27 20:23 Rosen Penev [this message]
2026-06-02 12:54 ` [PATCHv2] pinctrl: rza2: embed pins in the priv struct Geert Uytterhoeven
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=20260527202317.5347-1-rosenp@gmail.com \
--to=rosenp@gmail.com \
--cc=geert+renesas@glider.be \
--cc=gustavoars@kernel.org \
--cc=kees@kernel.org \
--cc=linusw@kernel.org \
--cc=linux-gpio@vger.kernel.org \
--cc=linux-hardening@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-renesas-soc@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