* [PATCH] memory: samsung: exynos5422-dmc: Avoid some over memory allocation
@ 2022-03-20 7:10 Christophe JAILLET
2022-03-20 12:16 ` Krzysztof Kozlowski
2022-04-04 17:08 ` Krzysztof Kozlowski
0 siblings, 2 replies; 3+ messages in thread
From: Christophe JAILLET @ 2022-03-20 7:10 UTC (permalink / raw)
To: Lukasz Luba, Krzysztof Kozlowski, Alim Akhtar
Cc: linux-kernel, kernel-janitors, Christophe JAILLET, linux-pm,
linux-samsung-soc, linux-arm-kernel
'dmc->counter' is a 'struct devfreq_event_dev **', so there is some
over memory allocation. 'counters_size' should be computed with
'sizeof(struct devfreq_event_dev *)'.
Use 'sizeof(*dmc->counter)' instead to fix it.
While at it, use devm_kcalloc() instead of devm_kzalloc()+open coded
multiplication.
Fixes: 6e7674c3c6df ("memory: Add DMC driver for Exynos5422")
Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
---
devm_kmalloc_array() could also be used to save a few cycles because the
array is fully initialized a few lines below.
---
drivers/memory/samsung/exynos5422-dmc.c | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)
diff --git a/drivers/memory/samsung/exynos5422-dmc.c b/drivers/memory/samsung/exynos5422-dmc.c
index 9c8318923ed0..4733e7898ffe 100644
--- a/drivers/memory/samsung/exynos5422-dmc.c
+++ b/drivers/memory/samsung/exynos5422-dmc.c
@@ -1322,7 +1322,6 @@ static int exynos5_dmc_init_clks(struct exynos5_dmc *dmc)
*/
static int exynos5_performance_counters_init(struct exynos5_dmc *dmc)
{
- int counters_size;
int ret, i;
dmc->num_counters = devfreq_event_get_edev_count(dmc->dev,
@@ -1332,8 +1331,8 @@ static int exynos5_performance_counters_init(struct exynos5_dmc *dmc)
return dmc->num_counters;
}
- counters_size = sizeof(struct devfreq_event_dev) * dmc->num_counters;
- dmc->counter = devm_kzalloc(dmc->dev, counters_size, GFP_KERNEL);
+ dmc->counter = devm_kcalloc(dmc->dev, dmc->num_counters,
+ sizeof(*dmc->counter), GFP_KERNEL);
if (!dmc->counter)
return -ENOMEM;
--
2.32.0
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCH] memory: samsung: exynos5422-dmc: Avoid some over memory allocation
2022-03-20 7:10 [PATCH] memory: samsung: exynos5422-dmc: Avoid some over memory allocation Christophe JAILLET
@ 2022-03-20 12:16 ` Krzysztof Kozlowski
2022-04-04 17:08 ` Krzysztof Kozlowski
1 sibling, 0 replies; 3+ messages in thread
From: Krzysztof Kozlowski @ 2022-03-20 12:16 UTC (permalink / raw)
To: Christophe JAILLET, Lukasz Luba, Alim Akhtar
Cc: linux-kernel, kernel-janitors, linux-pm, linux-samsung-soc,
linux-arm-kernel
On 20/03/2022 08:10, Christophe JAILLET wrote:
> 'dmc->counter' is a 'struct devfreq_event_dev **', so there is some
> over memory allocation. 'counters_size' should be computed with
> 'sizeof(struct devfreq_event_dev *)'.
>
> Use 'sizeof(*dmc->counter)' instead to fix it.
>
> While at it, use devm_kcalloc() instead of devm_kzalloc()+open coded
> multiplication.
>
> Fixes: 6e7674c3c6df ("memory: Add DMC driver for Exynos5422")
> Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
> ---
> devm_kmalloc_array() could also be used to save a few cycles because the
> array is fully initialized a few lines below.
> ---
> drivers/memory/samsung/exynos5422-dmc.c | 5 ++---
> 1 file changed, 2 insertions(+), 3 deletions(-)
>
Thanks, looks good. I'll take it after merge window.
Best regards,
Krzysztof
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCH] memory: samsung: exynos5422-dmc: Avoid some over memory allocation
2022-03-20 7:10 [PATCH] memory: samsung: exynos5422-dmc: Avoid some over memory allocation Christophe JAILLET
2022-03-20 12:16 ` Krzysztof Kozlowski
@ 2022-04-04 17:08 ` Krzysztof Kozlowski
1 sibling, 0 replies; 3+ messages in thread
From: Krzysztof Kozlowski @ 2022-04-04 17:08 UTC (permalink / raw)
To: Christophe JAILLET, Alim Akhtar, Lukasz Luba, Krzysztof Kozlowski
Cc: Krzysztof Kozlowski, linux-samsung-soc, kernel-janitors,
linux-kernel, linux-pm, linux-arm-kernel
On Sun, 20 Mar 2022 08:10:30 +0100, Christophe JAILLET wrote:
> 'dmc->counter' is a 'struct devfreq_event_dev **', so there is some
> over memory allocation. 'counters_size' should be computed with
> 'sizeof(struct devfreq_event_dev *)'.
>
> Use 'sizeof(*dmc->counter)' instead to fix it.
>
> While at it, use devm_kcalloc() instead of devm_kzalloc()+open coded
> multiplication.
>
> [...]
Applied, thanks!
[1/1] memory: samsung: exynos5422-dmc: Avoid some over memory allocation
commit: 56653827f0d7bc7c2d8bac0e119fd1521fa9990a
Best regards,
--
Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2022-04-04 21:25 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-20 7:10 [PATCH] memory: samsung: exynos5422-dmc: Avoid some over memory allocation Christophe JAILLET
2022-03-20 12:16 ` Krzysztof Kozlowski
2022-04-04 17:08 ` Krzysztof Kozlowski
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®