Skip to contentSkip to conversation

thermal: thermal_core: policy store via sysfs is broken

PATCH New Shawn Guo 2 participants 2 messages Jun 3, 2013 Thermal

lore
Share & tools
lore

Shawn Guo

author
#0 lore raw

PATCH 1/1 thermal: thermal_core: policy store via sysfs is broken

When function __find_governor() gets called from policy_store(), the argument 'buf' has a '\n' character at the end. This causes strnicmp() mismatches all the time. Consequently, policy_store() will always return -EINVAL, and hence the policy store via sysfs will always fail even when users store a correct policy name.

Fix the problem by using strncasecmp() for policy name matching in __find_governor().

---
 drivers/thermal/thermal_core.c |    5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/thermal/thermal_core.c +3 -2
index d755440..6ba869f 100644
@@ -57,9 +57,10 @@ static struct thermal_governor *__find_governor(const char *name)
 {
 	struct thermal_governor *pos;
 
-	list_for_each_entry(pos, &thermal_governor_list, governor_list)
-		if (!strnicmp(name, pos->name, THERMAL_NAME_LENGTH))
+	list_for_each_entry(pos, &thermal_governor_list, governor_list) {
+		if (!strncasecmp(name, pos->name, strlen(pos->name)))
 			return pos;
+	}
 
 	return NULL;
 }
Signature · 1 line
1.7.9.5
#1 lore raw

PATCH 1/1 thermal: thermal_core: policy store via sysfs is broken

Shawn,

Quoted 9 lines · Shawn Guo

When function __find_governor() gets called from policy_store(), the argument 'buf' has a '\n' character at the end. This causes strnicmp() mismatches all the time. Consequently, policy_store() will always return -EINVAL, and hence the policy store via sysfs will always fail even when users store a correct policy name.

Fix the problem by using strncasecmp() for policy name matching in __find_governor().

Thanks for your patch, but Andy has fixed this issue already here:

http://git.kernel.org/cgit/linux/kernel/git/rzhang/linux.git/commit/?h=next&id=42a5bf507d7f7ecbf606eb392dd9d2e4d009c36b

Patch is present in thermal/next.

Quoted 23 lines
---
 drivers/thermal/thermal_core.c |    5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/thermal/thermal_core.c +3 -2
index d755440..6ba869f 100644
@@ -57,9 +57,10 @@ static struct thermal_governor *__find_governor(const char *name)
 {
 	struct thermal_governor *pos;
 
-	list_for_each_entry(pos, &thermal_governor_list, governor_list)
-		if (!strnicmp(name, pos->name, THERMAL_NAME_LENGTH))
+	list_for_each_entry(pos, &thermal_governor_list, governor_list) {
+		if (!strncasecmp(name, pos->name, strlen(pos->name)))
 			return pos;
+	}
 
 	return NULL;
 }
Signature · 11 lines
You have got to be excited about what you are doing. (L. Lamport)

Eduardo Valentin

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 295 bytes
Desc: OpenPGP digital signature
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20130603/85efb595/attachment.sig>