* [PATCH] gpio: bcm-kona: remove kcalloc
@ 2026-03-11 0:34 Rosen Penev
2026-03-11 8:46 ` Bartosz Golaszewski
0 siblings, 1 reply; 2+ messages in thread
From: Rosen Penev @ 2026-03-11 0:34 UTC (permalink / raw)
To: linux-gpio
Cc: Ray Jui, Broadcom internal kernel review list, Linus Walleij,
Bartosz Golaszewski, Florian Fainelli, Scott Branden, Kees Cook,
Gustavo A. R. Silva, open list,
open list:KERNEL HARDENING (not covered by other
areas):Keyword:b__counted_by(_le|_be)?b
Simplify allocation by using a flexible array member.
Use __counted_by for extra runtime analysis.
Shuffle some code as __counted_by requires the counting variable to be
set right after allocation.
Signed-off-by: Rosen Penev <rosenp@gmail.com>
---
drivers/gpio/gpio-bcm-kona.c | 37 ++++++++++++++++--------------------
1 file changed, 16 insertions(+), 21 deletions(-)
diff --git a/drivers/gpio/gpio-bcm-kona.c b/drivers/gpio/gpio-bcm-kona.c
index 208b71c59d58..b1d32d590cf8 100644
--- a/drivers/gpio/gpio-bcm-kona.c
+++ b/drivers/gpio/gpio-bcm-kona.c
@@ -58,15 +58,6 @@
#define LOCK_CODE 0xffffffff
#define UNLOCK_CODE 0x00000000
-struct bcm_kona_gpio {
- void __iomem *reg_base;
- int num_bank;
- raw_spinlock_t lock;
- struct gpio_chip gpio_chip;
- struct irq_domain *irq_domain;
- struct bcm_kona_gpio_bank *banks;
-};
-
struct bcm_kona_gpio_bank {
int id;
int irq;
@@ -90,6 +81,15 @@ struct bcm_kona_gpio_bank {
struct bcm_kona_gpio *kona_gpio;
};
+struct bcm_kona_gpio {
+ void __iomem *reg_base;
+ int num_bank;
+ raw_spinlock_t lock;
+ struct gpio_chip gpio_chip;
+ struct irq_domain *irq_domain;
+ struct bcm_kona_gpio_bank banks[] __counted_by(num_bank);
+};
+
static inline void bcm_kona_gpio_write_lock_regs(void __iomem *reg_base,
int bank_id, u32 lockcode)
{
@@ -584,12 +584,6 @@ static int bcm_kona_gpio_probe(struct platform_device *pdev)
int ret;
int i;
- kona_gpio = devm_kzalloc(dev, sizeof(*kona_gpio), GFP_KERNEL);
- if (!kona_gpio)
- return -ENOMEM;
-
- kona_gpio->gpio_chip = template_chip;
- chip = &kona_gpio->gpio_chip;
ret = platform_irq_count(pdev);
if (!ret) {
dev_err(dev, "Couldn't determine # GPIO banks\n");
@@ -597,6 +591,11 @@ static int bcm_kona_gpio_probe(struct platform_device *pdev)
} else if (ret < 0) {
return dev_err_probe(dev, ret, "Couldn't determine GPIO banks\n");
}
+
+ kona_gpio = devm_kzalloc(dev, struct_size(kona_gpio, banks, ret), GFP_KERNEL);
+ if (!kona_gpio)
+ return -ENOMEM;
+
kona_gpio->num_bank = ret;
if (kona_gpio->num_bank > GPIO_MAX_BANK_NUM) {
@@ -604,13 +603,9 @@ static int bcm_kona_gpio_probe(struct platform_device *pdev)
GPIO_MAX_BANK_NUM);
return -ENXIO;
}
- kona_gpio->banks = devm_kcalloc(dev,
- kona_gpio->num_bank,
- sizeof(*kona_gpio->banks),
- GFP_KERNEL);
- if (!kona_gpio->banks)
- return -ENOMEM;
+ kona_gpio->gpio_chip = template_chip;
+ chip = &kona_gpio->gpio_chip;
chip->parent = dev;
chip->ngpio = kona_gpio->num_bank * GPIO_PER_BANK;
--
2.53.0
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] gpio: bcm-kona: remove kcalloc
2026-03-11 0:34 [PATCH] gpio: bcm-kona: remove kcalloc Rosen Penev
@ 2026-03-11 8:46 ` Bartosz Golaszewski
0 siblings, 0 replies; 2+ messages in thread
From: Bartosz Golaszewski @ 2026-03-11 8:46 UTC (permalink / raw)
To: linux-gpio, Rosen Penev
Cc: Bartosz Golaszewski, Ray Jui,
Broadcom internal kernel review list, Linus Walleij,
Bartosz Golaszewski, Florian Fainelli, Scott Branden, Kees Cook,
Gustavo A. R. Silva, linux-kernel, linux-hardening
On Tue, 10 Mar 2026 17:34:31 -0700, Rosen Penev wrote:
> Simplify allocation by using a flexible array member.
>
> Use __counted_by for extra runtime analysis.
>
> Shuffle some code as __counted_by requires the counting variable to be
> set right after allocation.
>
> [...]
Applied, thanks!
[1/1] gpio: bcm-kona: remove kcalloc
https://git.kernel.org/brgl/c/0258fe8721f541bbd3949cac2f4971b98e1fe4ed
Best regards,
--
Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-03-11 8:46 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-03-11 0:34 [PATCH] gpio: bcm-kona: remove kcalloc Rosen Penev
2026-03-11 8:46 ` Bartosz Golaszewski
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®