Skip to content

Commit

Permalink
memory: samsung: exynos5422-dmc: Avoid some over memory allocation
Browse files Browse the repository at this point in the history
[ Upstream commit 5665382 ]

'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: 6e7674c ("memory: Add DMC driver for Exynos5422")
Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
Link: https://lore.kernel.org/r/69d7e69346986e2fdb994d4382954c932f9f0993.1647760213.git.christophe.jaillet@wanadoo.fr
Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
  • Loading branch information
tititiou36 authored and gregkh committed Jun 9, 2022
1 parent 3960629 commit ea4f1c6
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions drivers/memory/samsung/exynos5422-dmc.c
Original file line number Diff line number Diff line change
Expand Up @@ -1327,7 +1327,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,
Expand All @@ -1337,8 +1336,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;

Expand Down

0 comments on commit ea4f1c6

Please sign in to comment.