Skip to contentSkip to conversation

macintosh: declare ctl_table as const

PATCH Applied Luis Felipe Hernandez 2 participants 2 messages Dec 18, 2024 – Jan 1, 2025 Linux for power macintosh

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 macintosh: declare ctl_table as const

Since commit 7abc9b53bd51 ("sysctl: allow registration of const struct ctl_table"), the sysctl registration API allows struct ctl_table variables to be placed into read-only memory.

mac_hid_files is registered as a sysctl table and should be treated as read-only. By declaring the mac_hid_files structure as const, we ensure that it cannot be accidentally modified. This change improves safety.

---
Changes in v2:
* Remove redundant commit reference
* Fix Suggested-by tags

---
 drivers/macintosh/mac_hid.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/macintosh/mac_hid.c +1 -1
index b461b1bed25b2df106ecf612b82efaedf69f62b0..369d72f59b3c10869bc914f31e7dcb73e029ef7f 100644
@@ -215,7 +215,7 @@ static int mac_hid_toggle_emumouse(const struct ctl_table *table, int write,
 }
 
 /* file(s) in /proc/sys/dev/mac_hid */
-static struct ctl_table mac_hid_files[] = {
+static const struct ctl_table mac_hid_files[] = {
 	{
 		.procname	= "mouse_button_emulation",
 		.data		= &mouse_emulate_buttons,

---
base-commit: fdb298fa865b0136f7be842e6c2e6310dede421a
change-id: 20241217-constify_ctl_table-881fcffc8804

Best regards,

Signature · 1 line
Luis Felipe Hernandez <[email protected]>
#1 lore raw
Quoted 9 lines · Luis Felipe Hernandez

Since commit 7abc9b53bd51 ("sysctl: allow registration of const struct ctl_table"), the sysctl registration API allows struct ctl_table variables to be placed into read-only memory.

mac_hid_files is registered as a sysctl table and should be treated as read-only. By declaring the mac_hid_files structure as const, we ensure that it cannot be accidentally modified. This change improves safety.

[...]

Applied to powerpc/next.

[1/1] macintosh: declare ctl_table as const

      https://git.kernel.org/pub/scm/linux/kernel/git/powerpc/linux.git/commit/?h=next&id=e834166822a3c9fb403411c898367df8dabf973c 

Thanks