Skip to contentSkip to conversation

hwmon: put HWMON_CHANNEL_INFO() initializers in rodata

PATCH Applied Jani Nikula 2 participants 2 messages Jan 17, 2024 Hardware monitoring

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 hwmon: put HWMON_CHANNEL_INFO() initializers in rodata

HWMON_CHANNEL_INFO() is supposed to be used as initializer for arrays of const struct hwmon_channel_info *. However, without explicit const, HWMON_CHANNEL_INFO() creates mutable compound literals, and the const pointers point at the mutable data. Add const to place the data in rodata.

Cc Jean Delvare <[email protected]>
Cc Guenter Roeck <[email protected]>
---
 include/linux/hwmon.h | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
include/linux/hwmon.h +6 -6
index 8cd6a6b33593..c2c0da18dfa3 100644
@@ -425,12 +425,12 @@ struct hwmon_channel_info {
 	const u32 *config;
 };
 
-#define HWMON_CHANNEL_INFO(stype, ...)	\
-	(&(struct hwmon_channel_info) {	\
-		.type = hwmon_##stype,	\
-		.config = (u32 []) {	\
-			__VA_ARGS__, 0	\
-		}			\
+#define HWMON_CHANNEL_INFO(stype, ...)		\
+	(&(const struct hwmon_channel_info) {	\
+		.type = hwmon_##stype,		\
+		.config = (const u32 []) {	\
+			__VA_ARGS__, 0		\
+		}				\
 	})
 
 /**
Signature · 1 line
2.39.2
maintainer Applied
#1 lore raw
Quoted 9 lines · Jani Nikula

HWMON_CHANNEL_INFO() is supposed to be used as initializer for arrays of const struct hwmon_channel_info *. However, without explicit const, HWMON_CHANNEL_INFO() creates mutable compound literals, and the const pointers point at the mutable data. Add const to place the data in rodata.

Cc Jean Delvare <[email protected]>
Cc Guenter Roeck <[email protected]>

Applied.

Thanks,
Guenter