rtc: armada38x: zalloc + calloc to single allocation
Subsystems (2)
PATCH 1/1 rtc: armada38x: zalloc + calloc to single allocation
Use a flexible array member to simplify allocation.
Signed-off-by Rosen Penev <[email protected]>
--- drivers/rtc/rtc-armada38x.c | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-)
drivers/rtc/rtc-armada38x.c +2 -7
@@ -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" );
Signature · 1 line
2.53.0
Quoted 2 lines · Rosen Penev
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 <[email protected]>
Thanks,
Gregory
Quoted 42 lines
Signed-off-by Rosen Penev <[email protected]>--- drivers/rtc/rtc-armada38x.c | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-)drivers/rtc/rtc-armada38x.c +2
-7@@ -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" );Signature · 1 line
2.53.0
Signature · 3 lines
Grégory CLEMENT, Bootlin Embedded Linux and Kernel engineering https://bootlin.com
Quoted 7 lines · Gregory CLEMENT
Quoted 2 lines · Rosen Penev
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.
Quoted 53 lines
Reviewed-by Gregory CLEMENT <[email protected]>Thanks,
Gregory
Quoted 40 lines
Signed-off-by Rosen Penev <[email protected]>--- drivers/rtc/rtc-armada38x.c | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-)drivers/rtc/rtc-armada38x.c +2
-8@@ -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" ); --Quoted 2 lines
2.53.0
--
Grégory CLEMENT, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
Quoted 3 lines · Rosen Penev
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,
Signature · 3 lines
Alexandre Belloni, co-owner and COO, Bootlin Embedded Linux and Kernel engineering https://bootlin.com