regulator: cros-ec-regulator: Add NULL test for devm_kmemdup call

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>
This commit is contained in:
Axel Lin 2020-08-02 11:25:09 +08:00 committed by Mark Brown
parent bcb3b2a763
commit ce41090057
No known key found for this signature in database
GPG Key ID: 24D68B725D5487D0

View 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 */