Skip to contentSkip to conversation

thermal: int340x: delete bogus length check

PATCH Applied Dan Carpenter 2 participants 2 messages Sep 30, 2021 – Oct 5, 2021

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 thermal: int340x: delete bogus length check

This check has a signedness bug and does not work. If "length" is larger than "PAGE_SIZE" then "PAGE_SIZE - length" is not negative but instead it is a large unsigned value. Fortunately, Takashi Iwai changed this code to use scnprint() instead of snprintf() so now "length" is never larger than "PAGE_SIZE - 1" and the check can be removed.

---
 drivers/thermal/intel/int340x_thermal/int3400_thermal.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)
drivers/thermal/intel/int340x_thermal/int3400_thermal.c +4 -5
index 19926beeb3b7..8502b7d8df89 100644
@@ -129,11 +129,10 @@ static ssize_t available_uuids_show(struct device *dev,
 
 	for (i = 0; i < INT3400_THERMAL_MAXIMUM_UUID; i++) {
 		if (priv->uuid_bitmap & (1 << i))
-			if (PAGE_SIZE - length > 0)
-				length += scnprintf(&buf[length],
-						   PAGE_SIZE - length,
-						   "%s\n",
-						   int3400_thermal_uuids[i]);
+			length += scnprintf(&buf[length],
+					    PAGE_SIZE - length,
+					    "%s\n",
+					    int3400_thermal_uuids[i]);
 	}
 
 	return length;
Signature · 1 line
2.20.1
maintainer Applied
#1 lore raw
Quoted 24 lines · Dan Carpenter

This check has a signedness bug and does not work. If "length" is larger than "PAGE_SIZE" then "PAGE_SIZE - length" is not negative but instead it is a large unsigned value. Fortunately, Takashi Iwai changed this code to use scnprint() instead of snprintf() so now "length" is never larger than "PAGE_SIZE - 1" and the check can be removed.

---
 drivers/thermal/intel/int340x_thermal/int3400_thermal.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)
drivers/thermal/intel/int340x_thermal/int3400_thermal.c +0 -3
index 19926beeb3b7..8502b7d8df89 100644
@@ -129,11 +129,10 @@ static ssize_t available_uuids_show(struct device *dev,
 
        for (i = 0; i < INT3400_THERMAL_MAXIMUM_UUID; i++) {
                if (priv->uuid_bitmap & (1 << i))
-                       if (PAGE_SIZE - length > 0)
-                               length += scnprintf(&buf[length],
-                                                  PAGE_SIZE - length,

drivers/thermal/intel/int340x_thermal/int3400_thermal.c static ssize_t available_uuids_show(struct device *dev,

Quoted 10 lines
drivers/thermal/intel/int340x_thermal/int3400_thermal.c +4 -3
-                                                  "%s\n",
-                                                  int3400_thermal_uuids[i]);
+                       length += scnprintf(&buf[length],
+                                           PAGE_SIZE - length,
+                                           "%s\n",
+                                           int3400_thermal_uuids[i]);
        }
 
        return length;
--

Applied as 5.16 material, thanks!