Skip to contentSkip to conversation

thermal: Fix UUID string comparison in current_uuid_store()

PATCH In review Kaushlendra Kumar 2 participants 4 messages Oct 17, 2025 – Oct 30, 2025 Thermal

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 thermal: Fix UUID string comparison in current_uuid_store()

Use strlen() for UUID matching instead of sizeof() to ensure correct comparison of supported UUIDs. sizeof() returns pointer size instead of actual string length, causing incomplete UUID matching.

---
 drivers/thermal/intel/int340x_thermal/int3400_thermal.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/thermal/intel/int340x_thermal/int3400_thermal.c +1 -1
index 908cc1bf57f1..236003d12dc7 100644
@@ -199,7 +199,7 @@ static ssize_t current_uuid_store(struct device *dev,
 
 	for (i = 0; i < INT3400_THERMAL_MAXIMUM_UUID; ++i) {
 		if (!strncmp(buf, int3400_thermal_uuids[i],
-			     sizeof(int3400_thermal_uuids[i]) - 1)) {
+			     strlen(int3400_thermal_uuids[i]))) {
 			/*
 			 * If we have a list of supported UUIDs, make sure
 			 * this one is supported.
Signature · 1 line
2.34.1
#1 lore raw
Quoted 16 lines · Kaushlendra Kumar

Use strlen() for UUID matching instead of sizeof() to ensure correct comparison of supported UUIDs. sizeof() returns pointer size instead of actual string length, causing incomplete UUID matching.

---
 drivers/thermal/intel/int340x_thermal/int3400_thermal.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/thermal/intel/int340x_thermal/int3400_thermal.c +0 -0
index 908cc1bf57f1..236003d12dc7 100644

drivers/thermal/intel/int340x_thermal/int3400_thermal.c static ssize_t current_uuid_store(struct device *dev, · line 200

Quoted 2 lines
drivers/thermal/intel/int340x_thermal/int3400_thermal.c +0 -0
@@ -199,7 +199,7 @@ static ssize_t current_uuid_store(struct device *dev,
 
        for (i = 0; i < INT3400_THERMAL_MAXIMUM_UUID; ++i) {

Exercise for the reader: Add a printk() here to print sizeof(int3400_thermal_uuids[i]) and see what number gets printed.

Quoted 7 lines
drivers/thermal/intel/int340x_thermal/int3400_thermal.c +1 -2
                if (!strncmp(buf, int3400_thermal_uuids[i],
-                            sizeof(int3400_thermal_uuids[i]) - 1)) {
+                            strlen(int3400_thermal_uuids[i]))) {
                        /*
                         * If we have a list of supported UUIDs, make sure
                         * this one is supported.
--
#2 lore raw
Quoted 20 lines · Rafael J. Wysocki
Quoted 17 lines · Kaushlendra Kumar

Use strlen() for UUID matching instead of sizeof() to ensure correct comparison of supported UUIDs. sizeof() returns pointer size instead of actual string length, causing incomplete UUID matching.

---
 drivers/thermal/intel/int340x_thermal/int3400_thermal.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/thermal/intel/int340x_thermal/int3400_thermal.c +0 -0
index 908cc1bf57f1..236003d12dc7 100644
@@ -199,7 +199,7 @@ static ssize_t current_uuid_store(struct device *dev,
 
Quoted 4 lines

drivers/thermal/intel/int340x_thermal/int3400_thermal.c static ssize_t current_uuid_store(struct device *dev, · line 200

Quoted 1 line
drivers/thermal/intel/int340x_thermal/int3400_thermal.c +0 -0
        for (i = 0; i < INT3400_THERMAL_MAXIMUM_UUID; ++i) {

Exercise for the reader: Add a printk() here to print sizeof(int3400_thermal_uuids[i]) and see what number gets printed.

It is 8, but note that comparing the first 7 characters is practically sufficient to distinguish all of the UUIDs in int3400_thermal_uuids[] from each other.

Also, this change would alter the kernel ABI, possibly confusing users who might notice that the first 7 characters mattered and might start to rely on that.

If you want to clean up that piece of code, please change it to pass a symbol representing the number 7 as the last argument to strncmp(), but that is as much as can be done here.

Quoted 7 lines
Quoted 7 lines
drivers/thermal/intel/int340x_thermal/int3400_thermal.c +1 -2
                if (!strncmp(buf, int3400_thermal_uuids[i],
-                            sizeof(int3400_thermal_uuids[i]) - 1)) {
+                            strlen(int3400_thermal_uuids[i]))) {
                        /*
                         * If we have a list of supported UUIDs, make sure
                         * this one is supported.
--
#3 lore raw
Quoted 3 lines · Rafael J. Wysocki

Also, this change would alter the kernel ABI, possibly confusing users who might notice that the first 7 characters mattered and might start to rely on that.

If you want to clean up that piece of code, please change it to pass a symbol representing the number 7 as the last argument to strncmp(), but that is as much as can be done here.

You're right about the ABI concern. I have sent a v2 patch that uses a symbolic constant for the 7-character comparison to maintain existing behavior

Thanks for the Review!

Kaushlendra