Skip to contentSkip to conversation

thermal: Constify 'type' argument for the registration routine

PATCH In review Anton Vorontsov 4 participants 4 messages Jun 18, 2012 – Jun 20, 2012 Thermal

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 thermal: Constify 'type' argument for the registration routine

thermal_zone_device_register() does not modify 'type' argument, so it is safe to declare it as const. Otherwise, if we pass a const string, we are getting the ugly warning:

CC drivers/power/power_supply_core.o
drivers/power/power_supply_core.c: In function 'psy_register_thermal':
drivers/power/power_supply_core.c:204:6: warning: passing argument 1 of ‘thermal_zone_device_register’ discards 'const' qualifier from pointer target type [enabled by default] include/linux/thermal.h:140:29: note: expected 'char *' but argument is of type 'const char *'

---
 drivers/thermal/thermal_sys.c |    2 +-
 include/linux/thermal.h       |    3 ++-
 2 files changed, 3 insertions(+), 2 deletions(-)
drivers/thermal/thermal_sys.c +1 -1
index 022bacb..3bf68c9 100644
@@ -1106,7 +1106,7 @@ EXPORT_SYMBOL(thermal_zone_device_update);
  * longer needed. The passive cooling formula uses tc1 and tc2 as described in
  * section 11.1.5.1 of the ACPI specification 3.0.
  */
-struct thermal_zone_device *thermal_zone_device_register(char *type,
+struct thermal_zone_device *thermal_zone_device_register(const char *type,
 	int trips, void *devdata,
 	const struct thermal_zone_device_ops *ops,
 	int tc1, int tc2, int passive_delay, int polling_delay)
include/linux/thermal.h +2 -1
index 796f1ff..ef75757 100644
@@ -137,7 +137,8 @@ enum {
 };
 #define THERMAL_GENL_CMD_MAX (__THERMAL_GENL_CMD_MAX - 1)
 
-struct thermal_zone_device *thermal_zone_device_register(char *, int, void *,
+struct thermal_zone_device *
+thermal_zone_device_register(const char *, int, void *,
 		const struct thermal_zone_device_ops *, int tc1, int tc2,
 		int passive_freq, int polling_freq);
 void thermal_zone_device_unregister(struct thermal_zone_device *);
Signature · 1 line
1.7.10.4
Acked-by on v1 1/1
#1 lore raw
Quoted 33 lines · Anton Vorontsov

thermal_zone_device_register() does not modify 'type' argument, so it is safe to declare it as const. Otherwise, if we pass a const string, we are getting the ugly warning:

CC drivers/power/power_supply_core.o
drivers/power/power_supply_core.c: In function 'psy_register_thermal':
drivers/power/power_supply_core.c:204:6: warning: passing argument 1 of ‘thermal_zone_device_register’ discards 'const' qualifier from pointer target type [enabled by default] include/linux/thermal.h:140:29: note: expected 'char *' but argument is of type 'const char *'

---
 drivers/thermal/thermal_sys.c |    2 +-
 include/linux/thermal.h       |    3 ++-
 2 files changed, 3 insertions(+), 2 deletions(-)
drivers/thermal/thermal_sys.c +1 -1
index 022bacb..3bf68c9 100644
@@ -1106,7 +1106,7 @@ EXPORT_SYMBOL(thermal_zone_device_update);
  * longer needed. The passive cooling formula uses tc1 and tc2 as described in
  * section 11.1.5.1 of the ACPI specification 3.0.
  */
-struct thermal_zone_device *thermal_zone_device_register(char *type,
+struct thermal_zone_device *thermal_zone_device_register(const char *type,
 	int trips, void *devdata,
 	const struct thermal_zone_device_ops *ops,
 	int tc1, int tc2, int passive_delay, int polling_delay)
include/linux/thermal.h +0 -0
index 796f1ff..ef75757 100644

include/linux/thermal.h enum { · line 144

Quoted 9 lines
include/linux/thermal.h +2 -1
@@ -137,7 +137,8 @@ enum {
 };
 #define THERMAL_GENL_CMD_MAX (__THERMAL_GENL_CMD_MAX - 1)
 
-struct thermal_zone_device *thermal_zone_device_register(char *, int, void *,
+struct thermal_zone_device *
+thermal_zone_device_register(const char *, int, void *,
 		const struct thermal_zone_device_ops *, int tc1, int tc2,
 		int passive_freq, int polling_freq);
 void thermal_zone_device_unregister(struct thermal_zone_device *);
Signature · 1 line
Jean Delvare
#2 lore raw
In reply to Anton Vorontsov
Quoted 6 lines · On Sun, 17 Jun 2012 21:50:37 -0700 Anton Vorontsov…

thermal_zone_device_register() does not modify 'type' argument, so it is safe to declare it as const. Otherwise, if we pass a const string, we are getting the ugly warning:

...

For some reason I can't apply this. I typed it in again and it seems to work OK. I'll assume that someone else will merge it into whatever-tree-broke.

include/linux/thermal.h enum { · line 144

Quoted 12 lines
include/linux/thermal.h +2 -1
@@ -137,7 +137,8 @@ enum {
 };
 #define THERMAL_GENL_CMD_MAX (__THERMAL_GENL_CMD_MAX - 1)
 
-struct thermal_zone_device *thermal_zone_device_register(char *, int, void *,
+struct thermal_zone_device *
+thermal_zone_device_register(const char *, int, void *,
 		const struct thermal_zone_device_ops *, int tc1, int tc2,
 		int passive_freq, int polling_freq);
 void thermal_zone_device_unregister(struct thermal_zone_device *);

Personally, I prefer it when the arguments are named in the declaration
- if you ever have reason to *read* the thing, the lack of names is quite maddening. Particularly when the function has 72 arguments.

But naming some of them and not others is just daft.

#3 lore raw
Quoted 11 lines · Andrew Morton
Quoted 6 lines · On Sun, 17 Jun 2012 21:50:37 -0700 Anton Vorontsov…

thermal_zone_device_register() does not modify 'type' argument, so it is safe to declare it as const. Otherwise, if we pass a const string, we are getting the ugly warning:

...

For some reason I can't apply this.

The reason is the same patch in ACPI tree that "broke" battery tree; we're just touching the same lines of code and that causes some pain.

Quoted 3 lines

I typed it in again and it seems
to work OK. I'll assume that someone else will merge it into whatever-tree-broke.

Len, will you merge this patch? Or should I take it into battery tree? (If I'm taking it, then Stephen will have to resolve some conflicts upon next -next tree generation.)

Quoted 9 lines

include/linux/thermal.h enum { · line 144

Quoted 5 lines
include/linux/thermal.h +2 -0
+struct thermal_zone_device *
+thermal_zone_device_register(const char *, int, void *,
 		const struct thermal_zone_device_ops *, int tc1, int tc2,
 		int passive_freq, int polling_freq);
 void thermal_zone_device_unregister(struct thermal_zone_device *);

Personally, I prefer it when the arguments are named in the declaration
- if you ever have reason to *read* the thing, the lack of names is quite maddening. Particularly when the function has 72 arguments.

:-)

Signature · 2 lines
Anton Vorontsov
Email: [email protected]