Skip to content

Commit

Permalink
thermal/drivers/cpuidle_cooling: Fix use after error
Browse files Browse the repository at this point in the history
When the function successfully finishes it logs an information about
the registration of the cooling device and use its name to build the
message. Unfortunately it was freed right before:

drivers/thermal/cpuidle_cooling.c:218 __cpuidle_cooling_register()
	warn: 'name' was already freed.

Fix this by freeing after the message happened.

Fixes: 6fd1b18 ("thermal/drivers/cpuidle_cooling: Use device name instead of auto-numbering")
Reported-by: Dan Carpenter <[email protected]>
Signed-off-by: Daniel Lezcano <[email protected]>
Acked-by: Viresh Kumar <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
  • Loading branch information
dlezcano committed Apr 15, 2021
1 parent 9aa80ab commit 6cc7b38
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions drivers/thermal/cpuidle_cooling.c
Original file line number Diff line number Diff line change
Expand Up @@ -208,18 +208,20 @@ static int __cpuidle_cooling_register(struct device_node *np,

cdev = thermal_of_cooling_device_register(np, name, idle_cdev,
&cpuidle_cooling_ops);
kfree(name);

if (IS_ERR(cdev)) {
ret = PTR_ERR(cdev);
goto out_unregister;
goto out_kfree_name;
}

pr_debug("%s: Idle injection set with idle duration=%u, latency=%u\n",
name, idle_duration_us, latency_us);

kfree(name);

return 0;

out_kfree_name:
kfree(name);
out_unregister:
idle_inject_unregister(ii_dev);
out_kfree:
Expand Down

0 comments on commit 6cc7b38

Please sign in to comment.