* [PATCH] rtc: armada38x: zalloc + calloc to single allocation
@ 2026-03-04 22:53 Rosen Penev
2026-03-05 8:41 ` Gregory CLEMENT
2026-03-13 10:26 ` Alexandre Belloni
0 siblings, 2 replies; 4+ messages in thread
From: Rosen Penev @ 2026-03-04 22:53 UTC (permalink / raw)
To: linux-rtc
Cc: Andrew Lunn, Gregory Clement, Sebastian Hesselbarth,
Alexandre Belloni,
moderated list:ARM/Marvell Kirkwood and Armada 370, 375, 38x,...,
open list
Use a flexible array member to simplify allocation.
Signed-off-by: Rosen Penev <rosenp@gmail.com>
---
drivers/rtc/rtc-armada38x.c | 9 ++-------
1 file changed, 2 insertions(+), 7 deletions(-)
diff --git a/drivers/rtc/rtc-armada38x.c b/drivers/rtc/rtc-armada38x.c
index 713fa0d077cd..245290ae1a8d 100644
--- a/drivers/rtc/rtc-armada38x.c
+++ b/drivers/rtc/rtc-armada38x.c
@@ -72,8 +72,8 @@ struct armada38x_rtc {
spinlock_t lock;
int irq;
bool initialized;
- struct value_to_freq *val_to_freq;
const struct armada38x_rtc_data *data;
+ struct value_to_freq val_to_freq[];
};
#define ALARM1 0
@@ -490,18 +490,13 @@ static __init int armada38x_rtc_probe(struct platform_device *pdev)
{
struct armada38x_rtc *rtc;
- rtc = devm_kzalloc(&pdev->dev, sizeof(struct armada38x_rtc),
+ rtc = devm_kzalloc(&pdev->dev, struct_size(rtc, val_to_freq, SAMPLE_NR),
GFP_KERNEL);
if (!rtc)
return -ENOMEM;
rtc->data = of_device_get_match_data(&pdev->dev);
- rtc->val_to_freq = devm_kcalloc(&pdev->dev, SAMPLE_NR,
- sizeof(struct value_to_freq), GFP_KERNEL);
- if (!rtc->val_to_freq)
- return -ENOMEM;
-
spin_lock_init(&rtc->lock);
rtc->regs = devm_platform_ioremap_resource_byname(pdev, "rtc");
--
2.53.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] rtc: armada38x: zalloc + calloc to single allocation
2026-03-04 22:53 [PATCH] rtc: armada38x: zalloc + calloc to single allocation Rosen Penev
@ 2026-03-05 8:41 ` Gregory CLEMENT
2026-03-05 8:51 ` Rosen Penev
2026-03-13 10:26 ` Alexandre Belloni
1 sibling, 1 reply; 4+ messages in thread
From: Gregory CLEMENT @ 2026-03-05 8:41 UTC (permalink / raw)
To: Rosen Penev, linux-rtc
Cc: Andrew Lunn, Sebastian Hesselbarth, Alexandre Belloni,
moderated list:ARM/Marvell Kirkwood and Armada 370, 375, 38x,...,
open list
Rosen Penev <rosenp@gmail.com> writes:
> Use a flexible array member to simplify allocation.
>
I must admit that I didn't know struct_size(), it is a nice helper!
Reviewed-by: Gregory CLEMENT <gregory.clement@bootlin.com>
Thanks,
Gregory
> Signed-off-by: Rosen Penev <rosenp@gmail.com>
> ---
> drivers/rtc/rtc-armada38x.c | 9 ++-------
> 1 file changed, 2 insertions(+), 7 deletions(-)
>
> diff --git a/drivers/rtc/rtc-armada38x.c b/drivers/rtc/rtc-armada38x.c
> index 713fa0d077cd..245290ae1a8d 100644
> --- a/drivers/rtc/rtc-armada38x.c
> +++ b/drivers/rtc/rtc-armada38x.c
> @@ -72,8 +72,8 @@ struct armada38x_rtc {
> spinlock_t lock;
> int irq;
> bool initialized;
> - struct value_to_freq *val_to_freq;
> const struct armada38x_rtc_data *data;
> + struct value_to_freq val_to_freq[];
> };
>
> #define ALARM1 0
> @@ -490,18 +490,13 @@ static __init int armada38x_rtc_probe(struct platform_device *pdev)
> {
> struct armada38x_rtc *rtc;
>
> - rtc = devm_kzalloc(&pdev->dev, sizeof(struct armada38x_rtc),
> + rtc = devm_kzalloc(&pdev->dev, struct_size(rtc, val_to_freq, SAMPLE_NR),
> GFP_KERNEL);
> if (!rtc)
> return -ENOMEM;
>
> rtc->data = of_device_get_match_data(&pdev->dev);
>
> - rtc->val_to_freq = devm_kcalloc(&pdev->dev, SAMPLE_NR,
> - sizeof(struct value_to_freq), GFP_KERNEL);
> - if (!rtc->val_to_freq)
> - return -ENOMEM;
> -
> spin_lock_init(&rtc->lock);
>
> rtc->regs = devm_platform_ioremap_resource_byname(pdev, "rtc");
> --
> 2.53.0
>
--
Grégory CLEMENT, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] rtc: armada38x: zalloc + calloc to single allocation
2026-03-05 8:41 ` Gregory CLEMENT
@ 2026-03-05 8:51 ` Rosen Penev
0 siblings, 0 replies; 4+ messages in thread
From: Rosen Penev @ 2026-03-05 8:51 UTC (permalink / raw)
To: Gregory CLEMENT
Cc: linux-rtc, Andrew Lunn, Sebastian Hesselbarth, Alexandre Belloni,
moderated list:ARM/Marvell Kirkwood and Armada 370, 375, 38x,...,
open list
On Thu, Mar 5, 2026 at 12:41 AM Gregory CLEMENT
<gregory.clement@bootlin.com> wrote:
>
> Rosen Penev <rosenp@gmail.com> writes:
>
> > Use a flexible array member to simplify allocation.
> >
>
> I must admit that I didn't know struct_size(), it is a nice helper!
There's kzalloc_flex that's even nicer. Has no devm version yet.
>
> Reviewed-by: Gregory CLEMENT <gregory.clement@bootlin.com>
>
> Thanks,
>
> Gregory
> > Signed-off-by: Rosen Penev <rosenp@gmail.com>
> > ---
> > drivers/rtc/rtc-armada38x.c | 9 ++-------
> > 1 file changed, 2 insertions(+), 7 deletions(-)
> >
> > diff --git a/drivers/rtc/rtc-armada38x.c b/drivers/rtc/rtc-armada38x.c
> > index 713fa0d077cd..245290ae1a8d 100644
> > --- a/drivers/rtc/rtc-armada38x.c
> > +++ b/drivers/rtc/rtc-armada38x.c
> > @@ -72,8 +72,8 @@ struct armada38x_rtc {
> > spinlock_t lock;
> > int irq;
> > bool initialized;
> > - struct value_to_freq *val_to_freq;
> > const struct armada38x_rtc_data *data;
> > + struct value_to_freq val_to_freq[];
> > };
> >
> > #define ALARM1 0
> > @@ -490,18 +490,13 @@ static __init int armada38x_rtc_probe(struct platform_device *pdev)
> > {
> > struct armada38x_rtc *rtc;
> >
> > - rtc = devm_kzalloc(&pdev->dev, sizeof(struct armada38x_rtc),
> > + rtc = devm_kzalloc(&pdev->dev, struct_size(rtc, val_to_freq, SAMPLE_NR),
> > GFP_KERNEL);
> > if (!rtc)
> > return -ENOMEM;
> >
> > rtc->data = of_device_get_match_data(&pdev->dev);
> >
> > - rtc->val_to_freq = devm_kcalloc(&pdev->dev, SAMPLE_NR,
> > - sizeof(struct value_to_freq), GFP_KERNEL);
> > - if (!rtc->val_to_freq)
> > - return -ENOMEM;
> > -
> > spin_lock_init(&rtc->lock);
> >
> > rtc->regs = devm_platform_ioremap_resource_byname(pdev, "rtc");
> > --
> > 2.53.0
> >
>
> --
> Grégory CLEMENT, Bootlin
> Embedded Linux and Kernel engineering
> https://bootlin.com
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] rtc: armada38x: zalloc + calloc to single allocation
2026-03-04 22:53 [PATCH] rtc: armada38x: zalloc + calloc to single allocation Rosen Penev
2026-03-05 8:41 ` Gregory CLEMENT
@ 2026-03-13 10:26 ` Alexandre Belloni
1 sibling, 0 replies; 4+ messages in thread
From: Alexandre Belloni @ 2026-03-13 10:26 UTC (permalink / raw)
To: linux-rtc, Rosen Penev
Cc: Andrew Lunn, Gregory Clement, Sebastian Hesselbarth,
linux-arm-kernel, linux-kernel
On Wed, 04 Mar 2026 14:53:29 -0800, Rosen Penev wrote:
> Use a flexible array member to simplify allocation.
>
>
Applied, thanks!
[1/1] rtc: armada38x: zalloc + calloc to single allocation
https://git.kernel.org/abelloni/c/5827fe59745d
Best regards,
--
Alexandre Belloni, co-owner and COO, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-03-13 10:27 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-04 22:53 [PATCH] rtc: armada38x: zalloc + calloc to single allocation Rosen Penev
2026-03-05 8:41 ` Gregory CLEMENT
2026-03-05 8:51 ` Rosen Penev
2026-03-13 10:26 ` Alexandre Belloni
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox