summaryrefslogtreecommitdiff
path: root/drivers/thermal/qcom
diff options
context:
space:
mode:
authorPeng Hao <peng.hao2@zte.com.cn>2019-02-13 22:53:29 +0800
committerEduardo Valentin <edubezval@gmail.com>2019-02-20 17:23:39 -0800
commita245b62be3f0274114df49a8b5481be6383b314f (patch)
tree9a649d393ff30e1a914960905508ca2ae455ef4f /drivers/thermal/qcom
parent76b1ae8698d63a15000068057ccae38ec763baaa (diff)
thermal/qcom/tsens-common : fix possible object reference leak
of_find_device_by_node() takes a reference to the struct device when it finds a match via get_device. We also should make sure to drop the reference to the device taken by of_find_device_by_node() when returning error. Signed-off-by: Peng Hao <peng.hao2@zte.com.cn> Signed-off-by: Eduardo Valentin <edubezval@gmail.com>
Diffstat (limited to 'drivers/thermal/qcom')
-rw-r--r--drivers/thermal/qcom/tsens-common.c33
1 files changed, 23 insertions, 10 deletions
diff --git a/drivers/thermal/qcom/tsens-common.c b/drivers/thermal/qcom/tsens-common.c
index 78652cac7f3d..f80c73f11740 100644
--- a/drivers/thermal/qcom/tsens-common.c
+++ b/drivers/thermal/qcom/tsens-common.c
@@ -144,13 +144,17 @@ int __init init_common(struct tsens_device *tmdev)
tmdev->tm_offset = 0;
res = platform_get_resource(op, IORESOURCE_MEM, 1);
srot_base = devm_ioremap_resource(&op->dev, res);
- if (IS_ERR(srot_base))
- return PTR_ERR(srot_base);
+ if (IS_ERR(srot_base)) {
+ ret = PTR_ERR(srot_base);
+ goto err_put_device;
+ }
tmdev->srot_map = devm_regmap_init_mmio(tmdev->dev, srot_base,
&tsens_srot_config);
- if (IS_ERR(tmdev->srot_map))
- return PTR_ERR(tmdev->srot_map);
+ if (IS_ERR(tmdev->srot_map)) {
+ ret = PTR_ERR(tmdev->srot_map);
+ goto err_put_device;
+ }
} else {
/* old DTs where SROT and TM were in a contiguous 2K block */
@@ -159,22 +163,31 @@ int __init init_common(struct tsens_device *tmdev)
res = platform_get_resource(op, IORESOURCE_MEM, 0);
tm_base = devm_ioremap_resource(&op->dev, res);
- if (IS_ERR(tm_base))
- return PTR_ERR(tm_base);
+ if (IS_ERR(tm_base)) {
+ ret = PTR_ERR(tm_base);
+ goto err_put_device;
+ }
tmdev->tm_map = devm_regmap_init_mmio(tmdev->dev, tm_base, &tsens_config);
- if (IS_ERR(tmdev->tm_map))
- return PTR_ERR(tmdev->tm_map);
+ if (IS_ERR(tmdev->tm_map)) {
+ ret = PTR_ERR(tmdev->tm_map);
+ goto err_put_device;
+ }
if (tmdev->srot_map) {
ret = regmap_read(tmdev->srot_map, ctrl_offset, &code);
if (ret)
- return ret;
+ goto err_put_device;
if (!(code & TSENS_EN)) {
dev_err(tmdev->dev, "tsens device is not enabled\n");
- return -ENODEV;
+ ret = -ENODEV;
+ goto err_put_device;
}
}
return 0;
+
+err_put_device:
+ put_device(&op->dev);
+ return ret;
}