diff mbox series

hwmon: put HWMON_CHANNEL_INFO() initializers in rodata

Message ID 20240117114405.1506775-1-jani.nikula@intel.com (mailing list archive)
State Accepted
Headers show
Series hwmon: put HWMON_CHANNEL_INFO() initializers in rodata | expand

Commit Message

Jani Nikula Jan. 17, 2024, 11:44 a.m. UTC
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 <jdelvare@suse.com>
Cc: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Jani Nikula <jani.nikula@intel.com>
---
 include/linux/hwmon.h | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

Comments

Guenter Roeck Jan. 17, 2024, 9:18 p.m. UTC | #1
On Wed, Jan 17, 2024 at 01:44:05PM +0200, Jani Nikula wrote:
> 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 <jdelvare@suse.com>
> Cc: Guenter Roeck <linux@roeck-us.net>
> Signed-off-by: Jani Nikula <jani.nikula@intel.com>

Applied.

Thanks,
Guenter
diff mbox series

Patch

diff --git a/include/linux/hwmon.h b/include/linux/hwmon.h
index 8cd6a6b33593..c2c0da18dfa3 100644
--- a/include/linux/hwmon.h
+++ b/include/linux/hwmon.h
@@ -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		\
+		}				\
 	})
 
 /**