]> git.baikalelectronics.ru Git - kernel.git/commitdiff
regulator: cros-ec-regulator: Add NULL test for devm_kmemdup call
authorAxel Lin <axel.lin@ingics.com>
Sun, 2 Aug 2020 03:25:09 +0000 (11:25 +0800)
committerMark Brown <broonie@kernel.org>
Tue, 4 Aug 2020 12:24:37 +0000 (13:24 +0100)
Fix possible NULL pointer dereference.

Signed-off-by: Axel Lin <axel.lin@ingics.com>
Link: https://lore.kernel.org/r/20200802032509.305425-1-axel.lin@ingics.com
Signed-off-by: Mark Brown <broonie@kernel.org>
drivers/regulator/cros-ec-regulator.c

index 3117bbd2826b2d1e42db29853d2541f9e5a0ad92..eb3fc1db4edc8118b0be4133e559e10e1f7a233d 100644 (file)
@@ -170,6 +170,9 @@ static int cros_ec_regulator_init_info(struct device *dev,
        data->voltages_mV =
                devm_kmemdup(dev, resp.voltages_mv,
                             sizeof(u16) * data->num_voltages, GFP_KERNEL);
+       if (!data->voltages_mV)
+               return -ENOMEM;
+
        data->desc.n_voltages = data->num_voltages;
 
        /* Make sure the returned name is always a valid string */