PM / devfreq: memlat: Remove kfree() on probe fails
Memory allocated with devm_kzalloc() is automatically freed if
the probe function fails and returns an error code. So there
is no need to free cpu_grp explicitly for the failure cases
that might come up after it is allocated. Additionally calls to
devm_kzalloc() must be accompanied by devm_kfree() if memory
deallocation is necessary.
For these reasons remove the kfree(cpu_grp) from the probe
function.
Change-Id: Ic4838fd58d40d283ac301facc64b06813eb3bd7d
Signed-off-by: Rohit Gupta <rohgup@codeaurora.org>
diff --git a/drivers/devfreq/arm-memlat-mon.c b/drivers/devfreq/arm-memlat-mon.c
index 370d7d9..4fb0a5f 100644
--- a/drivers/devfreq/arm-memlat-mon.c
+++ b/drivers/devfreq/arm-memlat-mon.c
@@ -311,19 +311,19 @@
hw->of_node = of_parse_phandle(dev->of_node, "qcom,target-dev", 0);
if (!hw->of_node) {
dev_err(dev, "Couldn't find a target device\n");
- goto err_out;
+ return -ENODEV;
}
if (get_mask_from_dev_handle(pdev, &cpu_grp->cpus)) {
dev_err(dev, "CPU list is empty\n");
- goto err_out;
+ return -ENODEV;
}
hw->num_cores = cpumask_weight(&cpu_grp->cpus);
hw->core_stats = devm_kzalloc(dev, hw->num_cores *
sizeof(*(hw->core_stats)), GFP_KERNEL);
if (!hw->core_stats)
- goto err_out;
+ return -ENOMEM;
for_each_cpu(cpu, &cpu_grp->cpus)
hw->core_stats[cpu - cpumask_first(&cpu_grp->cpus)].id = cpu;
@@ -335,14 +335,10 @@
ret = register_memlat(dev, hw);
if (ret) {
pr_err("Mem Latency Gov registration failed\n");
- goto err_out;
+ return ret;
}
return 0;
-
-err_out:
- kfree(cpu_grp);
- return -EINVAL;
}
static struct of_device_id match_table[] = {