19
19
#include <linux/kmemleak.h>
20
20
#include "internal.h"
21
21
22
+ #define list_for_each_table_entry (entry , table ) \
23
+ for ((entry) = (table); (entry)->procname; (entry)++)
24
+
22
25
static const struct dentry_operations proc_sys_dentry_operations ;
23
26
static const struct file_operations proc_sys_file_operations ;
24
27
static const struct inode_operations proc_sys_inode_operations ;
@@ -215,15 +218,19 @@ static void init_header(struct ctl_table_header *head,
215
218
INIT_HLIST_HEAD (& head -> inodes );
216
219
if (node ) {
217
220
struct ctl_table * entry ;
218
- for (entry = table ; entry -> procname ; entry ++ , node ++ )
221
+
222
+ list_for_each_table_entry (entry , table ) {
219
223
node -> header = head ;
224
+ node ++ ;
225
+ }
220
226
}
221
227
}
222
228
223
229
static void erase_header (struct ctl_table_header * head )
224
230
{
225
231
struct ctl_table * entry ;
226
- for (entry = head -> ctl_table ; entry -> procname ; entry ++ )
232
+
233
+ list_for_each_table_entry (entry , head -> ctl_table )
227
234
erase_entry (head , entry );
228
235
}
229
236
@@ -248,7 +255,7 @@ static int insert_header(struct ctl_dir *dir, struct ctl_table_header *header)
248
255
err = insert_links (header );
249
256
if (err )
250
257
goto fail_links ;
251
- for (entry = header -> ctl_table ; entry -> procname ; entry ++ ) {
258
+ list_for_each_table_entry (entry , header -> ctl_table ) {
252
259
err = insert_entry (header , entry );
253
260
if (err )
254
261
goto fail ;
@@ -1130,35 +1137,36 @@ static int sysctl_check_table_array(const char *path, struct ctl_table *table)
1130
1137
1131
1138
static int sysctl_check_table (const char * path , struct ctl_table * table )
1132
1139
{
1140
+ struct ctl_table * entry ;
1133
1141
int err = 0 ;
1134
- for (; table -> procname ; table ++ ) {
1135
- if (table -> child )
1136
- err |= sysctl_err (path , table , "Not a file" );
1137
-
1138
- if ((table -> proc_handler == proc_dostring ) ||
1139
- (table -> proc_handler == proc_dointvec ) ||
1140
- (table -> proc_handler == proc_douintvec ) ||
1141
- (table -> proc_handler == proc_douintvec_minmax ) ||
1142
- (table -> proc_handler == proc_dointvec_minmax ) ||
1143
- (table -> proc_handler == proc_dou8vec_minmax ) ||
1144
- (table -> proc_handler == proc_dointvec_jiffies ) ||
1145
- (table -> proc_handler == proc_dointvec_userhz_jiffies ) ||
1146
- (table -> proc_handler == proc_dointvec_ms_jiffies ) ||
1147
- (table -> proc_handler == proc_doulongvec_minmax ) ||
1148
- (table -> proc_handler == proc_doulongvec_ms_jiffies_minmax )) {
1149
- if (!table -> data )
1150
- err |= sysctl_err (path , table , "No data" );
1151
- if (!table -> maxlen )
1152
- err |= sysctl_err (path , table , "No maxlen" );
1142
+ list_for_each_table_entry ( entry , table ) {
1143
+ if (entry -> child )
1144
+ err |= sysctl_err (path , entry , "Not a file" );
1145
+
1146
+ if ((entry -> proc_handler == proc_dostring ) ||
1147
+ (entry -> proc_handler == proc_dointvec ) ||
1148
+ (entry -> proc_handler == proc_douintvec ) ||
1149
+ (entry -> proc_handler == proc_douintvec_minmax ) ||
1150
+ (entry -> proc_handler == proc_dointvec_minmax ) ||
1151
+ (entry -> proc_handler == proc_dou8vec_minmax ) ||
1152
+ (entry -> proc_handler == proc_dointvec_jiffies ) ||
1153
+ (entry -> proc_handler == proc_dointvec_userhz_jiffies ) ||
1154
+ (entry -> proc_handler == proc_dointvec_ms_jiffies ) ||
1155
+ (entry -> proc_handler == proc_doulongvec_minmax ) ||
1156
+ (entry -> proc_handler == proc_doulongvec_ms_jiffies_minmax )) {
1157
+ if (!entry -> data )
1158
+ err |= sysctl_err (path , entry , "No data" );
1159
+ if (!entry -> maxlen )
1160
+ err |= sysctl_err (path , entry , "No maxlen" );
1153
1161
else
1154
- err |= sysctl_check_table_array (path , table );
1162
+ err |= sysctl_check_table_array (path , entry );
1155
1163
}
1156
- if (!table -> proc_handler )
1157
- err |= sysctl_err (path , table , "No proc_handler" );
1164
+ if (!entry -> proc_handler )
1165
+ err |= sysctl_err (path , entry , "No proc_handler" );
1158
1166
1159
- if ((table -> mode & (S_IRUGO |S_IWUGO )) != table -> mode )
1160
- err |= sysctl_err (path , table , "bogus .mode 0%o" ,
1161
- table -> mode );
1167
+ if ((entry -> mode & (S_IRUGO |S_IWUGO )) != entry -> mode )
1168
+ err |= sysctl_err (path , entry , "bogus .mode 0%o" ,
1169
+ entry -> mode );
1162
1170
}
1163
1171
return err ;
1164
1172
}
@@ -1174,7 +1182,7 @@ static struct ctl_table_header *new_links(struct ctl_dir *dir, struct ctl_table
1174
1182
1175
1183
name_bytes = 0 ;
1176
1184
nr_entries = 0 ;
1177
- for (entry = table ; entry -> procname ; entry ++ ) {
1185
+ list_for_each_table_entry (entry , table ) {
1178
1186
nr_entries ++ ;
1179
1187
name_bytes += strlen (entry -> procname ) + 1 ;
1180
1188
}
@@ -1191,14 +1199,16 @@ static struct ctl_table_header *new_links(struct ctl_dir *dir, struct ctl_table
1191
1199
node = (struct ctl_node * )(links + 1 );
1192
1200
link_table = (struct ctl_table * )(node + nr_entries );
1193
1201
link_name = (char * )& link_table [nr_entries + 1 ];
1202
+ link = link_table ;
1194
1203
1195
- for ( link = link_table , entry = table ; entry -> procname ; link ++ , entry ++ ) {
1204
+ list_for_each_table_entry ( entry , table ) {
1196
1205
int len = strlen (entry -> procname ) + 1 ;
1197
1206
memcpy (link_name , entry -> procname , len );
1198
1207
link -> procname = link_name ;
1199
1208
link -> mode = S_IFLNK |S_IRWXUGO ;
1200
1209
link -> data = link_root ;
1201
1210
link_name += len ;
1211
+ link ++ ;
1202
1212
}
1203
1213
init_header (links , dir -> header .root , dir -> header .set , node , link_table );
1204
1214
links -> nreg = nr_entries ;
@@ -1213,7 +1223,7 @@ static bool get_links(struct ctl_dir *dir,
1213
1223
struct ctl_table * entry , * link ;
1214
1224
1215
1225
/* Are there links available for every entry in table? */
1216
- for (entry = table ; entry -> procname ; entry ++ ) {
1226
+ list_for_each_table_entry (entry , table ) {
1217
1227
const char * procname = entry -> procname ;
1218
1228
link = find_entry (& head , dir , procname , strlen (procname ));
1219
1229
if (!link )
@@ -1226,7 +1236,7 @@ static bool get_links(struct ctl_dir *dir,
1226
1236
}
1227
1237
1228
1238
/* The checks passed. Increase the registration count on the links */
1229
- for (entry = table ; entry -> procname ; entry ++ ) {
1239
+ list_for_each_table_entry (entry , table ) {
1230
1240
const char * procname = entry -> procname ;
1231
1241
link = find_entry (& head , dir , procname , strlen (procname ));
1232
1242
head -> nreg ++ ;
@@ -1329,7 +1339,7 @@ struct ctl_table_header *__register_sysctl_table(
1329
1339
struct ctl_node * node ;
1330
1340
int nr_entries = 0 ;
1331
1341
1332
- for (entry = table ; entry -> procname ; entry ++ )
1342
+ list_for_each_table_entry (entry , table )
1333
1343
nr_entries ++ ;
1334
1344
1335
1345
header = kzalloc (sizeof (struct ctl_table_header ) +
@@ -1456,7 +1466,7 @@ static int count_subheaders(struct ctl_table *table)
1456
1466
if (!table || !table -> procname )
1457
1467
return 1 ;
1458
1468
1459
- for (entry = table ; entry -> procname ; entry ++ ) {
1469
+ list_for_each_table_entry (entry , table ) {
1460
1470
if (entry -> child )
1461
1471
nr_subheaders += count_subheaders (entry -> child );
1462
1472
else
@@ -1475,7 +1485,7 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
1475
1485
int nr_dirs = 0 ;
1476
1486
int err = - ENOMEM ;
1477
1487
1478
- for (entry = table ; entry -> procname ; entry ++ ) {
1488
+ list_for_each_table_entry (entry , table ) {
1479
1489
if (entry -> child )
1480
1490
nr_dirs ++ ;
1481
1491
else
@@ -1492,7 +1502,9 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
1492
1502
goto out ;
1493
1503
1494
1504
ctl_table_arg = files ;
1495
- for (new = files , entry = table ; entry -> procname ; entry ++ ) {
1505
+ new = files ;
1506
+
1507
+ list_for_each_table_entry (entry , table ) {
1496
1508
if (entry -> child )
1497
1509
continue ;
1498
1510
* new = * entry ;
@@ -1516,7 +1528,7 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
1516
1528
}
1517
1529
1518
1530
/* Recurse into the subdirectories. */
1519
- for (entry = table ; entry -> procname ; entry ++ ) {
1531
+ list_for_each_table_entry (entry , table ) {
1520
1532
char * child_pos ;
1521
1533
1522
1534
if (!entry -> child )
@@ -1670,7 +1682,7 @@ static void put_links(struct ctl_table_header *header)
1670
1682
if (IS_ERR (core_parent ))
1671
1683
return ;
1672
1684
1673
- for (entry = header -> ctl_table ; entry -> procname ; entry ++ ) {
1685
+ list_for_each_table_entry (entry , header -> ctl_table ) {
1674
1686
struct ctl_table_header * link_head ;
1675
1687
struct ctl_table * link ;
1676
1688
const char * name = entry -> procname ;
0 commit comments