public inbox for linux-arm-kernel@lists.infradead.org
 help / color / mirror / Atom feed
* [PATCH] gpio: msc313: remove kcalloc
@ 2026-03-08  2:15 Rosen Penev
  2026-03-08  5:59 ` Daniel Palmer
  2026-03-09  0:06 ` Linus Walleij
  0 siblings, 2 replies; 8+ messages in thread
From: Rosen Penev @ 2026-03-08  2:15 UTC (permalink / raw)
  To: linux-gpio
  Cc: Daniel Palmer, linux-hardening, gustavoars, Romain Perier,
	Linus Walleij, Bartosz Golaszewski,
	moderated list:ARM/MStar/Sigmastar Armv7 SoC support, open list

Use a flexible array member to combine kzalloc and kcalloc.

Signed-off-by: Rosen Penev <rosenp@gmail.com>
---
 drivers/gpio/gpio-msc313.c | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)

diff --git a/drivers/gpio/gpio-msc313.c b/drivers/gpio/gpio-msc313.c
index 7345afdc78de..de3e6da2a089 100644
--- a/drivers/gpio/gpio-msc313.c
+++ b/drivers/gpio/gpio-msc313.c
@@ -483,7 +483,7 @@ MSC313_GPIO_CHIPDATA(ssd20xd);
 struct msc313_gpio {
 	void __iomem *base;
 	const struct msc313_gpio_data *gpio_data;
-	u8 *saved;
+	u8 saved[];
 };
 
 static int msc313_gpio_set(struct gpio_chip *chip, unsigned int offset, int value)
@@ -631,16 +631,12 @@ static int msc313_gpio_probe(struct platform_device *pdev)
 	if (!parent_domain)
 		return -ENODEV;
 
-	gpio = devm_kzalloc(dev, sizeof(*gpio), GFP_KERNEL);
+	gpio = devm_kzalloc(dev, struct_size(gpio, saved, match_data->num), GFP_KERNEL);
 	if (!gpio)
 		return -ENOMEM;
 
 	gpio->gpio_data = match_data;
 
-	gpio->saved = devm_kcalloc(dev, gpio->gpio_data->num, sizeof(*gpio->saved), GFP_KERNEL);
-	if (!gpio->saved)
-		return -ENOMEM;
-
 	gpio->base = devm_platform_ioremap_resource(pdev, 0);
 	if (IS_ERR(gpio->base))
 		return PTR_ERR(gpio->base);
-- 
2.53.0



^ permalink raw reply related	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2026-03-10  8:51 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-08  2:15 [PATCH] gpio: msc313: remove kcalloc Rosen Penev
2026-03-08  5:59 ` Daniel Palmer
2026-03-09  0:06 ` Linus Walleij
2026-03-09  1:27   ` Rosen Penev
2026-03-09  3:17     ` Gustavo A. R. Silva
2026-03-09  9:03     ` Bartosz Golaszewski
2026-03-09 22:00       ` Rosen Penev
2026-03-10  8:51         ` Bartosz Golaszewski

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox