Commit 8f5a37cb authored by Viresh Kumar's avatar Viresh Kumar Committed by Sebastian Reichel

power-supply: Don't over-allocate memory for "supplied-from" array

In routine power_supply_check_supplies(), 'cnt' is counting the number of
supplies passed in "power-supplies" field of a node. The value of 'cnt' will
always be one more than the number of supplies after the do-while loop ends. And
so we need to allocate memory for 'cnt - 1' char pointers. But we are allocating
memory for 'cnt' instead.

Fix this by not over-allocating memory.
Signed-off-by: default avatarViresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: default avatarSebastian Reichel <sre@kernel.org>
parent 86515b7d
......@@ -234,7 +234,7 @@ static int power_supply_check_supplies(struct power_supply *psy)
return -ENOMEM;
}
*psy->supplied_from = devm_kzalloc(psy->dev, sizeof(char *) * cnt,
*psy->supplied_from = devm_kzalloc(psy->dev, sizeof(char *) * (cnt - 1),
GFP_KERNEL);
if (!*psy->supplied_from) {
dev_err(psy->dev, "Couldn't allocate memory for supply list\n");
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment