Skip to content

Commit 18d4b42

Browse files
Joelgranadosmcgrof
authored andcommitted
sysctl: Use ctl_table_header in list_for_each_table_entry
We replace the ctl_table with the ctl_table_header pointer in list_for_each_table_entry which is the macro responsible for traversing the ctl_table arrays. This is a preparation commit that will make it easier to add the ctl_table array size (that will be added to ctl_table_header in subsequent commits) to the already existing loop logic based on empty ctl_table elements (so called sentinels). Signed-off-by: Joel Granados <[email protected]> Signed-off-by: Luis Chamberlain <[email protected]>
1 parent cc9f7ee commit 18d4b42

File tree

1 file changed

+14
-12
lines changed

1 file changed

+14
-12
lines changed

fs/proc/proc_sysctl.c

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

22-
#define list_for_each_table_entry(entry, table) \
23-
for ((entry) = (table); (entry)->procname; (entry)++)
22+
#define list_for_each_table_entry(entry, header) \
23+
for ((entry) = (header->ctl_table); (entry)->procname; (entry)++)
2424

2525
static const struct dentry_operations proc_sys_dentry_operations;
2626
static const struct file_operations proc_sys_file_operations;
@@ -204,7 +204,7 @@ static void init_header(struct ctl_table_header *head,
204204
if (node) {
205205
struct ctl_table *entry;
206206

207-
list_for_each_table_entry(entry, table) {
207+
list_for_each_table_entry(entry, head) {
208208
node->header = head;
209209
node++;
210210
}
@@ -215,7 +215,7 @@ static void erase_header(struct ctl_table_header *head)
215215
{
216216
struct ctl_table *entry;
217217

218-
list_for_each_table_entry(entry, head->ctl_table)
218+
list_for_each_table_entry(entry, head)
219219
erase_entry(head, entry);
220220
}
221221

@@ -242,7 +242,7 @@ static int insert_header(struct ctl_dir *dir, struct ctl_table_header *header)
242242
err = insert_links(header);
243243
if (err)
244244
goto fail_links;
245-
list_for_each_table_entry(entry, header->ctl_table) {
245+
list_for_each_table_entry(entry, header) {
246246
err = insert_entry(header, entry);
247247
if (err)
248248
goto fail;
@@ -1129,7 +1129,7 @@ static int sysctl_check_table(const char *path, struct ctl_table_header *header)
11291129
{
11301130
struct ctl_table *entry;
11311131
int err = 0;
1132-
list_for_each_table_entry(entry, header->ctl_table) {
1132+
list_for_each_table_entry(entry, header) {
11331133
if ((entry->proc_handler == proc_dostring) ||
11341134
(entry->proc_handler == proc_dobool) ||
11351135
(entry->proc_handler == proc_dointvec) ||
@@ -1169,7 +1169,7 @@ static struct ctl_table_header *new_links(struct ctl_dir *dir, struct ctl_table_
11691169

11701170
name_bytes = 0;
11711171
nr_entries = 0;
1172-
list_for_each_table_entry(entry, head->ctl_table) {
1172+
list_for_each_table_entry(entry, head) {
11731173
nr_entries++;
11741174
name_bytes += strlen(entry->procname) + 1;
11751175
}
@@ -1188,7 +1188,7 @@ static struct ctl_table_header *new_links(struct ctl_dir *dir, struct ctl_table_
11881188
link_name = (char *)&link_table[nr_entries + 1];
11891189
link = link_table;
11901190

1191-
list_for_each_table_entry(entry, head->ctl_table) {
1191+
list_for_each_table_entry(entry, head) {
11921192
int len = strlen(entry->procname) + 1;
11931193
memcpy(link_name, entry->procname, len);
11941194
link->procname = link_name;
@@ -1211,7 +1211,7 @@ static bool get_links(struct ctl_dir *dir,
12111211
struct ctl_table *entry, *link;
12121212

12131213
/* Are there links available for every entry in table? */
1214-
list_for_each_table_entry(entry, header->ctl_table) {
1214+
list_for_each_table_entry(entry, header) {
12151215
const char *procname = entry->procname;
12161216
link = find_entry(&tmp_head, dir, procname, strlen(procname));
12171217
if (!link)
@@ -1224,7 +1224,7 @@ static bool get_links(struct ctl_dir *dir,
12241224
}
12251225

12261226
/* The checks passed. Increase the registration count on the links */
1227-
list_for_each_table_entry(entry, header->ctl_table) {
1227+
list_for_each_table_entry(entry, header) {
12281228
const char *procname = entry->procname;
12291229
link = find_entry(&tmp_head, dir, procname, strlen(procname));
12301230
tmp_head->nreg++;
@@ -1356,12 +1356,14 @@ struct ctl_table_header *__register_sysctl_table(
13561356
{
13571357
struct ctl_table_root *root = set->dir.header.root;
13581358
struct ctl_table_header *header;
1359+
struct ctl_table_header h_tmp;
13591360
struct ctl_dir *dir;
13601361
struct ctl_table *entry;
13611362
struct ctl_node *node;
13621363
int nr_entries = 0;
13631364

1364-
list_for_each_table_entry(entry, table)
1365+
h_tmp.ctl_table = table;
1366+
list_for_each_table_entry(entry, (&h_tmp))
13651367
nr_entries++;
13661368

13671369
header = kzalloc(sizeof(struct ctl_table_header) +
@@ -1471,7 +1473,7 @@ static void put_links(struct ctl_table_header *header)
14711473
if (IS_ERR(core_parent))
14721474
return;
14731475

1474-
list_for_each_table_entry(entry, header->ctl_table) {
1476+
list_for_each_table_entry(entry, header) {
14751477
struct ctl_table_header *link_head;
14761478
struct ctl_table *link;
14771479
const char *name = entry->procname;

0 commit comments

Comments
 (0)