regulator: Remove pointer table overallocation
authorMichał Mirosław <mirq-linux@rere.qmqm.pl>
Sun, 9 Aug 2020 19:21:16 +0000 (21:21 +0200)
committerMark Brown <broonie@kernel.org>
Tue, 18 Aug 2020 16:18:44 +0000 (17:18 +0100)
The code allocates sizeof(regulator_dev) for a pointer. Make it less
generous. Let kcalloc() calculate the size, while at it.

Signed-off-by: Michał Mirosław <mirq-linux@rere.qmqm.pl>
Reviewed-by: Dmitry Osipenko <digetx@gmail.com>
Link: https://lore.kernel.org/r/407fbd06a02caf038a9ba3baa51c7d6d47cd6517.1597000795.git.mirq-linux@rere.qmqm.pl
Signed-off-by: Mark Brown <broonie@kernel.org>
drivers/regulator/core.c

index 76e9ed8..98777d7 100644 (file)
@@ -5030,20 +5030,20 @@ static void regulator_remove_coupling(struct regulator_dev *rdev)
 
 static int regulator_init_coupling(struct regulator_dev *rdev)
 {
+       struct regulator_dev **coupled;
        int err, n_phandles;
-       size_t alloc_size;
 
        if (!IS_ENABLED(CONFIG_OF))
                n_phandles = 0;
        else
                n_phandles = of_get_n_coupled(rdev);
 
-       alloc_size = sizeof(*rdev) * (n_phandles + 1);
-
-       rdev->coupling_desc.coupled_rdevs = kzalloc(alloc_size, GFP_KERNEL);
-       if (!rdev->coupling_desc.coupled_rdevs)
+       coupled = kcalloc(n_phandles + 1, sizeof(*coupled), GFP_KERNEL);
+       if (!coupled)
                return -ENOMEM;
 
+       rdev->coupling_desc.coupled_rdevs = coupled;
+
        /*
         * Every regulator should always have coupling descriptor filled with
         * at least pointer to itself.