Skip to content

Commit 53f3811

Browse files
Joelgranadosmcgrof
authored andcommitted
sysctl: Use ctl_table_size as stopping criteria for list macro
This is a preparation commit to make it easy to remove the sentinel elements (empty end markers) from the ctl_table arrays. It both allows the systematic removal of the sentinels and adds the ctl_table_size variable to the stopping criteria of the list_for_each_table_entry macro that traverses all ctl_table arrays. Once all the sentinels are removed by subsequent commits, ctl_table_size will become the only stopping criteria in the macro. We don't actually remove any elements in this commit, but it sets things up to for the removal process to take place. By adding header->ctl_table_size as an additional stopping criteria for the list_for_each_table_entry macro, it will execute until it finds an "empty" ->procname or until the size runs out. Therefore if a ctl_table array with a sentinel is passed its size will be too big (by one element) but it will stop on the sentinel. On the other hand, if the ctl_table array without a sentinel is passed its size will be just write and there will be no need for a sentinel. Signed-off-by: Joel Granados <[email protected]> Suggested-by: Jani Nikula <[email protected]> Signed-off-by: Luis Chamberlain <[email protected]>
1 parent e1b41e4 commit 53f3811

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

fs/proc/proc_sysctl.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,9 @@
1919
#include <linux/kmemleak.h>
2020
#include "internal.h"
2121

22-
#define list_for_each_table_entry(entry, header) \
23-
for ((entry) = (header->ctl_table); (entry)->procname; (entry)++)
22+
#define list_for_each_table_entry(entry, header) \
23+
entry = header->ctl_table; \
24+
for (size_t i = 0 ; i < header->ctl_table_size && entry->procname; ++i, entry++)
2425

2526
static const struct dentry_operations proc_sys_dentry_operations;
2627
static const struct file_operations proc_sys_file_operations;

0 commit comments

Comments
 (0)