[PATCH] fs/proc: avoid unused ctl_table entry in init_header

Safety 1 posted 1 patch 2 weeks, 2 days ago
fs/proc/proc_sysctl.c | 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)
[PATCH] fs/proc: avoid unused ctl_table entry in init_header
Posted by Safety 1 2 weeks, 2 days ago
The entry variable in init_header() is only used by
list_for_each_table_entry() for iteration and is never read. With
-Werror=unused-but-set-variable, this causes the build to fail.

Use the table size directly for the loop since the entry value is
not needed here.

Tested with: make -j$(nproc)
Signed-off-by: Safety 1 <176830914+JokerPython3@users.noreply.github.com>
---
 fs/proc/proc_sysctl.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c
index 04a382178..ddc510def 100644
--- a/fs/proc/proc_sysctl.c
+++ b/fs/proc/proc_sysctl.c
@@ -206,9 +206,7 @@ static void init_header(struct ctl_table_header *head,
 	head->node = node;
 	INIT_HLIST_HEAD(&head->inodes);
 	if (node) {
-		const struct ctl_table *entry;
-
-		list_for_each_table_entry(entry, head) {
+		for (size_t i = 0; i < head->ctl_table_size; i++) {
 			node->header = head;
 			node++;
 		}

base-commit: 893e11787f78e43b534e252249ac3fff4d1333f8
-- 
2.55.0
Re: [PATCH] fs/proc: avoid unused ctl_table entry in init_header
Posted by Joel Granados 1 week, 3 days ago
On Wed, Sep 09, 2026 at 07:32:14PM +0300, Safety 1 wrote:
> The entry variable in init_header() is only used by
> list_for_each_table_entry() for iteration and is never read. With
> -Werror=unused-but-set-variable, this causes the build to fail.
That makes no sense. entry++ implies a read. Additionally that entry should be
removed once the code is optimized compiled. So there is no need for this.

> 
> Use the table size directly for the loop since the entry value is
> not needed here.
> 
> Tested with: make -j$(nproc)
> Signed-off-by: Safety 1 <176830914+JokerPython3@users.noreply.github.com>
This is just wrong.

> ---
>  fs/proc/proc_sysctl.c | 4 +---
>  1 file changed, 1 insertion(+), 3 deletions(-)
> 
> diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c
> index 04a382178..ddc510def 100644
> --- a/fs/proc/proc_sysctl.c
> +++ b/fs/proc/proc_sysctl.c
> @@ -206,9 +206,7 @@ static void init_header(struct ctl_table_header *head,
>  	head->node = node;
>  	INIT_HLIST_HEAD(&head->inodes);
>  	if (node) {
> -		const struct ctl_table *entry;
> -
> -		list_for_each_table_entry(entry, head) {
> +		for (size_t i = 0; i < head->ctl_table_size; i++) {
>  			node->header = head;
>  			node++;
>  		}
> 
> base-commit: 893e11787f78e43b534e252249ac3fff4d1333f8
> -- 
> 2.55.0
>