Skip to contentSkip to conversation

thermal: cut the spaces when user sets policy

PATCH Superseded Andy Shevchenko 2 participants 3 messages May 3, 2013 – May 6, 2013 Thermal

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 thermal: cut the spaces when user sets policy

Setting policy results in invalid value error.
% echo "step_wise" > policy
% echo: write error: Invalid argument

Need clean up of the buffer which "echo" may add based on the arguments, before comparing aganist list of governor names.

---
 drivers/thermal/thermal_core.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/thermal/thermal_core.c +2 -1
index d755440..a637be5 100644
@@ -33,6 +33,7 @@
 #include <linux/idr.h>
 #include <linux/thermal.h>
 #include <linux/reboot.h>
+#include <linux/string.h>
 #include <net/netlink.h>
 #include <net/genetlink.h>
 
@@ -716,7 +717,7 @@ policy_store(struct device *dev, struct device_attribute *attr,
 
 	mutex_lock(&thermal_governor_lock);
 
-	gov = __find_governor(buf);
+	gov = __find_governor(strim(buf));
 	if (!gov)
 		goto exit;
 
Signature · 1 line
1.8.2.rc0.22.gb3600c3
#1 lore raw

Andy,

Quoted 26 lines · Andy Shevchenko

Setting policy results in invalid value error.
% echo "step_wise" > policy
% echo: write error: Invalid argument

Need clean up of the buffer which "echo" may add based on the arguments, before comparing aganist list of governor names.

---
 drivers/thermal/thermal_core.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/thermal/thermal_core.c +1 -0
index d755440..a637be5 100644
@@ -33,6 +33,7 @@
 #include <linux/idr.h>
 #include <linux/thermal.h>
 #include <linux/reboot.h>
+#include <linux/string.h>
 #include <net/netlink.h>
 #include <net/genetlink.h>
 

drivers/thermal/thermal_core.c policy_store(struct device *dev, struct device_attribute *attr, · line 720

Quoted 5 lines
drivers/thermal/thermal_core.c +1 -1
@@ -716,7 +717,7 @@ policy_store(struct device *dev, struct device_attribute *attr,
 
 	mutex_lock(&thermal_governor_lock);
 
-	gov = __find_governor(buf);
+	gov = __find_governor(strim(buf));

I am much happier with this approach, much cleaner and does the job. On the other hand, this patch introduces a compilation warning that we want to avoid:
drivers/thermal/thermal_sys.c: In function 'policy_store':
drivers/thermal/thermal_sys.c:708: warning: passing argument 1 of 'strim' discards qualifiers from pointer target type include/linux/string.h:63: note: expected 'char *' but argument is of type 'const char *'

Quoted 4 lines
drivers/thermal/thermal_core.c +0 -0
 	if (!gov)
 		goto exit;
 
#2 lore raw
Quoted 12 lines · Eduardo Valentin
Quoted 11 lines · Andy Shevchenko

Setting policy results in invalid value error.
% echo "step_wise" > policy
% echo: write error: Invalid argument

Need clean up of the buffer which "echo" may add based on the arguments, before comparing aganist list of governor names.

drivers/thermal/thermal_core.c +0 -0
@@ -716,7 +717,7 @@ policy_store(struct device *dev, struct device_attribute *attr,
 
 	mutex_lock(&thermal_governor_lock);
 
Quoted 12 lines

drivers/thermal/thermal_core.c policy_store(struct device *dev, struct device_attribute *attr, · line 720

Quoted 2 lines
drivers/thermal/thermal_core.c +1 -1
-	gov = __find_governor(buf);
+	gov = __find_governor(strim(buf));

I am much happier with this approach, much cleaner and does the job. On the other hand, this patch introduces a compilation warning that we want to avoid:
drivers/thermal/thermal_sys.c: In function 'policy_store':
drivers/thermal/thermal_sys.c:708: warning: passing argument 1 of 'strim' discards qualifiers from pointer target type include/linux/string.h:63: note: expected 'char *' but argument is of type 'const char *'

Oops.
What about introduce temporary variable and pass it as a parameter? It seems explicit casting looks not good, though it makes the job.

Signature · 2 lines
Andy Shevchenko <[email protected]>
Intel Finland Oy