All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] thermal: thermal_of: fix error return code of thermal_of_populate_bind_params()
@ 2021-03-10 12:24 Jia-Ju Bai
  2021-03-10 12:42 ` Daniel Lezcano
  2021-03-17 12:39 ` [thermal: thermal/next] thermal: thermal_of: Fix " thermal-bot for Jia-Ju Bai
  0 siblings, 2 replies; 3+ messages in thread
From: Jia-Ju Bai @ 2021-03-10 12:24 UTC (permalink / raw)
  To: rui.zhang, daniel.lezcano, amitk; +Cc: linux-pm, linux-kernel, Jia-Ju Bai

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(-)

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",
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH v2] thermal: thermal_of: fix error return code of thermal_of_populate_bind_params()
  2021-03-10 12:24 [PATCH v2] thermal: thermal_of: fix error return code of thermal_of_populate_bind_params() Jia-Ju Bai
@ 2021-03-10 12:42 ` Daniel Lezcano
  2021-03-17 12:39 ` [thermal: thermal/next] thermal: thermal_of: Fix " thermal-bot for Jia-Ju Bai
  1 sibling, 0 replies; 3+ messages in thread
From: Daniel Lezcano @ 2021-03-10 12:42 UTC (permalink / raw)
  To: Jia-Ju Bai, rui.zhang, amitk; +Cc: linux-pm, linux-kernel

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.

-- 
<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

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [thermal: thermal/next] thermal: thermal_of: Fix error return code of thermal_of_populate_bind_params()
  2021-03-10 12:24 [PATCH v2] thermal: thermal_of: fix error return code of thermal_of_populate_bind_params() Jia-Ju Bai
  2021-03-10 12:42 ` Daniel Lezcano
@ 2021-03-17 12:39 ` thermal-bot for Jia-Ju Bai
  1 sibling, 0 replies; 3+ messages in thread
From: thermal-bot for Jia-Ju Bai @ 2021-03-17 12:39 UTC (permalink / raw)
  To: linux-pm; +Cc: TOTE Robot, Jia-Ju Bai, Daniel Lezcano, rui.zhang, amitk

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 <baijiaju1990@gmail.com>
AuthorDate:    Wed, 10 Mar 2021 04:24:23 -08:00
Committer:     Daniel Lezcano <daniel.lezcano@linaro.org>
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.

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

diff --git a/drivers/thermal/thermal_of.c b/drivers/thermal/thermal_of.c
index 69ef12f..5b76f9a 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",

^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-03-17 12:40 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-10 12:24 [PATCH v2] thermal: thermal_of: fix error return code of thermal_of_populate_bind_params() Jia-Ju Bai
2021-03-10 12:42 ` Daniel Lezcano
2021-03-17 12:39 ` [thermal: thermal/next] thermal: thermal_of: Fix " thermal-bot for Jia-Ju Bai

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.