Skip to contentSkip to conversation

Thermal/int340x: _art and _trt fixes

PATCH Applied Ilkka Koskinen 2 participants 6 messages Dec 9, 2014 Thermal

lore
Share & tools
lore
#3 lore raw

PATCH 2/2 Thermal/int340x: Handle properly the case when _trt or _art acpi entry is missing

In reply to Ilkka Koskinen

If either of the entries was missing, the driver tried to free memory using uninitialized pointer. In addition, it was dereferencing null pointer.

---
 drivers/thermal/int340x_thermal/acpi_thermal_rel.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/thermal/int340x_thermal/acpi_thermal_rel.c +4 -4
index e4e61b3..ee4ed3b 100644
@@ -82,7 +82,7 @@ int acpi_parse_trt(acpi_handle handle, int *trt_count, struct trt **trtp,
 	struct acpi_buffer trt_format = { sizeof("RRNNNNNN"), "RRNNNNNN" };
 
 	if (!acpi_has_method(handle, "_TRT"))
-		return 0;
+		return -EEXIST;
 
 	status = acpi_evaluate_object(handle, "_TRT", NULL, &buffer);
 	if (ACPI_FAILURE(status))
@@ -167,7 +167,7 @@ int acpi_parse_art(acpi_handle handle, int *art_count, struct art **artp,
 		sizeof("RRNNNNNNNNNNN"), "RRNNNNNNNNNNN" };
 
 	if (!acpi_has_method(handle, "_ART"))
-		return 0;
+		return -EEXIST;
 
 	status = acpi_evaluate_object(handle, "_ART", NULL, &buffer);
 	if (ACPI_FAILURE(status))
@@ -321,8 +321,8 @@ static long acpi_thermal_rel_ioctl(struct file *f, unsigned int cmd,
 	unsigned long length = 0;
 	int count = 0;
 	char __user *arg = (void __user *)__arg;
-	struct trt *trts;
-	struct art *arts;
+	struct trt *trts = NULL;
+	struct art *arts = NULL;
 
 	switch (cmd) {
 	case ACPI_THERMAL_GET_TRT_COUNT:
Signature · 1 line
1.9.1
#0 lore raw

cover Thermal/int340x: _art and _trt fixes

This patch set fixes two issues in parsing _art and _trt acpi entries

Ilkka Koskinen (2):
Thermal/int340x: Clear the error value of the last
acpi_bus_get_device() call
Thermal/int340x: Handle properly the case when _trt or _art acpi entry
is missing

 drivers/thermal/int340x_thermal/acpi_thermal_rel.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)
Signature · 1 line
1.9.1
#1 lore raw

PATCH 1/2 Thermal/int340x: Clear the error value of the last acpi_bus_get_device() call

Previously the return value of the last acpi_bus_get_device() was returned. However, since we only report those issues, it should be cleared to continue as expected.

---
 drivers/thermal/int340x_thermal/acpi_thermal_rel.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/thermal/int340x_thermal/acpi_thermal_rel.c +2 -0
index ac5c405..e4e61b3 100644
@@ -131,6 +131,8 @@ int acpi_parse_trt(acpi_handle handle, int *trt_count, struct trt **trtp,
 			pr_warn("Failed to get target ACPI device\n");
 	}
 
+	result = 0;
+
 	*trtp = trts;
 	/* don't count bad entries */
 	*trt_count -= nr_bad_entries;
Signature · 1 line
1.9.1
reviewer
#4 lore raw

Re: [PATCH 2/2] Thermal/int340x: Handle properly the case when _trt or _art acpi entry is missing

In reply to Ilkka Koskinen
Quoted 15 lines · Ilkka Koskinen

If either of the entries was missing, the driver tried to free memory using uninitialized pointer. In addition, it was dereferencing null pointer.

---
 drivers/thermal/int340x_thermal/acpi_thermal_rel.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/thermal/int340x_thermal/acpi_thermal_rel.c +0 -0
index e4e61b3..ee4ed3b 100644

drivers/thermal/int340x_thermal/acpi_thermal_rel.c int acpi_parse_trt(acpi_handle handle, int *trt_count, struct trt **trtp, · line 86

Quoted 6 lines
drivers/thermal/int340x_thermal/acpi_thermal_rel.c +1 -1
@@ -82,7 +82,7 @@ int acpi_parse_trt(acpi_handle handle, int *trt_count, struct trt **trtp,
 	struct acpi_buffer trt_format = { sizeof("RRNNNNNN"), "RRNNNNNN" };
 
 	if (!acpi_has_method(handle, "_TRT"))
-		return 0;
+		return -EEXIST;
 

If the control method does not exist, shouldn't we return -ENODEV or -ENOENT instead?

thanks,
rui

Quoted 22 lines
drivers/thermal/int340x_thermal/acpi_thermal_rel.c +3 -3
 	status = acpi_evaluate_object(handle, "_TRT", NULL, &buffer);
 	if (ACPI_FAILURE(status))
@@ -167,7 +167,7 @@ int acpi_parse_art(acpi_handle handle, int *art_count, struct art **artp,
 		sizeof("RRNNNNNNNNNNN"), "RRNNNNNNNNNNN" };
 
 	if (!acpi_has_method(handle, "_ART"))
-		return 0;
+		return -EEXIST;
 
 	status = acpi_evaluate_object(handle, "_ART", NULL, &buffer);
 	if (ACPI_FAILURE(status))
@@ -321,8 +321,8 @@ static long acpi_thermal_rel_ioctl(struct file *f, unsigned int cmd,
 	unsigned long length = 0;
 	int count = 0;
 	char __user *arg = (void __user *)__arg;
-	struct trt *trts;
-	struct art *arts;
+	struct trt *trts = NULL;
+	struct art *arts = NULL;
 
 	switch (cmd) {
 	case ACPI_THERMAL_GET_TRT_COUNT:
reviewer Applied
#2 lore raw

Re: [PATCH 1/2] Thermal/int340x: Clear the error value of the last acpi_bus_get_device() call

In reply to Ilkka Koskinen
Quoted 6 lines · Ilkka Koskinen

Previously the return value of the last acpi_bus_get_device() was returned. However, since we only report those issues, it should be cleared to continue as expected.

applied.

thanks,
rui

Quoted 17 lines
---
 drivers/thermal/int340x_thermal/acpi_thermal_rel.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/thermal/int340x_thermal/acpi_thermal_rel.c +2 -0
index ac5c405..e4e61b3 100644
@@ -131,6 +131,8 @@ int acpi_parse_trt(acpi_handle handle, int *trt_count, struct trt **trtp,
 			pr_warn("Failed to get target ACPI device\n");
 	}
 
+	result = 0;
+
 	*trtp = trts;
 	/* don't count bad entries */
 	*trt_count -= nr_bad_entries;
#5 lore raw

Re: [PATCH 2/2] Thermal/int340x: Handle properly the case when _trt or _art acpi entry is missing

In reply to Zhang Rui
Quoted 20 lines · Zhang Rui
Quoted 19 lines · Ilkka Koskinen

If either of the entries was missing, the driver tried to free memory using uninitialized pointer. In addition, it was dereferencing null pointer.

---
 drivers/thermal/int340x_thermal/acpi_thermal_rel.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/thermal/int340x_thermal/acpi_thermal_rel.c +0 -0
index e4e61b3..ee4ed3b 100644
@@ -82,7 +82,7 @@ int acpi_parse_trt(acpi_handle handle, int *trt_count,
 struct trt **trtp,
 	struct acpi_buffer trt_format = { sizeof("RRNNNNNN"), "RRNNNNNN" };
 
Quoted 6 lines

drivers/thermal/int340x_thermal/acpi_thermal_rel.c int acpi_parse_trt(acpi_handle handle, int *trt_count, struct trt **trtp, · line 86

Quoted 4 lines
drivers/thermal/int340x_thermal/acpi_thermal_rel.c +1 -1
 	if (!acpi_has_method(handle, "_TRT"))
-		return 0;
+		return -EEXIST;
 

If the control method does not exist, shouldn't we return -ENODEV or -ENOENT instead?

Absolutely! I wonder why I had chosen that one. I change them to -ENODEV and submit a new version of this patch.

Cheers, Ilkka

Quoted 2 lines

thanks,
rui