diff mbox series

[v2] thermal: thermal_of: fix error return code of thermal_of_populate_bind_params()

Message ID 20210310122423.3266-1-baijiaju1990@gmail.com (mailing list archive)
State New, archived
Delegated to: Daniel Lezcano
Headers show
Series [v2] thermal: thermal_of: fix error return code of thermal_of_populate_bind_params() | expand

Commit Message

Jia-Ju Bai March 10, 2021, 12:24 p.m. UTC
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>
---
v2:
* Add the fixing about of_count_phandle_with_args() and the fixes tag.
  Thank Daniel Lezcano for good advice.

---
 drivers/thermal/thermal_of.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

Comments

Daniel Lezcano March 10, 2021, 12:42 p.m. UTC | #1
On 10/03/2021 13:24, Jia-Ju Bai wrote:
> 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>

Thanks, applied.
diff mbox series

Patch

diff --git a/drivers/thermal/thermal_of.c b/drivers/thermal/thermal_of.c
index 69ef12f852b7..5b76f9a1280d 100644
--- a/drivers/thermal/thermal_of.c
+++ b/drivers/thermal/thermal_of.c
@@ -704,14 +704,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",