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 ;
@@ -978,7 +985,6 @@ static struct ctl_dir *new_dir(struct ctl_table_set *set,
978
985
table = (struct ctl_table * )(node + 1 );
979
986
new_name = (char * )(table + 2 );
980
987
memcpy (new_name , name , namelen );
981
- new_name [namelen ] = '\0' ;
982
988
table [0 ].procname = new_name ;
983
989
table [0 ].mode = S_IFDIR |S_IRUGO |S_IXUGO ;
984
990
init_header (& new -> header , set -> dir .header .root , set , node , table );
@@ -1130,35 +1136,36 @@ static int sysctl_check_table_array(const char *path, struct ctl_table *table)
1130
1136
1131
1137
static int sysctl_check_table (const char * path , struct ctl_table * table )
1132
1138
{
1139
+ struct ctl_table * entry ;
1133
1140
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" );
1141
+ list_for_each_table_entry ( entry , table ) {
1142
+ if (entry -> child )
1143
+ err |= sysctl_err (path , entry , "Not a file" );
1144
+
1145
+ if ((entry -> proc_handler == proc_dostring ) ||
1146
+ (entry -> proc_handler == proc_dointvec ) ||
1147
+ (entry -> proc_handler == proc_douintvec ) ||
1148
+ (entry -> proc_handler == proc_douintvec_minmax ) ||
1149
+ (entry -> proc_handler == proc_dointvec_minmax ) ||
1150
+ (entry -> proc_handler == proc_dou8vec_minmax ) ||
1151
+ (entry -> proc_handler == proc_dointvec_jiffies ) ||
1152
+ (entry -> proc_handler == proc_dointvec_userhz_jiffies ) ||
1153
+ (entry -> proc_handler == proc_dointvec_ms_jiffies ) ||
1154
+ (entry -> proc_handler == proc_doulongvec_minmax ) ||
1155
+ (entry -> proc_handler == proc_doulongvec_ms_jiffies_minmax )) {
1156
+ if (!entry -> data )
1157
+ err |= sysctl_err (path , entry , "No data" );
1158
+ if (!entry -> maxlen )
1159
+ err |= sysctl_err (path , entry , "No maxlen" );
1153
1160
else
1154
- err |= sysctl_check_table_array (path , table );
1161
+ err |= sysctl_check_table_array (path , entry );
1155
1162
}
1156
- if (!table -> proc_handler )
1157
- err |= sysctl_err (path , table , "No proc_handler" );
1163
+ if (!entry -> proc_handler )
1164
+ err |= sysctl_err (path , entry , "No proc_handler" );
1158
1165
1159
- if ((table -> mode & (S_IRUGO |S_IWUGO )) != table -> mode )
1160
- err |= sysctl_err (path , table , "bogus .mode 0%o" ,
1161
- table -> mode );
1166
+ if ((entry -> mode & (S_IRUGO |S_IWUGO )) != entry -> mode )
1167
+ err |= sysctl_err (path , entry , "bogus .mode 0%o" ,
1168
+ entry -> mode );
1162
1169
}
1163
1170
return err ;
1164
1171
}
@@ -1174,7 +1181,7 @@ static struct ctl_table_header *new_links(struct ctl_dir *dir, struct ctl_table
1174
1181
1175
1182
name_bytes = 0 ;
1176
1183
nr_entries = 0 ;
1177
- for (entry = table ; entry -> procname ; entry ++ ) {
1184
+ list_for_each_table_entry (entry , table ) {
1178
1185
nr_entries ++ ;
1179
1186
name_bytes += strlen (entry -> procname ) + 1 ;
1180
1187
}
@@ -1191,14 +1198,16 @@ static struct ctl_table_header *new_links(struct ctl_dir *dir, struct ctl_table
1191
1198
node = (struct ctl_node * )(links + 1 );
1192
1199
link_table = (struct ctl_table * )(node + nr_entries );
1193
1200
link_name = (char * )& link_table [nr_entries + 1 ];
1201
+ link = link_table ;
1194
1202
1195
- for ( link = link_table , entry = table ; entry -> procname ; link ++ , entry ++ ) {
1203
+ list_for_each_table_entry ( entry , table ) {
1196
1204
int len = strlen (entry -> procname ) + 1 ;
1197
1205
memcpy (link_name , entry -> procname , len );
1198
1206
link -> procname = link_name ;
1199
1207
link -> mode = S_IFLNK |S_IRWXUGO ;
1200
1208
link -> data = link_root ;
1201
1209
link_name += len ;
1210
+ link ++ ;
1202
1211
}
1203
1212
init_header (links , dir -> header .root , dir -> header .set , node , link_table );
1204
1213
links -> nreg = nr_entries ;
@@ -1213,7 +1222,7 @@ static bool get_links(struct ctl_dir *dir,
1213
1222
struct ctl_table * entry , * link ;
1214
1223
1215
1224
/* Are there links available for every entry in table? */
1216
- for (entry = table ; entry -> procname ; entry ++ ) {
1225
+ list_for_each_table_entry (entry , table ) {
1217
1226
const char * procname = entry -> procname ;
1218
1227
link = find_entry (& head , dir , procname , strlen (procname ));
1219
1228
if (!link )
@@ -1226,7 +1235,7 @@ static bool get_links(struct ctl_dir *dir,
1226
1235
}
1227
1236
1228
1237
/* The checks passed. Increase the registration count on the links */
1229
- for (entry = table ; entry -> procname ; entry ++ ) {
1238
+ list_for_each_table_entry (entry , table ) {
1230
1239
const char * procname = entry -> procname ;
1231
1240
link = find_entry (& head , dir , procname , strlen (procname ));
1232
1241
head -> nreg ++ ;
@@ -1329,7 +1338,7 @@ struct ctl_table_header *__register_sysctl_table(
1329
1338
struct ctl_node * node ;
1330
1339
int nr_entries = 0 ;
1331
1340
1332
- for (entry = table ; entry -> procname ; entry ++ )
1341
+ list_for_each_table_entry (entry , table )
1333
1342
nr_entries ++ ;
1334
1343
1335
1344
header = kzalloc (sizeof (struct ctl_table_header ) +
@@ -1456,7 +1465,7 @@ static int count_subheaders(struct ctl_table *table)
1456
1465
if (!table || !table -> procname )
1457
1466
return 1 ;
1458
1467
1459
- for (entry = table ; entry -> procname ; entry ++ ) {
1468
+ list_for_each_table_entry (entry , table ) {
1460
1469
if (entry -> child )
1461
1470
nr_subheaders += count_subheaders (entry -> child );
1462
1471
else
@@ -1475,7 +1484,7 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
1475
1484
int nr_dirs = 0 ;
1476
1485
int err = - ENOMEM ;
1477
1486
1478
- for (entry = table ; entry -> procname ; entry ++ ) {
1487
+ list_for_each_table_entry (entry , table ) {
1479
1488
if (entry -> child )
1480
1489
nr_dirs ++ ;
1481
1490
else
@@ -1492,7 +1501,9 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
1492
1501
goto out ;
1493
1502
1494
1503
ctl_table_arg = files ;
1495
- for (new = files , entry = table ; entry -> procname ; entry ++ ) {
1504
+ new = files ;
1505
+
1506
+ list_for_each_table_entry (entry , table ) {
1496
1507
if (entry -> child )
1497
1508
continue ;
1498
1509
* new = * entry ;
@@ -1516,7 +1527,7 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
1516
1527
}
1517
1528
1518
1529
/* Recurse into the subdirectories. */
1519
- for (entry = table ; entry -> procname ; entry ++ ) {
1530
+ list_for_each_table_entry (entry , table ) {
1520
1531
char * child_pos ;
1521
1532
1522
1533
if (!entry -> child )
@@ -1670,7 +1681,7 @@ static void put_links(struct ctl_table_header *header)
1670
1681
if (IS_ERR (core_parent ))
1671
1682
return ;
1672
1683
1673
- for (entry = header -> ctl_table ; entry -> procname ; entry ++ ) {
1684
+ list_for_each_table_entry (entry , header -> ctl_table ) {
1674
1685
struct ctl_table_header * link_head ;
1675
1686
struct ctl_table * link ;
1676
1687
const char * name = entry -> procname ;
0 commit comments