Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

net: make the tcp and udp file_operations for the /proc stuff const

the tcp and udp code creates a set of struct file_operations at runtime
while it can also be done at compile time, with the added benefit of then
having these file operations be const.

the trickiest part was to get the "THIS_MODULE" reference right; the naive
method of declaring a struct in the place of registration would not work
for this reason.

Signed-off-by: Arjan van de Ven <arjan@linux.intel.com>
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by

Arjan van de Ven and committed by
David S. Miller
73cb88ec 98f41f69

+75 -41
+6 -4
include/net/tcp.h
··· 1403 1403 TCP_SEQ_STATE_TIME_WAIT, 1404 1404 }; 1405 1405 1406 + int tcp_seq_open(struct inode *inode, struct file *file); 1407 + 1406 1408 struct tcp_seq_afinfo { 1407 - char *name; 1408 - sa_family_t family; 1409 - struct file_operations seq_fops; 1410 - struct seq_operations seq_ops; 1409 + char *name; 1410 + sa_family_t family; 1411 + const struct file_operations *seq_fops; 1412 + struct seq_operations seq_ops; 1411 1413 }; 1412 1414 1413 1415 struct tcp_iter_state {
+7 -5
include/net/udp.h
··· 230 230 #endif 231 231 232 232 /* /proc */ 233 + int udp_seq_open(struct inode *inode, struct file *file); 234 + 233 235 struct udp_seq_afinfo { 234 - char *name; 235 - sa_family_t family; 236 - struct udp_table *udp_table; 237 - struct file_operations seq_fops; 238 - struct seq_operations seq_ops; 236 + char *name; 237 + sa_family_t family; 238 + struct udp_table *udp_table; 239 + const struct file_operations *seq_fops; 240 + struct seq_operations seq_ops; 239 241 }; 240 242 241 243 struct udp_iter_state {
+12 -10
net/ipv4/tcp_ipv4.c
··· 2339 2339 } 2340 2340 } 2341 2341 2342 - static int tcp_seq_open(struct inode *inode, struct file *file) 2342 + int tcp_seq_open(struct inode *inode, struct file *file) 2343 2343 { 2344 2344 struct tcp_seq_afinfo *afinfo = PDE(inode)->data; 2345 2345 struct tcp_iter_state *s; ··· 2355 2355 s->last_pos = 0; 2356 2356 return 0; 2357 2357 } 2358 + EXPORT_SYMBOL(tcp_seq_open); 2358 2359 2359 2360 int tcp_proc_register(struct net *net, struct tcp_seq_afinfo *afinfo) 2360 2361 { 2361 2362 int rc = 0; 2362 2363 struct proc_dir_entry *p; 2363 2364 2364 - afinfo->seq_fops.open = tcp_seq_open; 2365 - afinfo->seq_fops.read = seq_read; 2366 - afinfo->seq_fops.llseek = seq_lseek; 2367 - afinfo->seq_fops.release = seq_release_net; 2368 - 2369 2365 afinfo->seq_ops.start = tcp_seq_start; 2370 2366 afinfo->seq_ops.next = tcp_seq_next; 2371 2367 afinfo->seq_ops.stop = tcp_seq_stop; 2372 2368 2373 2369 p = proc_create_data(afinfo->name, S_IRUGO, net->proc_net, 2374 - &afinfo->seq_fops, afinfo); 2370 + afinfo->seq_fops, afinfo); 2375 2371 if (!p) 2376 2372 rc = -ENOMEM; 2377 2373 return rc; ··· 2516 2520 return 0; 2517 2521 } 2518 2522 2523 + static const struct file_operations tcp_afinfo_seq_fops = { 2524 + .owner = THIS_MODULE, 2525 + .open = tcp_seq_open, 2526 + .read = seq_read, 2527 + .llseek = seq_lseek, 2528 + .release = seq_release_net 2529 + }; 2530 + 2519 2531 static struct tcp_seq_afinfo tcp4_seq_afinfo = { 2520 2532 .name = "tcp", 2521 2533 .family = AF_INET, 2522 - .seq_fops = { 2523 - .owner = THIS_MODULE, 2524 - }, 2534 + .seq_fops = &tcp_afinfo_seq_fops, 2525 2535 .seq_ops = { 2526 2536 .show = tcp4_seq_show, 2527 2537 },
+12 -10
net/ipv4/udp.c
··· 2037 2037 spin_unlock_bh(&state->udp_table->hash[state->bucket].lock); 2038 2038 } 2039 2039 2040 - static int udp_seq_open(struct inode *inode, struct file *file) 2040 + int udp_seq_open(struct inode *inode, struct file *file) 2041 2041 { 2042 2042 struct udp_seq_afinfo *afinfo = PDE(inode)->data; 2043 2043 struct udp_iter_state *s; ··· 2053 2053 s->udp_table = afinfo->udp_table; 2054 2054 return err; 2055 2055 } 2056 + EXPORT_SYMBOL(udp_seq_open); 2056 2057 2057 2058 /* ------------------------------------------------------------------------ */ 2058 2059 int udp_proc_register(struct net *net, struct udp_seq_afinfo *afinfo) ··· 2061 2060 struct proc_dir_entry *p; 2062 2061 int rc = 0; 2063 2062 2064 - afinfo->seq_fops.open = udp_seq_open; 2065 - afinfo->seq_fops.read = seq_read; 2066 - afinfo->seq_fops.llseek = seq_lseek; 2067 - afinfo->seq_fops.release = seq_release_net; 2068 - 2069 2063 afinfo->seq_ops.start = udp_seq_start; 2070 2064 afinfo->seq_ops.next = udp_seq_next; 2071 2065 afinfo->seq_ops.stop = udp_seq_stop; 2072 2066 2073 2067 p = proc_create_data(afinfo->name, S_IRUGO, net->proc_net, 2074 - &afinfo->seq_fops, afinfo); 2068 + afinfo->seq_fops, afinfo); 2075 2069 if (!p) 2076 2070 rc = -ENOMEM; 2077 2071 return rc; ··· 2116 2120 return 0; 2117 2121 } 2118 2122 2123 + static const struct file_operations udp_afinfo_seq_fops = { 2124 + .owner = THIS_MODULE, 2125 + .open = udp_seq_open, 2126 + .read = seq_read, 2127 + .llseek = seq_lseek, 2128 + .release = seq_release_net 2129 + }; 2130 + 2119 2131 /* ------------------------------------------------------------------------ */ 2120 2132 static struct udp_seq_afinfo udp4_seq_afinfo = { 2121 2133 .name = "udp", 2122 2134 .family = AF_INET, 2123 2135 .udp_table = &udp_table, 2124 - .seq_fops = { 2125 - .owner = THIS_MODULE, 2126 - }, 2136 + .seq_fops = &udp_afinfo_seq_fops, 2127 2137 .seq_ops = { 2128 2138 .show = udp4_seq_show, 2129 2139 },
+10 -3
net/ipv4/udplite.c
··· 71 71 }; 72 72 73 73 #ifdef CONFIG_PROC_FS 74 + 75 + static const struct file_operations udplite_afinfo_seq_fops = { 76 + .owner = THIS_MODULE, 77 + .open = udp_seq_open, 78 + .read = seq_read, 79 + .llseek = seq_lseek, 80 + .release = seq_release_net 81 + }; 82 + 74 83 static struct udp_seq_afinfo udplite4_seq_afinfo = { 75 84 .name = "udplite", 76 85 .family = AF_INET, 77 86 .udp_table = &udplite_table, 78 - .seq_fops = { 79 - .owner = THIS_MODULE, 80 - }, 87 + .seq_fops = &udplite_afinfo_seq_fops, 81 88 .seq_ops = { 82 89 .show = udp4_seq_show, 83 90 },
+9 -3
net/ipv6/tcp_ipv6.c
··· 2161 2161 return 0; 2162 2162 } 2163 2163 2164 + static const struct file_operations tcp6_afinfo_seq_fops = { 2165 + .owner = THIS_MODULE, 2166 + .open = tcp_seq_open, 2167 + .read = seq_read, 2168 + .llseek = seq_lseek, 2169 + .release = seq_release_net 2170 + }; 2171 + 2164 2172 static struct tcp_seq_afinfo tcp6_seq_afinfo = { 2165 2173 .name = "tcp6", 2166 2174 .family = AF_INET6, 2167 - .seq_fops = { 2168 - .owner = THIS_MODULE, 2169 - }, 2175 + .seq_fops = &tcp6_afinfo_seq_fops, 2170 2176 .seq_ops = { 2171 2177 .show = tcp6_seq_show, 2172 2178 },
+9 -3
net/ipv6/udp.c
··· 1424 1424 return 0; 1425 1425 } 1426 1426 1427 + static const struct file_operations udp6_afinfo_seq_fops = { 1428 + .owner = THIS_MODULE, 1429 + .open = udp_seq_open, 1430 + .read = seq_read, 1431 + .llseek = seq_lseek, 1432 + .release = seq_release_net 1433 + }; 1434 + 1427 1435 static struct udp_seq_afinfo udp6_seq_afinfo = { 1428 1436 .name = "udp6", 1429 1437 .family = AF_INET6, 1430 1438 .udp_table = &udp_table, 1431 - .seq_fops = { 1432 - .owner = THIS_MODULE, 1433 - }, 1439 + .seq_fops = &udp6_afinfo_seq_fops, 1434 1440 .seq_ops = { 1435 1441 .show = udp6_seq_show, 1436 1442 },
+10 -3
net/ipv6/udplite.c
··· 93 93 } 94 94 95 95 #ifdef CONFIG_PROC_FS 96 + 97 + static const struct file_operations udplite6_afinfo_seq_fops = { 98 + .owner = THIS_MODULE, 99 + .open = udp_seq_open, 100 + .read = seq_read, 101 + .llseek = seq_lseek, 102 + .release = seq_release_net 103 + }; 104 + 96 105 static struct udp_seq_afinfo udplite6_seq_afinfo = { 97 106 .name = "udplite6", 98 107 .family = AF_INET6, 99 108 .udp_table = &udplite_table, 100 - .seq_fops = { 101 - .owner = THIS_MODULE, 102 - }, 109 + .seq_fops = &udplite6_afinfo_seq_fops, 103 110 .seq_ops = { 104 111 .show = udp6_seq_show, 105 112 },