kernel: fix ip6_tunnel compilation
[openwrt.git] / target / linux / generic / patches-4.4 / 902-debloat_proc.patch
1 --- a/fs/locks.c
2 +++ b/fs/locks.c
3 @@ -2712,6 +2712,8 @@ static const struct file_operations proc
4  
5  static int __init proc_locks_init(void)
6  {
7 +       if (IS_ENABLED(CONFIG_PROC_STRIPPED))
8 +               return 0;
9         proc_create("locks", 0, NULL, &proc_locks_operations);
10         return 0;
11  }
12 --- a/fs/proc/Kconfig
13 +++ b/fs/proc/Kconfig
14 @@ -81,3 +81,8 @@ config PROC_CHILDREN
15  
16           Say Y if you are running any user-space software which takes benefit from
17           this interface. For example, rkt is such a piece of software.
18 +
19 +config PROC_STRIPPED
20 +       default n
21 +       depends on EXPERT
22 +       bool "Strip non-essential /proc functionality to reduce code size"
23 --- a/fs/proc/consoles.c
24 +++ b/fs/proc/consoles.c
25 @@ -106,6 +106,9 @@ static const struct file_operations proc
26  
27  static int __init proc_consoles_init(void)
28  {
29 +       if (IS_ENABLED(CONFIG_PROC_STRIPPED))
30 +               return 0;
31 +
32         proc_create("consoles", 0, NULL, &proc_consoles_operations);
33         return 0;
34  }
35 --- a/fs/proc/proc_tty.c
36 +++ b/fs/proc/proc_tty.c
37 @@ -143,7 +143,10 @@ static const struct file_operations proc
38  void proc_tty_register_driver(struct tty_driver *driver)
39  {
40         struct proc_dir_entry *ent;
41 -               
42 +
43 +       if (IS_ENABLED(CONFIG_PROC_STRIPPED))
44 +               return;
45 +
46         if (!driver->driver_name || driver->proc_entry ||
47             !driver->ops->proc_fops)
48                 return;
49 @@ -160,6 +163,9 @@ void proc_tty_unregister_driver(struct t
50  {
51         struct proc_dir_entry *ent;
52  
53 +       if (IS_ENABLED(CONFIG_PROC_STRIPPED))
54 +               return;
55 +
56         ent = driver->proc_entry;
57         if (!ent)
58                 return;
59 @@ -174,6 +180,9 @@ void proc_tty_unregister_driver(struct t
60   */
61  void __init proc_tty_init(void)
62  {
63 +       if (IS_ENABLED(CONFIG_PROC_STRIPPED))
64 +               return;
65 +
66         if (!proc_mkdir("tty", NULL))
67                 return;
68         proc_mkdir("tty/ldisc", NULL);  /* Preserved: it's userspace visible */
69 --- a/kernel/exec_domain.c
70 +++ b/kernel/exec_domain.c
71 @@ -41,6 +41,8 @@ static const struct file_operations exec
72  
73  static int __init proc_execdomains_init(void)
74  {
75 +       if (IS_ENABLED(CONFIG_PROC_STRIPPED))
76 +               return 0;
77         proc_create("execdomains", 0, NULL, &execdomains_proc_fops);
78         return 0;
79  }
80 --- a/kernel/irq/proc.c
81 +++ b/kernel/irq/proc.c
82 @@ -327,6 +327,9 @@ void register_irq_proc(unsigned int irq,
83         static DEFINE_MUTEX(register_lock);
84         char name [MAX_NAMELEN];
85  
86 +       if (IS_ENABLED(CONFIG_PROC_STRIPPED) && !IS_ENABLED(CONFIG_SMP))
87 +               return;
88 +
89         if (!root_irq_dir || (desc->irq_data.chip == &no_irq_chip))
90                 return;
91  
92 @@ -376,6 +379,9 @@ void unregister_irq_proc(unsigned int ir
93  {
94         char name [MAX_NAMELEN];
95  
96 +       if (IS_ENABLED(CONFIG_PROC_STRIPPED) && !IS_ENABLED(CONFIG_SMP))
97 +               return;
98 +
99         if (!root_irq_dir || !desc->dir)
100                 return;
101  #ifdef CONFIG_SMP
102 @@ -411,6 +417,9 @@ void init_irq_proc(void)
103         unsigned int irq;
104         struct irq_desc *desc;
105  
106 +       if (IS_ENABLED(CONFIG_PROC_STRIPPED) && !IS_ENABLED(CONFIG_SMP))
107 +               return;
108 +
109         /* create /proc/irq */
110         root_irq_dir = proc_mkdir("irq", NULL);
111         if (!root_irq_dir)
112 --- a/kernel/time/timer_list.c
113 +++ b/kernel/time/timer_list.c
114 @@ -393,6 +393,8 @@ static int __init init_timer_list_procfs
115  {
116         struct proc_dir_entry *pe;
117  
118 +       if (IS_ENABLED(CONFIG_PROC_STRIPPED))
119 +               return 0;
120         pe = proc_create("timer_list", 0444, NULL, &timer_list_fops);
121         if (!pe)
122                 return -ENOMEM;
123 --- a/mm/vmalloc.c
124 +++ b/mm/vmalloc.c
125 @@ -2684,6 +2684,8 @@ static const struct file_operations proc
126  
127  static int __init proc_vmalloc_init(void)
128  {
129 +       if (IS_ENABLED(CONFIG_PROC_STRIPPED))
130 +               return 0;
131         proc_create("vmallocinfo", S_IRUSR, NULL, &proc_vmalloc_operations);
132         return 0;
133  }
134 --- a/mm/vmstat.c
135 +++ b/mm/vmstat.c
136 @@ -1553,10 +1553,12 @@ static int __init setup_vmstat(void)
137         cpu_notifier_register_done();
138  #endif
139  #ifdef CONFIG_PROC_FS
140 -       proc_create("buddyinfo", S_IRUGO, NULL, &fragmentation_file_operations);
141 -       proc_create("pagetypeinfo", S_IRUGO, NULL, &pagetypeinfo_file_ops);
142 +       if (!IS_ENABLED(CONFIG_PROC_STRIPPED)) {
143 +               proc_create("buddyinfo", S_IRUGO, NULL, &fragmentation_file_operations);
144 +               proc_create("pagetypeinfo", S_IRUGO, NULL, &pagetypeinfo_file_ops);
145 +               proc_create("zoneinfo", S_IRUGO, NULL, &proc_zoneinfo_file_operations);
146 +       }
147         proc_create("vmstat", S_IRUGO, NULL, &proc_vmstat_file_operations);
148 -       proc_create("zoneinfo", S_IRUGO, NULL, &proc_zoneinfo_file_operations);
149  #endif
150         return 0;
151  }
152 --- a/net/8021q/vlanproc.c
153 +++ b/net/8021q/vlanproc.c
154 @@ -127,6 +127,9 @@ void vlan_proc_cleanup(struct net *net)
155  {
156         struct vlan_net *vn = net_generic(net, vlan_net_id);
157  
158 +       if (IS_ENABLED(CONFIG_PROC_STRIPPED))
159 +               return;
160 +
161         if (vn->proc_vlan_conf)
162                 remove_proc_entry(name_conf, vn->proc_vlan_dir);
163  
164 @@ -146,6 +149,9 @@ int __net_init vlan_proc_init(struct net
165  {
166         struct vlan_net *vn = net_generic(net, vlan_net_id);
167  
168 +       if (IS_ENABLED(CONFIG_PROC_STRIPPED))
169 +               return 0;
170 +
171         vn->proc_vlan_dir = proc_net_mkdir(net, name_root, net->proc_net);
172         if (!vn->proc_vlan_dir)
173                 goto err;
174 --- a/net/core/sock.c
175 +++ b/net/core/sock.c
176 @@ -3035,6 +3035,8 @@ static __net_initdata struct pernet_oper
177  
178  static int __init proto_init(void)
179  {
180 +       if (IS_ENABLED(CONFIG_PROC_STRIPPED))
181 +               return 0;
182         return register_pernet_subsys(&proto_net_ops);
183  }
184  
185 --- a/net/ipv4/fib_trie.c
186 +++ b/net/ipv4/fib_trie.c
187 @@ -2646,10 +2646,12 @@ static const struct file_operations fib_
188  
189  int __net_init fib_proc_init(struct net *net)
190  {
191 -       if (!proc_create("fib_trie", S_IRUGO, net->proc_net, &fib_trie_fops))
192 +       if (!IS_ENABLED(CONFIG_PROC_STRIPPED) &&
193 +               !proc_create("fib_trie", S_IRUGO, net->proc_net, &fib_trie_fops))
194                 goto out1;
195  
196 -       if (!proc_create("fib_triestat", S_IRUGO, net->proc_net,
197 +       if (!IS_ENABLED(CONFIG_PROC_STRIPPED) &&
198 +               !proc_create("fib_triestat", S_IRUGO, net->proc_net,
199                          &fib_triestat_fops))
200                 goto out2;
201  
202 @@ -2659,17 +2661,21 @@ int __net_init fib_proc_init(struct net
203         return 0;
204  
205  out3:
206 -       remove_proc_entry("fib_triestat", net->proc_net);
207 +       if (!IS_ENABLED(CONFIG_PROC_STRIPPED))
208 +               remove_proc_entry("fib_triestat", net->proc_net);
209  out2:
210 -       remove_proc_entry("fib_trie", net->proc_net);
211 +       if (!IS_ENABLED(CONFIG_PROC_STRIPPED))
212 +               remove_proc_entry("fib_trie", net->proc_net);
213  out1:
214         return -ENOMEM;
215  }
216  
217  void __net_exit fib_proc_exit(struct net *net)
218  {
219 -       remove_proc_entry("fib_trie", net->proc_net);
220 -       remove_proc_entry("fib_triestat", net->proc_net);
221 +       if (!IS_ENABLED(CONFIG_PROC_STRIPPED)) {
222 +               remove_proc_entry("fib_trie", net->proc_net);
223 +               remove_proc_entry("fib_triestat", net->proc_net);
224 +       }
225         remove_proc_entry("route", net->proc_net);
226  }
227  
228 --- a/net/ipv4/proc.c
229 +++ b/net/ipv4/proc.c
230 @@ -539,6 +539,9 @@ static __net_initdata struct pernet_oper
231  
232  int __init ip_misc_proc_init(void)
233  {
234 +       if (IS_ENABLED(CONFIG_PROC_STRIPPED))
235 +               return 0;
236 +
237         return register_pernet_subsys(&ip_proc_ops);
238  }
239  
240 --- a/net/ipv4/route.c
241 +++ b/net/ipv4/route.c
242 @@ -420,6 +420,9 @@ static struct pernet_operations ip_rt_pr
243  
244  static int __init ip_rt_proc_init(void)
245  {
246 +       if (IS_ENABLED(CONFIG_PROC_STRIPPED))
247 +               return 0;
248 +
249         return register_pernet_subsys(&ip_rt_proc_ops);
250  }
251  
252 --- a/ipc/msg.c
253 +++ b/ipc/msg.c
254 @@ -1068,6 +1068,9 @@ void __init msg_init(void)
255  {
256         msg_init_ns(&init_ipc_ns);
257  
258 +       if (IS_ENABLED(CONFIG_PROC_STRIPPED))
259 +               return;
260 +
261         ipc_init_proc_interface("sysvipc/msg",
262                                 "       key      msqid perms      cbytes       qnum lspid lrpid   uid   gid  cuid  cgid      stime      rtime      ctime\n",
263                                 IPC_MSG_IDS, sysvipc_msg_proc_show);
264 --- a/ipc/sem.c
265 +++ b/ipc/sem.c
266 @@ -191,6 +191,8 @@ void sem_exit_ns(struct ipc_namespace *n
267  void __init sem_init(void)
268  {
269         sem_init_ns(&init_ipc_ns);
270 +       if (IS_ENABLED(CONFIG_PROC_STRIPPED))
271 +               return;
272         ipc_init_proc_interface("sysvipc/sem",
273                                 "       key      semid perms      nsems   uid   gid  cuid  cgid      otime      ctime\n",
274                                 IPC_SEM_IDS, sysvipc_sem_proc_show);
275 --- a/ipc/shm.c
276 +++ b/ipc/shm.c
277 @@ -118,6 +118,8 @@ pure_initcall(ipc_ns_init);
278  
279  void __init shm_init(void)
280  {
281 +       if (IS_ENABLED(CONFIG_PROC_STRIPPED))
282 +               return;
283         ipc_init_proc_interface("sysvipc/shm",
284  #if BITS_PER_LONG <= 32
285                                 "       key      shmid perms       size  cpid  lpid nattch   uid   gid  cuid  cgid      atime      dtime      ctime        rss       swap\n",
286 --- a/ipc/util.c
287 +++ b/ipc/util.c
288 @@ -121,6 +121,9 @@ void __init ipc_init_proc_interface(cons
289         struct proc_dir_entry *pde;
290         struct ipc_proc_iface *iface;
291  
292 +       if (IS_ENABLED(CONFIG_PROC_STRIPPED))
293 +               return;
294 +
295         iface = kmalloc(sizeof(*iface), GFP_KERNEL);
296         if (!iface)
297                 return;
298 --- a/net/core/net-procfs.c
299 +++ b/net/core/net-procfs.c
300 @@ -318,10 +318,12 @@ static int __net_init dev_proc_net_init(
301  
302         if (!proc_create("dev", S_IRUGO, net->proc_net, &dev_seq_fops))
303                 goto out;
304 -       if (!proc_create("softnet_stat", S_IRUGO, net->proc_net,
305 +       if (!IS_ENABLED(CONFIG_PROC_STRIPPED) &&
306 +               !proc_create("softnet_stat", S_IRUGO, net->proc_net,
307                          &softnet_seq_fops))
308                 goto out_dev;
309 -       if (!proc_create("ptype", S_IRUGO, net->proc_net, &ptype_seq_fops))
310 +       if (!IS_ENABLED(CONFIG_PROC_STRIPPED) &&
311 +               !proc_create("ptype", S_IRUGO, net->proc_net, &ptype_seq_fops))
312                 goto out_softnet;
313  
314         if (wext_proc_init(net))
315 @@ -330,9 +332,11 @@ static int __net_init dev_proc_net_init(
316  out:
317         return rc;
318  out_ptype:
319 -       remove_proc_entry("ptype", net->proc_net);
320 +       if (!IS_ENABLED(CONFIG_PROC_STRIPPED))
321 +               remove_proc_entry("ptype", net->proc_net);
322  out_softnet:
323 -       remove_proc_entry("softnet_stat", net->proc_net);
324 +       if (!IS_ENABLED(CONFIG_PROC_STRIPPED))
325 +               remove_proc_entry("softnet_stat", net->proc_net);
326  out_dev:
327         remove_proc_entry("dev", net->proc_net);
328         goto out;
329 @@ -342,8 +346,10 @@ static void __net_exit dev_proc_net_exit
330  {
331         wext_proc_exit(net);
332  
333 -       remove_proc_entry("ptype", net->proc_net);
334 -       remove_proc_entry("softnet_stat", net->proc_net);
335 +       if (!IS_ENABLED(CONFIG_PROC_STRIPPED)) {
336 +               remove_proc_entry("ptype", net->proc_net);
337 +               remove_proc_entry("softnet_stat", net->proc_net);
338 +       }
339         remove_proc_entry("dev", net->proc_net);
340  }
341  
342 --- a/include/net/snmp.h
343 +++ b/include/net/snmp.h
344 @@ -123,6 +123,30 @@ struct linux_xfrm_mib {
345  #define DECLARE_SNMP_STAT(type, name)  \
346         extern __typeof__(type) __percpu *name
347  
348 +#ifdef CONFIG_PROC_STRIPPED
349 +#define SNMP_INC_STATS_BH(mib, field)  \
350 +       do { (void) mib->mibs[0]; } while(0)
351 +#define SNMP_INC_STATS_USER(mib, field)        \
352 +       do { (void) mib->mibs[0]; } while(0)
353 +#define SNMP_INC_STATS_ATOMIC_LONG(mib, field) \
354 +       do { (void) mib->mibs[0]; } while(0)
355 +#define SNMP_INC_STATS(mib, field)     \
356 +       do { (void) mib->mibs[0]; } while(0)
357 +#define SNMP_DEC_STATS(mib, field)     \
358 +       do { (void) mib->mibs[0]; } while(0)
359 +#define SNMP_ADD_STATS_BH(mib, field, addend)  \
360 +       do { (void) mib->mibs[0]; } while(0)
361 +#define SNMP_ADD_STATS_USER(mib, field, addend)        \
362 +       do { (void) mib->mibs[0]; } while(0)
363 +#define SNMP_ADD_STATS(mib, field, addend)     \
364 +       do { (void) mib->mibs[0]; } while(0)
365 +#define SNMP_UPD_PO_STATS(mib, basefield, addend)      \
366 +       do { (void) mib->mibs[0]; } while(0)
367 +#define SNMP_UPD_PO_STATS_BH(mib, basefield, addend)   \
368 +       do { (void) mib->mibs[0]; } while(0)
369 +
370 +#else
371 +
372  #define SNMP_INC_STATS_BH(mib, field)  \
373                         __this_cpu_inc(mib->mibs[field])
374  
375 @@ -159,8 +183,9 @@ struct linux_xfrm_mib {
376                 __this_cpu_add(ptr[basefield##OCTETS], addend); \
377         } while (0)
378  
379 +#endif
380  
381 -#if BITS_PER_LONG==32
382 +#if (BITS_PER_LONG==32) && !defined(CONFIG_PROC_STRIPPED)
383  
384  #define SNMP_ADD_STATS64_BH(mib, field, addend)                        \
385         do {                                                            \