thermal: thermal_of: fix error return code of thermal_of_populate_bind_params()
PATCH v2 1/1 thermal: thermal_of: fix error return code of thermal_of_populate_bind_params()
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.
---
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(-)
drivers/thermal/thermal_of.c +5 -2
@@ -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",
Signature · 1 line
2.17.1
Daniel Lezcano
AppliedQuoted 9 lines · Jia-Ju Bai
When
kcalloc()returns NULL to__tcbporof_count_phandle_with_args()returns zero or-ENOENTto count, no error return code ofthermal_of_populate_bind_params()is assigned.
To fix these bugs, ret is assigned with-ENOMEMand-ENOENTin these cases, respectively.Fixes a92bab8919e3 ("of: thermal: Allow multiple devices to share cooling map")Reported-by TOTE Robot <[email protected]>Signed-off-by Jia-Ju Bai <[email protected]>
Thanks, applied.
Signature · 5 lines
<http://www.linaro.org/> Linaro.org │ Open source software for ARM SoCs Follow Linaro: <http://www.facebook.com/pages/Linaro> Facebook | <http://twitter.com/#!/linaroorg> Twitter | <http://www.linaro.org/linaro-blog/> Blog
[thermal: thermal/next] thermal: thermal_of: Fix error return code of thermal_of_populate_bind_params()
In reply to Jia-Ju BaiThe following commit has been merged into the thermal/next branch of thermal:
The following commit has been merged into the thermal/next branch of thermal:
Commit-ID: 45c7eaeb29d67224db4ba935deb575586a1fda09 Gitweb: https://git.kernel.org/pub/scm/linux/kernel/git/thermal/linux.git//45c7eaeb29d67224db4ba935deb575586a1fda09 Author: Jia-Ju Bai <[email protected]> AuthorDate: Wed, 10 Mar 2021 04:24:23 -08:00 Committer: Daniel Lezcano <[email protected]> CommitterDate: Wed, 10 Mar 2021 13:41:33 +01:00
thermal: thermal_of: Fix error return code of thermal_of_populate_bind_params()
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.
--- drivers/thermal/thermal_of.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
drivers/thermal/thermal_of.c +5 -2
@@ -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",