[PATCH] regulator: cros-ec-regulator: Add NULL test for devm_kmemdup call

From: Axel Lin
Date: Sat Aug 01 2020 - 23:30:44 EST


Fix possible NULL pointer dereference.

Signed-off-by: Axel Lin <axel.lin@xxxxxxxxxx>
---
drivers/regulator/cros-ec-regulator.c | 3 +++
1 file changed, 3 insertions(+)

diff --git a/drivers/regulator/cros-ec-regulator.c b/drivers/regulator/cros-ec-regulator.c
index 3117bbd2826b..eb3fc1db4edc 100644
--- a/drivers/regulator/cros-ec-regulator.c
+++ b/drivers/regulator/cros-ec-regulator.c
@@ -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 */
--
2.25.1