]> git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/commitdiff
memory: samsung: exynos5422-dmc: Avoid some over memory allocation
authorChristophe JAILLET <christophe.jaillet@wanadoo.fr>
Sun, 20 Mar 2022 07:10:30 +0000 (08:10 +0100)
committerStefan Bader <stefan.bader@canonical.com>
Wed, 10 Aug 2022 07:24:41 +0000 (09:24 +0200)
BugLink: https://bugs.launchpad.net/bugs/1981864
[ Upstream commit 56653827f0d7bc7c2d8bac0e119fd1521fa9990a ]

'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>
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>
Signed-off-by: Kamal Mostafa <kamal@canonical.com>
Signed-off-by: Stefan Bader <stefan.bader@canonical.com>
drivers/memory/samsung/exynos5422-dmc.c

index 9c8318923ed0b25ea4a48729a6205bfca1395eed..4733e7898ffe5379686afdad2f8bde52bbb72add 100644 (file)
@@ -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;