diff options
| author | Jia-Ju Bai <baijiaju1990@gmail.com> | 2021-03-10 04:24:23 -0800 |
|---|---|---|
| committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2021-05-19 10:08:24 +0200 |
| commit | f49f00dbe3d0b4bd9cb39925ada33709f552fc73 (patch) | |
| tree | 273efdb3b9ca6cf973aeb43df95d2c824ce0ce0b /drivers/thermal | |
| parent | f599960166a0a05507d1f331ba933edcb71e32b7 (diff) | |
| download | linux-f49f00dbe3d0b4bd9cb39925ada33709f552fc73.tar.gz linux-f49f00dbe3d0b4bd9cb39925ada33709f552fc73.tar.bz2 linux-f49f00dbe3d0b4bd9cb39925ada33709f552fc73.zip | |
thermal: thermal_of: Fix error return code of thermal_of_populate_bind_params()
[ Upstream commit 45c7eaeb29d67224db4ba935deb575586a1fda09 ]
When kcalloc() returns NULL to __tcbp or of_count_phandle_with_args()
returns zero or -ENOENT to count, no error return code of
thermal_of_populate_bind_params() is assigned.
To fix these bugs, ret is assigned with -ENOMEM and -ENOENT in these
cases, respectively.
Fixes: a92bab8919e3 ("of: thermal: Allow multiple devices to share cooling map")
Reported-by: TOTE Robot <oslab@tsinghua.edu.cn>
Signed-off-by: Jia-Ju Bai <baijiaju1990@gmail.com>
Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org>
Link: https://lore.kernel.org/r/20210310122423.3266-1-baijiaju1990@gmail.com
Signed-off-by: Sasha Levin <sashal@kernel.org>
Diffstat (limited to 'drivers/thermal')
| -rw-r--r-- | drivers/thermal/of-thermal.c | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/drivers/thermal/of-thermal.c b/drivers/thermal/of-thermal.c index dc5093be553e..68d0c181ec7b 100644 --- a/drivers/thermal/of-thermal.c +++ b/drivers/thermal/of-thermal.c @@ -712,14 +712,17 @@ static int thermal_of_populate_bind_params(struct device_node *np, count = of_count_phandle_with_args(np, "cooling-device", "#cooling-cells"); - if (!count) { + if (count <= 0) { pr_err("Add a cooling_device property with at least one device\n"); + ret = -ENOENT; goto end; } __tcbp = kcalloc(count, sizeof(*__tcbp), GFP_KERNEL); - if (!__tcbp) + if (!__tcbp) { + ret = -ENOMEM; goto end; + } for (i = 0; i < count; i++) { ret = of_parse_phandle_with_args(np, "cooling-device", |
