Blame view

net/atm/proc.c 11.5 KB
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1
2
3
4
5
6
7
8
9
  /* net/atm/proc.c - ATM /proc interface
   *
   * Written 1995-2000 by Werner Almesberger, EPFL LRC/ICA
   *
   * seq_file api usage by romieu@fr.zoreil.com
   *
   * Evaluating the efficiency of the whole thing if left as an exercise to
   * the reader.
   */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
10
11
12
13
14
15
16
17
18
19
20
21
22
23
  #include <linux/module.h> /* for EXPORT_SYMBOL */
  #include <linux/string.h>
  #include <linux/types.h>
  #include <linux/mm.h>
  #include <linux/fs.h>
  #include <linux/stat.h>
  #include <linux/proc_fs.h>
  #include <linux/seq_file.h>
  #include <linux/errno.h>
  #include <linux/atm.h>
  #include <linux/atmdev.h>
  #include <linux/netdevice.h>
  #include <linux/atmclip.h>
  #include <linux/init.h> /* for __init */
5a0e3ad6a   Tejun Heo   include cleanup: ...
24
  #include <linux/slab.h>
457c4cbc5   Eric W. Biederman   [NET]: Make /proc...
25
  #include <net/net_namespace.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
26
  #include <net/atmclip.h>
07367adbe   Joe Perches   net/atm/proc.c: c...
27
28
  #include <linux/uaccess.h>
  #include <linux/param.h> /* for HZ */
60063497a   Arun Sharma   atomic: use <linu...
29
  #include <linux/atomic.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
30
31
32
  #include "resources.h"
  #include "common.h" /* atm_proc_init prototype */
  #include "signaling.h" /* to get sigd - ugly too */
07367adbe   Joe Perches   net/atm/proc.c: c...
33
34
  static ssize_t proc_dev_atm_read(struct file *file, char __user *buf,
  				 size_t count, loff_t *pos);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
35

9a32144e9   Arjan van de Ven   [PATCH] mark stru...
36
  static const struct file_operations proc_atm_dev_ops = {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
37
38
  	.owner =	THIS_MODULE,
  	.read =		proc_dev_atm_read,
6038f373a   Arnd Bergmann   llseek: automatic...
39
  	.llseek =	noop_llseek,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
40
41
42
43
44
45
  };
  
  static void add_stats(struct seq_file *seq, const char *aal,
    const struct k_atm_aal_stats *stats)
  {
  	seq_printf(seq, "%s ( %d %d %d %d %d )", aal,
07367adbe   Joe Perches   net/atm/proc.c: c...
46
47
48
  		   atomic_read(&stats->tx), atomic_read(&stats->tx_err),
  		   atomic_read(&stats->rx), atomic_read(&stats->rx_err),
  		   atomic_read(&stats->rx_drop));
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
  }
  
  static void atm_dev_info(struct seq_file *seq, const struct atm_dev *dev)
  {
  	int i;
  
  	seq_printf(seq, "%3d %-8s", dev->number, dev->type);
  	for (i = 0; i < ESI_LEN; i++)
  		seq_printf(seq, "%02x", dev->esi[i]);
  	seq_puts(seq, "  ");
  	add_stats(seq, "0", &dev->stats.aal0);
  	seq_puts(seq, "  ");
  	add_stats(seq, "5", &dev->stats.aal5);
  	seq_printf(seq, "\t[%d]", atomic_read(&dev->refcnt));
  	seq_putc(seq, '
  ');
  }
  
  struct vcc_state {
  	int bucket;
  	struct sock *sk;
  	int family;
  };
  
  static inline int compare_family(struct sock *sk, int family)
  {
  	return !family || (sk->sk_family == family);
  }
  
  static int __vcc_walk(struct sock **sock, int family, int *bucket, loff_t l)
  {
  	struct sock *sk = *sock;
2e1e9848a   Joe Perches   [ATM]: Use SEQ_ST...
81
  	if (sk == SEQ_START_TOKEN) {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
82
83
84
85
86
87
88
89
  		for (*bucket = 0; *bucket < VCC_HTABLE_SIZE; ++*bucket) {
  			struct hlist_head *head = &vcc_hash[*bucket];
  
  			sk = hlist_empty(head) ? NULL : __sk_head(head);
  			if (sk)
  				break;
  		}
  		l--;
f7d57453d   YOSHIFUJI Hideaki   [NET] ATM: Fix wh...
90
  	}
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
91
92
93
94
95
96
97
98
99
100
  try_again:
  	for (; sk; sk = sk_next(sk)) {
  		l -= compare_family(sk, family);
  		if (l < 0)
  			goto out;
  	}
  	if (!sk && ++*bucket < VCC_HTABLE_SIZE) {
  		sk = sk_head(&vcc_hash[*bucket]);
  		goto try_again;
  	}
2e1e9848a   Joe Perches   [ATM]: Use SEQ_ST...
101
  	sk = SEQ_START_TOKEN;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
102
103
104
105
106
107
108
109
110
111
112
113
  out:
  	*sock = sk;
  	return (l < 0);
  }
  
  static inline void *vcc_walk(struct vcc_state *state, loff_t l)
  {
  	return __vcc_walk(&state->sk, state->family, &state->bucket, l) ?
  	       state : NULL;
  }
  
  static int __vcc_seq_open(struct inode *inode, struct file *file,
ececfdee1   Al Viro   fallout from cons...
114
  	int family, const struct seq_operations *ops)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
115
116
  {
  	struct vcc_state *state;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
117

9a8c09e73   Pavel Emelyanov   [ATM]: Use seq_op...
118
119
120
  	state = __seq_open_private(file, ops, sizeof(*state));
  	if (state == NULL)
  		return -ENOMEM;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
121
122
  
  	state->family = family;
9a8c09e73   Pavel Emelyanov   [ATM]: Use seq_op...
123
  	return 0;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
124
125
126
  }
  
  static void *vcc_seq_start(struct seq_file *seq, loff_t *pos)
5c17d5f11   Eric Dumazet   [ATM]: Suppress s...
127
  	__acquires(vcc_sklist_lock)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
128
129
130
131
132
  {
  	struct vcc_state *state = seq->private;
  	loff_t left = *pos;
  
  	read_lock(&vcc_sklist_lock);
2e1e9848a   Joe Perches   [ATM]: Use SEQ_ST...
133
134
  	state->sk = SEQ_START_TOKEN;
  	return left ? vcc_walk(state, left) : SEQ_START_TOKEN;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
135
136
137
  }
  
  static void vcc_seq_stop(struct seq_file *seq, void *v)
5c17d5f11   Eric Dumazet   [ATM]: Suppress s...
138
  	__releases(vcc_sklist_lock)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
  {
  	read_unlock(&vcc_sklist_lock);
  }
  
  static void *vcc_seq_next(struct seq_file *seq, void *v, loff_t *pos)
  {
  	struct vcc_state *state = seq->private;
  
  	v = vcc_walk(state, 1);
  	*pos += !!PTR_ERR(v);
  	return v;
  }
  
  static void pvc_info(struct seq_file *seq, struct atm_vcc *vcc)
  {
07367adbe   Joe Perches   net/atm/proc.c: c...
154
155
  	static const char *const class_name[] = {
  		"off", "UBR", "CBR", "VBR", "ABR"};
36cbd3dcc   Jan Engelhardt   net: mark read-on...
156
  	static const char *const aal_name[] = {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
157
158
159
160
161
162
  		"---",	"1",	"2",	"3/4",	/*  0- 3 */
  		"???",	"5",	"???",	"???",	/*  4- 7 */
  		"???",	"???",	"???",	"???",	/*  8-11 */
  		"???",	"0",	"???",	"???"};	/* 12-15 */
  
  	seq_printf(seq, "%3d %3d %5d %-3s %7d %-5s %7d %-6s",
07367adbe   Joe Perches   net/atm/proc.c: c...
163
164
165
166
167
168
  		   vcc->dev->number, vcc->vpi, vcc->vci,
  		   vcc->qos.aal >= ARRAY_SIZE(aal_name) ? "err" :
  		   aal_name[vcc->qos.aal], vcc->qos.rxtp.min_pcr,
  		   class_name[vcc->qos.rxtp.traffic_class],
  		   vcc->qos.txtp.min_pcr,
  		   class_name[vcc->qos.txtp.traffic_class]);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
  	if (test_bit(ATM_VF_IS_CLIP, &vcc->flags)) {
  		struct clip_vcc *clip_vcc = CLIP_VCC(vcc);
  		struct net_device *dev;
  
  		dev = clip_vcc->entry ? clip_vcc->entry->neigh->dev : NULL;
  		seq_printf(seq, "CLIP, Itf:%s, Encap:",
  		    dev ? dev->name : "none?");
  		seq_printf(seq, "%s", clip_vcc->encap ? "LLC/SNAP" : "None");
  	}
  	seq_putc(seq, '
  ');
  }
  
  static const char *vcc_state(struct atm_vcc *vcc)
  {
36cbd3dcc   Jan Engelhardt   net: mark read-on...
184
  	static const char *const map[] = { ATM_VS2TXT_MAP };
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
185
186
187
188
189
190
191
  
  	return map[ATM_VF2VS(vcc->flags)];
  }
  
  static void vcc_info(struct seq_file *seq, struct atm_vcc *vcc)
  {
  	struct sock *sk = sk_atm(vcc);
71338aa7d   Dan Rosenberg   net: convert %p u...
192
  	seq_printf(seq, "%pK ", vcc);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
193
194
  	if (!vcc->dev)
  		seq_printf(seq, "Unassigned    ");
f7d57453d   YOSHIFUJI Hideaki   [NET] ATM: Fix wh...
195
  	else
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
196
197
198
  		seq_printf(seq, "%3d %3d %5d ", vcc->dev->number, vcc->vpi,
  			vcc->vci);
  	switch (sk->sk_family) {
07367adbe   Joe Perches   net/atm/proc.c: c...
199
200
201
202
203
204
205
206
  	case AF_ATMPVC:
  		seq_printf(seq, "PVC");
  		break;
  	case AF_ATMSVC:
  		seq_printf(seq, "SVC");
  		break;
  	default:
  		seq_printf(seq, "%3d", sk->sk_family);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
207
  	}
07367adbe   Joe Perches   net/atm/proc.c: c...
208
209
210
211
212
213
  	seq_printf(seq, " %04lx  %5d %7d/%7d %7d/%7d [%d]
  ",
  		   vcc->flags, sk->sk_err,
  		   sk_wmem_alloc_get(sk), sk->sk_sndbuf,
  		   sk_rmem_alloc_get(sk), sk->sk_rcvbuf,
  		   atomic_read(&sk->sk_refcnt));
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
214
215
216
217
218
219
  }
  
  static void svc_info(struct seq_file *seq, struct atm_vcc *vcc)
  {
  	if (!vcc->dev)
  		seq_printf(seq, sizeof(void *) == 4 ?
71338aa7d   Dan Rosenberg   net: convert %p u...
220
  			   "N/A@%pK%10s" : "N/A@%pK%2s", vcc, "");
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
  	else
  		seq_printf(seq, "%3d %3d %5d         ",
  			   vcc->dev->number, vcc->vpi, vcc->vci);
  	seq_printf(seq, "%-10s ", vcc_state(vcc));
  	seq_printf(seq, "%s%s", vcc->remote.sas_addr.pub,
  	    *vcc->remote.sas_addr.pub && *vcc->remote.sas_addr.prv ? "+" : "");
  	if (*vcc->remote.sas_addr.prv) {
  		int i;
  
  		for (i = 0; i < ATM_ESA_LEN; i++)
  			seq_printf(seq, "%02x", vcc->remote.sas_addr.prv[i]);
  	}
  	seq_putc(seq, '
  ');
  }
  
  static int atm_dev_seq_show(struct seq_file *seq, void *v)
  {
  	static char atm_dev_banner[] =
  		"Itf Type    ESI/\"MAC\"addr "
  		"AAL(TX,err,RX,err,drop) ...               [refcnt]
  ";
f7d57453d   YOSHIFUJI Hideaki   [NET] ATM: Fix wh...
243

67de79242   Li Zefan   net: atm: use seq...
244
  	if (v == &atm_devs)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
245
246
247
248
249
250
  		seq_puts(seq, atm_dev_banner);
  	else {
  		struct atm_dev *dev = list_entry(v, struct atm_dev, dev_list);
  
  		atm_dev_info(seq, dev);
  	}
f7d57453d   YOSHIFUJI Hideaki   [NET] ATM: Fix wh...
251
  	return 0;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
252
  }
f7d57453d   YOSHIFUJI Hideaki   [NET] ATM: Fix wh...
253

56b3d975b   Philippe De Muyter   [NET]: Make all i...
254
  static const struct seq_operations atm_dev_seq_ops = {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
255
256
257
258
259
  	.start	= atm_dev_seq_start,
  	.next	= atm_dev_seq_next,
  	.stop	= atm_dev_seq_stop,
  	.show	= atm_dev_seq_show,
  };
f7d57453d   YOSHIFUJI Hideaki   [NET] ATM: Fix wh...
260

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
261
262
263
264
  static int atm_dev_seq_open(struct inode *inode, struct file *file)
  {
  	return seq_open(file, &atm_dev_seq_ops);
  }
f7d57453d   YOSHIFUJI Hideaki   [NET] ATM: Fix wh...
265

9a32144e9   Arjan van de Ven   [PATCH] mark stru...
266
  static const struct file_operations devices_seq_fops = {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
267
268
269
270
271
272
273
274
  	.open		= atm_dev_seq_open,
  	.read		= seq_read,
  	.llseek		= seq_lseek,
  	.release	= seq_release,
  };
  
  static int pvc_seq_show(struct seq_file *seq, void *v)
  {
f7d57453d   YOSHIFUJI Hideaki   [NET] ATM: Fix wh...
275
  	static char atm_pvc_banner[] =
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
276
277
  		"Itf VPI VCI   AAL RX(PCR,Class) TX(PCR,Class)
  ";
2e1e9848a   Joe Perches   [ATM]: Use SEQ_ST...
278
  	if (v == SEQ_START_TOKEN)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
279
280
281
282
283
284
285
286
287
  		seq_puts(seq, atm_pvc_banner);
  	else {
  		struct vcc_state *state = seq->private;
  		struct atm_vcc *vcc = atm_sk(state->sk);
  
  		pvc_info(seq, vcc);
  	}
  	return 0;
  }
56b3d975b   Philippe De Muyter   [NET]: Make all i...
288
  static const struct seq_operations pvc_seq_ops = {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
289
290
291
292
293
294
295
296
297
298
  	.start	= vcc_seq_start,
  	.next	= vcc_seq_next,
  	.stop	= vcc_seq_stop,
  	.show	= pvc_seq_show,
  };
  
  static int pvc_seq_open(struct inode *inode, struct file *file)
  {
  	return __vcc_seq_open(inode, file, PF_ATMPVC, &pvc_seq_ops);
  }
9a32144e9   Arjan van de Ven   [PATCH] mark stru...
299
  static const struct file_operations pvc_seq_fops = {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
300
301
302
  	.open		= pvc_seq_open,
  	.read		= seq_read,
  	.llseek		= seq_lseek,
9a8c09e73   Pavel Emelyanov   [ATM]: Use seq_op...
303
  	.release	= seq_release_private,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
304
305
306
307
  };
  
  static int vcc_seq_show(struct seq_file *seq, void *v)
  {
2e1e9848a   Joe Perches   [ATM]: Use SEQ_ST...
308
  	if (v == SEQ_START_TOKEN) {
f7d57453d   YOSHIFUJI Hideaki   [NET] ATM: Fix wh...
309
310
311
312
313
314
315
316
317
318
319
  		seq_printf(seq, sizeof(void *) == 4 ? "%-8s%s" : "%-16s%s",
  			"Address ", "Itf VPI VCI   Fam Flags Reply "
  			"Send buffer     Recv buffer      [refcnt]
  ");
  	} else {
  		struct vcc_state *state = seq->private;
  		struct atm_vcc *vcc = atm_sk(state->sk);
  
  		vcc_info(seq, vcc);
  	}
  	return 0;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
320
  }
f7d57453d   YOSHIFUJI Hideaki   [NET] ATM: Fix wh...
321

56b3d975b   Philippe De Muyter   [NET]: Make all i...
322
  static const struct seq_operations vcc_seq_ops = {
f7d57453d   YOSHIFUJI Hideaki   [NET] ATM: Fix wh...
323
324
325
326
  	.start	= vcc_seq_start,
  	.next	= vcc_seq_next,
  	.stop	= vcc_seq_stop,
  	.show	= vcc_seq_show,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
327
  };
f7d57453d   YOSHIFUJI Hideaki   [NET] ATM: Fix wh...
328

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
329
330
  static int vcc_seq_open(struct inode *inode, struct file *file)
  {
f7d57453d   YOSHIFUJI Hideaki   [NET] ATM: Fix wh...
331
  	return __vcc_seq_open(inode, file, 0, &vcc_seq_ops);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
332
  }
f7d57453d   YOSHIFUJI Hideaki   [NET] ATM: Fix wh...
333

9a32144e9   Arjan van de Ven   [PATCH] mark stru...
334
  static const struct file_operations vcc_seq_fops = {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
335
336
337
  	.open		= vcc_seq_open,
  	.read		= seq_read,
  	.llseek		= seq_lseek,
9a8c09e73   Pavel Emelyanov   [ATM]: Use seq_op...
338
  	.release	= seq_release_private,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
339
340
341
342
  };
  
  static int svc_seq_show(struct seq_file *seq, void *v)
  {
36cbd3dcc   Jan Engelhardt   net: mark read-on...
343
  	static const char atm_svc_banner[] =
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
344
345
  		"Itf VPI VCI           State      Remote
  ";
2e1e9848a   Joe Perches   [ATM]: Use SEQ_ST...
346
  	if (v == SEQ_START_TOKEN)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
347
348
349
350
351
352
353
354
355
  		seq_puts(seq, atm_svc_banner);
  	else {
  		struct vcc_state *state = seq->private;
  		struct atm_vcc *vcc = atm_sk(state->sk);
  
  		svc_info(seq, vcc);
  	}
  	return 0;
  }
56b3d975b   Philippe De Muyter   [NET]: Make all i...
356
  static const struct seq_operations svc_seq_ops = {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
357
358
359
360
361
362
363
364
365
366
  	.start	= vcc_seq_start,
  	.next	= vcc_seq_next,
  	.stop	= vcc_seq_stop,
  	.show	= svc_seq_show,
  };
  
  static int svc_seq_open(struct inode *inode, struct file *file)
  {
  	return __vcc_seq_open(inode, file, PF_ATMSVC, &svc_seq_ops);
  }
9a32144e9   Arjan van de Ven   [PATCH] mark stru...
367
  static const struct file_operations svc_seq_fops = {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
368
369
370
  	.open		= svc_seq_open,
  	.read		= seq_read,
  	.llseek		= seq_lseek,
9a8c09e73   Pavel Emelyanov   [ATM]: Use seq_op...
371
  	.release	= seq_release_private,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
372
373
374
375
376
377
378
379
  };
  
  static ssize_t proc_dev_atm_read(struct file *file, char __user *buf,
  				 size_t count, loff_t *pos)
  {
  	struct atm_dev *dev;
  	unsigned long page;
  	int length;
07367adbe   Joe Perches   net/atm/proc.c: c...
380
381
  	if (count == 0)
  		return 0;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
382
  	page = get_zeroed_page(GFP_KERNEL);
07367adbe   Joe Perches   net/atm/proc.c: c...
383
384
  	if (!page)
  		return -ENOMEM;
76a0f1742   Josef Sipek   [PATCH] struct pa...
385
  	dev = PDE(file->f_path.dentry->d_inode)->data;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
386
387
388
  	if (!dev->ops->proc_read)
  		length = -EINVAL;
  	else {
07367adbe   Joe Perches   net/atm/proc.c: c...
389
390
391
  		length = dev->ops->proc_read(dev, pos, (char *)page);
  		if (length > count)
  			length = -EINVAL;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
392
393
  	}
  	if (length >= 0) {
07367adbe   Joe Perches   net/atm/proc.c: c...
394
395
  		if (copy_to_user(buf, (char *)page, length))
  			length = -EFAULT;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
396
397
398
399
400
  		(*pos)++;
  	}
  	free_page(page);
  	return length;
  }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
401
402
403
404
405
406
  struct proc_dir_entry *atm_proc_root;
  EXPORT_SYMBOL(atm_proc_root);
  
  
  int atm_proc_dev_register(struct atm_dev *dev)
  {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
407
408
409
410
411
412
413
  	int error;
  
  	/* No proc info */
  	if (!dev->ops->proc_read)
  		return 0;
  
  	error = -ENOMEM;
62c97ac04   Eric Dumazet   atm: Use kasprintf
414
  	dev->proc_name = kasprintf(GFP_KERNEL, "%s:%d", dev->type, dev->number);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
415
416
  	if (!dev->proc_name)
  		goto err_out;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
417

0c89652a7   Denis V. Lunev   atm: assign PDE->...
418
419
  	dev->proc_entry = proc_create_data(dev->proc_name, 0, atm_proc_root,
  					   &proc_atm_dev_ops, dev);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
420
421
  	if (!dev->proc_entry)
  		goto err_free_name;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
422
  	return 0;
07367adbe   Joe Perches   net/atm/proc.c: c...
423

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
424
425
426
427
428
  err_free_name:
  	kfree(dev->proc_name);
  err_out:
  	return error;
  }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
429
430
431
432
433
434
435
436
437
438
439
  void atm_proc_dev_deregister(struct atm_dev *dev)
  {
  	if (!dev->ops->proc_read)
  		return;
  
  	remove_proc_entry(dev->proc_name, atm_proc_root);
  	kfree(dev->proc_name);
  }
  
  static struct atm_proc_entry {
  	char *name;
9a32144e9   Arjan van de Ven   [PATCH] mark stru...
440
  	const struct file_operations *proc_fops;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
441
442
443
444
445
446
447
448
449
450
451
452
453
454
  	struct proc_dir_entry *dirent;
  } atm_proc_ents[] = {
  	{ .name = "devices",	.proc_fops = &devices_seq_fops },
  	{ .name = "pvc",	.proc_fops = &pvc_seq_fops },
  	{ .name = "svc",	.proc_fops = &svc_seq_fops },
  	{ .name = "vc",		.proc_fops = &vcc_seq_fops },
  	{ .name = NULL,		.proc_fops = NULL }
  };
  
  static void atm_proc_dirs_remove(void)
  {
  	static struct atm_proc_entry *e;
  
  	for (e = atm_proc_ents; e->name; e++) {
f7d57453d   YOSHIFUJI Hideaki   [NET] ATM: Fix wh...
455
  		if (e->dirent)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
456
457
  			remove_proc_entry(e->name, atm_proc_root);
  	}
e5d69b9f4   Denis V. Lunev   [ATM]: Oops readi...
458
  	proc_net_remove(&init_net, "atm");
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
459
460
461
462
463
464
  }
  
  int __init atm_proc_init(void)
  {
  	static struct atm_proc_entry *e;
  	int ret;
e5d69b9f4   Denis V. Lunev   [ATM]: Oops readi...
465
  	atm_proc_root = proc_net_mkdir(&init_net, "atm", init_net.proc_net);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
466
467
468
469
  	if (!atm_proc_root)
  		goto err_out;
  	for (e = atm_proc_ents; e->name; e++) {
  		struct proc_dir_entry *dirent;
16e297b35   Wang Chen   [ATM]: Use proc_c...
470
471
  		dirent = proc_create(e->name, S_IRUGO,
  				     atm_proc_root, e->proc_fops);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
472
473
  		if (!dirent)
  			goto err_out_remove;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
474
475
476
477
478
479
480
481
482
483
484
485
  		e->dirent = dirent;
  	}
  	ret = 0;
  out:
  	return ret;
  
  err_out_remove:
  	atm_proc_dirs_remove();
  err_out:
  	ret = -ENOMEM;
  	goto out;
  }
b9c6e3e96   Kevin Hilman   [ATM]: Compile er...
486
  void atm_proc_exit(void)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
487
488
489
  {
  	atm_proc_dirs_remove();
  }