[PATCH] macintosh: declare ctl_table as const

Luis Felipe Hernandez posted 1 patch 1 year ago
There is a newer version of this series
drivers/macintosh/mac_hid.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
[PATCH] macintosh: declare ctl_table as const
Posted by Luis Felipe Hernandez 1 year ago
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 at runtime. This change improves
safety and aligns with the recommendation from commit 7abc9b53bd51
("sysctl: allow registration of const struct ctl_table").

Signed-off-by: Luis Felipe Hernandez <luis.hernandez093@gmail.com>
---
Suggested-by: Thomas Weißschuh <linux@weissschuh.net>
Suggested-by: Ricardo B. Marliere <rbm@suse.com>
---
 drivers/macintosh/mac_hid.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/macintosh/mac_hid.c b/drivers/macintosh/mac_hid.c
index b461b1bed25b2df106ecf612b82efaedf69f62b0..369d72f59b3c10869bc914f31e7dcb73e029ef7f 100644
--- a/drivers/macintosh/mac_hid.c
+++ b/drivers/macintosh/mac_hid.c
@@ -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: e25c8d66f6786300b680866c0e0139981273feba
change-id: 20241216-constify_sysctl_mac_hid-55886592c206

Best regards,
-- 
Luis Felipe Hernandez <luis.hernandez093@gmail.com>

Re: [PATCH] macintosh: declare ctl_table as const
Posted by Ricardo B. Marliere 1 year ago
Hi!

On 16 Dec 24 22:20, Luis Felipe Hernandez wrote:
> 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 at runtime. This change improves
> safety and aligns with the recommendation from commit 7abc9b53bd51
> ("sysctl: allow registration of const struct ctl_table").

No need to mention the commit twice :)

> 
> Signed-off-by: Luis Felipe Hernandez <luis.hernandez093@gmail.com>
> ---
> Suggested-by: Thomas Weißschuh <linux@weissschuh.net>
> Suggested-by: Ricardo B. Marliere <rbm@suse.com>
> ---

What happened here? Signed-off-by should be last and without "---".

With those fixed:

Reviewed-by: Ricardo B. Marliere <rbm@suse.com>

Thank you,
-	Ricardo.


>  drivers/macintosh/mac_hid.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/macintosh/mac_hid.c b/drivers/macintosh/mac_hid.c
> index b461b1bed25b2df106ecf612b82efaedf69f62b0..369d72f59b3c10869bc914f31e7dcb73e029ef7f 100644
> --- a/drivers/macintosh/mac_hid.c
> +++ b/drivers/macintosh/mac_hid.c
> @@ -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: e25c8d66f6786300b680866c0e0139981273feba
> change-id: 20241216-constify_sysctl_mac_hid-55886592c206
> 
> Best regards,
> -- 
> Luis Felipe Hernandez <luis.hernandez093@gmail.com>
>