Blame view

drivers/parport/procfs.c 12.3 KB
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1
2
  /* Sysctl interface for parport devices.
   * 
bdca3f202   Adrian Bunk   remove the bounci...
3
   * Authors: David Campbell
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
4
5
6
7
8
9
10
11
12
13
14
15
   *          Tim Waugh <tim@cyberelk.demon.co.uk>
   *          Philip Blundell <philb@gnu.org>
   *          Andrea Arcangeli
   *          Riccardo Facchetti <fizban@tin.it>
   *
   * based on work by Grant Guenther <grant@torque.net>
   *              and Philip Blundell
   *
   * Cleaned up include files - Russell King <linux@arm.uk.linux.org>
   */
  
  #include <linux/string.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
  #include <linux/init.h>
  #include <linux/module.h>
  #include <linux/errno.h>
  #include <linux/kernel.h>
  #include <linux/slab.h>
  #include <linux/parport.h>
  #include <linux/ctype.h>
  #include <linux/sysctl.h>
  
  #include <asm/uaccess.h>
  
  #if defined(CONFIG_SYSCTL) && defined(CONFIG_PROC_FS)
  
  #define PARPORT_MIN_TIMESLICE_VALUE 1ul 
  #define PARPORT_MAX_TIMESLICE_VALUE ((unsigned long) HZ)
  #define PARPORT_MIN_SPINTIME_VALUE 1
  #define PARPORT_MAX_SPINTIME_VALUE 1000
be424c63a   Joe Perches   parport: convert ...
33
  static int do_active_device(struct ctl_table *table, int write,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
  		      void __user *result, size_t *lenp, loff_t *ppos)
  {
  	struct parport *port = (struct parport *)table->extra1;
  	char buffer[256];
  	struct pardevice *dev;
  	int len = 0;
  
  	if (write)		/* can't happen anyway */
  		return -EACCES;
  
  	if (*ppos) {
  		*lenp = 0;
  		return 0;
  	}
  	
  	for (dev = port->devices; dev ; dev = dev->next) {
  		if(dev == port->cad) {
  			len += sprintf(buffer, "%s
  ", dev->name);
  		}
  	}
  
  	if(!len) {
  		len += sprintf(buffer, "%s
  ", "none");
  	}
  
  	if (len > *lenp)
  		len = *lenp;
  	else
  		*lenp = len;
  
  	*ppos += len;
  
  	return copy_to_user(result, buffer, len) ? -EFAULT : 0;
  }
  
  #ifdef CONFIG_PARPORT_1284
be424c63a   Joe Perches   parport: convert ...
72
  static int do_autoprobe(struct ctl_table *table, int write,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
  			void __user *result, size_t *lenp, loff_t *ppos)
  {
  	struct parport_device_info *info = table->extra2;
  	const char *str;
  	char buffer[256];
  	int len = 0;
  
  	if (write) /* permissions stop this */
  		return -EACCES;
  
  	if (*ppos) {
  		*lenp = 0;
  		return 0;
  	}
  	
  	if ((str = info->class_name) != NULL)
  		len += sprintf (buffer + len, "CLASS:%s;
  ", str);
  
  	if ((str = info->model) != NULL)
  		len += sprintf (buffer + len, "MODEL:%s;
  ", str);
  
  	if ((str = info->mfr) != NULL)
  		len += sprintf (buffer + len, "MANUFACTURER:%s;
  ", str);
  
  	if ((str = info->description) != NULL)
  		len += sprintf (buffer + len, "DESCRIPTION:%s;
  ", str);
  
  	if ((str = info->cmdset) != NULL)
  		len += sprintf (buffer + len, "COMMAND SET:%s;
  ", str);
  
  	if (len > *lenp)
  		len = *lenp;
  	else
  		*lenp = len;
  
  	*ppos += len;
  
  	return copy_to_user (result, buffer, len) ? -EFAULT : 0;
  }
  #endif /* IEEE1284.3 support. */
be424c63a   Joe Perches   parport: convert ...
118
119
120
  static int do_hardware_base_addr(struct ctl_table *table, int write,
  				 void __user *result,
  				 size_t *lenp, loff_t *ppos)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
  {
  	struct parport *port = (struct parport *)table->extra1;
  	char buffer[20];
  	int len = 0;
  
  	if (*ppos) {
  		*lenp = 0;
  		return 0;
  	}
  
  	if (write) /* permissions prevent this anyway */
  		return -EACCES;
  
  	len += sprintf (buffer, "%lu\t%lu
  ", port->base, port->base_hi);
  
  	if (len > *lenp)
  		len = *lenp;
  	else
  		*lenp = len;
  
  	*ppos += len;
  
  	return copy_to_user(result, buffer, len) ? -EFAULT : 0;
  }
be424c63a   Joe Perches   parport: convert ...
146
147
148
  static int do_hardware_irq(struct ctl_table *table, int write,
  			   void __user *result,
  			   size_t *lenp, loff_t *ppos)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
  {
  	struct parport *port = (struct parport *)table->extra1;
  	char buffer[20];
  	int len = 0;
  
  	if (*ppos) {
  		*lenp = 0;
  		return 0;
  	}
  
  	if (write) /* permissions prevent this anyway */
  		return -EACCES;
  
  	len += sprintf (buffer, "%d
  ", port->irq);
  
  	if (len > *lenp)
  		len = *lenp;
  	else
  		*lenp = len;
  
  	*ppos += len;
  
  	return copy_to_user(result, buffer, len) ? -EFAULT : 0;
  }
be424c63a   Joe Perches   parport: convert ...
174
175
176
  static int do_hardware_dma(struct ctl_table *table, int write,
  			   void __user *result,
  			   size_t *lenp, loff_t *ppos)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
  {
  	struct parport *port = (struct parport *)table->extra1;
  	char buffer[20];
  	int len = 0;
  
  	if (*ppos) {
  		*lenp = 0;
  		return 0;
  	}
  
  	if (write) /* permissions prevent this anyway */
  		return -EACCES;
  
  	len += sprintf (buffer, "%d
  ", port->dma);
  
  	if (len > *lenp)
  		len = *lenp;
  	else
  		*lenp = len;
  
  	*ppos += len;
  
  	return copy_to_user(result, buffer, len) ? -EFAULT : 0;
  }
be424c63a   Joe Perches   parport: convert ...
202
203
204
  static int do_hardware_modes(struct ctl_table *table, int write,
  			     void __user *result,
  			     size_t *lenp, loff_t *ppos)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
  {
  	struct parport *port = (struct parport *)table->extra1;
  	char buffer[40];
  	int len = 0;
  
  	if (*ppos) {
  		*lenp = 0;
  		return 0;
  	}
  
  	if (write) /* permissions prevent this anyway */
  		return -EACCES;
  
  	{
  #define printmode(x) {if(port->modes&PARPORT_MODE_##x){len+=sprintf(buffer+len,"%s%s",f?",":"",#x);f++;}}
  		int f = 0;
  		printmode(PCSPP);
  		printmode(TRISTATE);
  		printmode(COMPAT);
  		printmode(EPP);
  		printmode(ECP);
  		printmode(DMA);
  #undef printmode
  	}
  	buffer[len++] = '
  ';
  
  	if (len > *lenp)
  		len = *lenp;
  	else
  		*lenp = len;
  
  	*ppos += len;
  
  	return copy_to_user(result, buffer, len) ? -EFAULT : 0;
  }
894d24911   Eric W. Biederman   sysctl drivers: R...
241
242
  #define PARPORT_PORT_DIR(CHILD) { .procname = NULL, .mode = 0555, .child = CHILD }
  #define PARPORT_PARPORT_DIR(CHILD) { .procname = "parport", \
2564b7bd9   Eric W. Biederman   [PATCH] sysctl: C...
243
                                       .mode = 0555, .child = CHILD }
894d24911   Eric W. Biederman   sysctl drivers: R...
244
  #define PARPORT_DEV_DIR(CHILD) { .procname = "dev", .mode = 0555, .child = CHILD }
25398a158   Eric W. Biederman   sysctl: parport r...
245
  #define PARPORT_DEVICES_ROOT_DIR  {  .procname = "devices", \
2564b7bd9   Eric W. Biederman   [PATCH] sysctl: C...
246
                                      .mode = 0555, .child = NULL }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
  
  static const unsigned long parport_min_timeslice_value =
  PARPORT_MIN_TIMESLICE_VALUE;
  
  static const unsigned long parport_max_timeslice_value =
  PARPORT_MAX_TIMESLICE_VALUE;
  
  static const  int parport_min_spintime_value =
  PARPORT_MIN_SPINTIME_VALUE;
  
  static const int parport_max_spintime_value =
  PARPORT_MAX_SPINTIME_VALUE;
  
  
  struct parport_sysctl_table {
  	struct ctl_table_header *sysctl_header;
be424c63a   Joe Perches   parport: convert ...
263
264
265
266
267
  	struct ctl_table vars[12];
  	struct ctl_table device_dir[2];
  	struct ctl_table port_dir[2];
  	struct ctl_table parport_dir[2];
  	struct ctl_table dev_dir[2];
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
268
269
270
  };
  
  static const struct parport_sysctl_table parport_sysctl_template = {
2564b7bd9   Eric W. Biederman   [PATCH] sysctl: C...
271
  	.sysctl_header = NULL,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
272
          {
2564b7bd9   Eric W. Biederman   [PATCH] sysctl: C...
273
  		{
2564b7bd9   Eric W. Biederman   [PATCH] sysctl: C...
274
275
276
277
  			.procname	= "spintime",
  			.data		= NULL,
  			.maxlen		= sizeof(int),
  			.mode		= 0644,
6d4561110   Eric W. Biederman   sysctl: Drop & in...
278
  			.proc_handler	= proc_dointvec_minmax,
2564b7bd9   Eric W. Biederman   [PATCH] sysctl: C...
279
280
281
282
  			.extra1		= (void*) &parport_min_spintime_value,
  			.extra2		= (void*) &parport_max_spintime_value
  		},
  		{
2564b7bd9   Eric W. Biederman   [PATCH] sysctl: C...
283
284
285
286
  			.procname	= "base-addr",
  			.data		= NULL,
  			.maxlen		= 0,
  			.mode		= 0444,
6d4561110   Eric W. Biederman   sysctl: Drop & in...
287
  			.proc_handler	= do_hardware_base_addr
2564b7bd9   Eric W. Biederman   [PATCH] sysctl: C...
288
289
  		},
  		{
2564b7bd9   Eric W. Biederman   [PATCH] sysctl: C...
290
291
292
293
  			.procname	= "irq",
  			.data		= NULL,
  			.maxlen		= 0,
  			.mode		= 0444,
6d4561110   Eric W. Biederman   sysctl: Drop & in...
294
  			.proc_handler	= do_hardware_irq
2564b7bd9   Eric W. Biederman   [PATCH] sysctl: C...
295
296
  		},
  		{
2564b7bd9   Eric W. Biederman   [PATCH] sysctl: C...
297
298
299
300
  			.procname	= "dma",
  			.data		= NULL,
  			.maxlen		= 0,
  			.mode		= 0444,
6d4561110   Eric W. Biederman   sysctl: Drop & in...
301
  			.proc_handler	= do_hardware_dma
2564b7bd9   Eric W. Biederman   [PATCH] sysctl: C...
302
303
  		},
  		{
2564b7bd9   Eric W. Biederman   [PATCH] sysctl: C...
304
305
306
307
  			.procname	= "modes",
  			.data		= NULL,
  			.maxlen		= 0,
  			.mode		= 0444,
6d4561110   Eric W. Biederman   sysctl: Drop & in...
308
  			.proc_handler	= do_hardware_modes
2564b7bd9   Eric W. Biederman   [PATCH] sysctl: C...
309
  		},
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
310
311
  		PARPORT_DEVICES_ROOT_DIR,
  #ifdef CONFIG_PARPORT_1284
2564b7bd9   Eric W. Biederman   [PATCH] sysctl: C...
312
  		{
2564b7bd9   Eric W. Biederman   [PATCH] sysctl: C...
313
314
315
316
  			.procname	= "autoprobe",
  			.data		= NULL,
  			.maxlen		= 0,
  			.mode		= 0444,
6d4561110   Eric W. Biederman   sysctl: Drop & in...
317
  			.proc_handler	= do_autoprobe
2564b7bd9   Eric W. Biederman   [PATCH] sysctl: C...
318
319
  		},
  		{
2564b7bd9   Eric W. Biederman   [PATCH] sysctl: C...
320
321
322
323
  			.procname	= "autoprobe0",
  			.data		= NULL,
  			.maxlen		= 0,
  			.mode		= 0444,
6d4561110   Eric W. Biederman   sysctl: Drop & in...
324
  			.proc_handler	= do_autoprobe
2564b7bd9   Eric W. Biederman   [PATCH] sysctl: C...
325
326
  		},
  		{
2564b7bd9   Eric W. Biederman   [PATCH] sysctl: C...
327
328
329
330
  			.procname	= "autoprobe1",
  			.data		= NULL,
  			.maxlen		= 0,
  			.mode		= 0444,
6d4561110   Eric W. Biederman   sysctl: Drop & in...
331
  			.proc_handler	= do_autoprobe
2564b7bd9   Eric W. Biederman   [PATCH] sysctl: C...
332
333
  		},
  		{
2564b7bd9   Eric W. Biederman   [PATCH] sysctl: C...
334
335
336
337
  			.procname	= "autoprobe2",
  			.data		= NULL,
  			.maxlen		= 0,
  			.mode		= 0444,
6d4561110   Eric W. Biederman   sysctl: Drop & in...
338
  			.proc_handler	= do_autoprobe
2564b7bd9   Eric W. Biederman   [PATCH] sysctl: C...
339
340
  		},
  		{
2564b7bd9   Eric W. Biederman   [PATCH] sysctl: C...
341
342
343
344
  			.procname	= "autoprobe3",
  			.data		= NULL,
  			.maxlen		= 0,
  			.mode		= 0444,
6d4561110   Eric W. Biederman   sysctl: Drop & in...
345
  			.proc_handler	= do_autoprobe
2564b7bd9   Eric W. Biederman   [PATCH] sysctl: C...
346
  		},
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
347
  #endif /* IEEE 1284 support */
2564b7bd9   Eric W. Biederman   [PATCH] sysctl: C...
348
  		{}
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
349
  	},
2564b7bd9   Eric W. Biederman   [PATCH] sysctl: C...
350
351
  	{
  		{
2564b7bd9   Eric W. Biederman   [PATCH] sysctl: C...
352
353
354
355
  			.procname	= "active",
  			.data		= NULL,
  			.maxlen		= 0,
  			.mode		= 0444,
6d4561110   Eric W. Biederman   sysctl: Drop & in...
356
  			.proc_handler	= do_active_device
2564b7bd9   Eric W. Biederman   [PATCH] sysctl: C...
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
  		},
  		{}
  	},
  	{
  		PARPORT_PORT_DIR(NULL),
  		{}
  	},
  	{
  		PARPORT_PARPORT_DIR(NULL),
  		{}
  	},
  	{
  		PARPORT_DEV_DIR(NULL),
  		{}
  	}
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
372
373
374
375
376
  };
  
  struct parport_device_sysctl_table
  {
  	struct ctl_table_header *sysctl_header;
be424c63a   Joe Perches   parport: convert ...
377
378
379
380
381
382
  	struct ctl_table vars[2];
  	struct ctl_table device_dir[2];
  	struct ctl_table devices_root_dir[2];
  	struct ctl_table port_dir[2];
  	struct ctl_table parport_dir[2];
  	struct ctl_table dev_dir[2];
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
383
384
385
386
  };
  
  static const struct parport_device_sysctl_table
  parport_device_sysctl_template = {
2564b7bd9   Eric W. Biederman   [PATCH] sysctl: C...
387
388
389
  	.sysctl_header = NULL,
  	{
  		{
2564b7bd9   Eric W. Biederman   [PATCH] sysctl: C...
390
391
  			.procname 	= "timeslice",
  			.data		= NULL,
60af88033   Eric Dumazet   parport: "dev->ti...
392
  			.maxlen		= sizeof(unsigned long),
2564b7bd9   Eric W. Biederman   [PATCH] sysctl: C...
393
  			.mode		= 0644,
6d4561110   Eric W. Biederman   sysctl: Drop & in...
394
  			.proc_handler	= proc_doulongvec_ms_jiffies_minmax,
2564b7bd9   Eric W. Biederman   [PATCH] sysctl: C...
395
396
397
398
399
400
  			.extra1		= (void*) &parport_min_timeslice_value,
  			.extra2		= (void*) &parport_max_timeslice_value
  		},
  	},
  	{
  		{
2564b7bd9   Eric W. Biederman   [PATCH] sysctl: C...
401
402
403
404
405
406
407
408
  			.procname	= NULL,
  			.data		= NULL,
  			.maxlen		= 0,
  			.mode		= 0555,
  			.child		= NULL
  		},
  		{}
  	},
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
409
  	{
2564b7bd9   Eric W. Biederman   [PATCH] sysctl: C...
410
411
412
413
414
415
  		PARPORT_DEVICES_ROOT_DIR,
  		{}
  	},
  	{
  		PARPORT_PORT_DIR(NULL),
  		{}
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
416
  	},
2564b7bd9   Eric W. Biederman   [PATCH] sysctl: C...
417
418
419
420
421
422
423
424
  	{
  		PARPORT_PARPORT_DIR(NULL),
  		{}
  	},
  	{
  		PARPORT_DEV_DIR(NULL),
  		{}
  	}
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
425
426
427
428
429
  };
  
  struct parport_default_sysctl_table
  {
  	struct ctl_table_header *sysctl_header;
be424c63a   Joe Perches   parport: convert ...
430
431
432
433
  	struct ctl_table vars[3];
  	struct ctl_table default_dir[2];
  	struct ctl_table parport_dir[2];
  	struct ctl_table dev_dir[2];
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
434
  };
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
435
436
  static struct parport_default_sysctl_table
  parport_default_sysctl_table = {
2564b7bd9   Eric W. Biederman   [PATCH] sysctl: C...
437
438
439
  	.sysctl_header	= NULL,
  	{
  		{
2564b7bd9   Eric W. Biederman   [PATCH] sysctl: C...
440
441
442
443
  			.procname	= "timeslice",
  			.data		= &parport_default_timeslice,
  			.maxlen		= sizeof(parport_default_timeslice),
  			.mode		= 0644,
6d4561110   Eric W. Biederman   sysctl: Drop & in...
444
  			.proc_handler	= proc_doulongvec_ms_jiffies_minmax,
2564b7bd9   Eric W. Biederman   [PATCH] sysctl: C...
445
446
447
448
  			.extra1		= (void*) &parport_min_timeslice_value,
  			.extra2		= (void*) &parport_max_timeslice_value
  		},
  		{
2564b7bd9   Eric W. Biederman   [PATCH] sysctl: C...
449
450
451
452
  			.procname	= "spintime",
  			.data		= &parport_default_spintime,
  			.maxlen		= sizeof(parport_default_spintime),
  			.mode		= 0644,
6d4561110   Eric W. Biederman   sysctl: Drop & in...
453
  			.proc_handler	= proc_dointvec_minmax,
2564b7bd9   Eric W. Biederman   [PATCH] sysctl: C...
454
455
456
457
458
  			.extra1		= (void*) &parport_min_spintime_value,
  			.extra2		= (void*) &parport_max_spintime_value
  		},
  		{}
  	},
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
459
  	{
2564b7bd9   Eric W. Biederman   [PATCH] sysctl: C...
460
  		{
2564b7bd9   Eric W. Biederman   [PATCH] sysctl: C...
461
462
463
464
465
  			.procname	= "default",
  			.mode		= 0555,
  			.child		= parport_default_sysctl_table.vars
  		},
  		{}
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
466
  	},
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
467
  	{
2564b7bd9   Eric W. Biederman   [PATCH] sysctl: C...
468
469
470
471
472
473
474
  		PARPORT_PARPORT_DIR(parport_default_sysctl_table.default_dir),
  		{}
  	},
  	{
  		PARPORT_DEV_DIR(parport_default_sysctl_table.parport_dir),
  		{}
  	}
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
475
476
477
478
479
480
481
  };
  
  
  int parport_proc_register(struct parport *port)
  {
  	struct parport_sysctl_table *t;
  	int i;
2451a8483   Silviu-Mihai Popescu   parport: use kmem...
482
  	t = kmemdup(&parport_sysctl_template, sizeof(*t), GFP_KERNEL);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
483
484
  	if (t == NULL)
  		return -ENOMEM;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
485
486
  
  	t->device_dir[0].extra1 = port;
25398a158   Eric W. Biederman   sysctl: parport r...
487
  	for (i = 0; i < 5; i++)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
488
489
490
491
492
493
494
495
496
  		t->vars[i].extra1 = port;
  
  	t->vars[0].data = &port->spintime;
  	t->vars[5].child = t->device_dir;
  	
  	for (i = 0; i < 5; i++)
  		t->vars[6 + i].extra2 = &port->probe_info[i];
  
  	t->port_dir[0].procname = port->name;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
497
498
499
500
  
  	t->port_dir[0].child = t->vars;
  	t->parport_dir[0].child = t->port_dir;
  	t->dev_dir[0].child = t->parport_dir;
0b4d41471   Eric W. Biederman   [PATCH] sysctl: r...
501
  	t->sysctl_header = register_sysctl_table(t->dev_dir);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
  	if (t->sysctl_header == NULL) {
  		kfree(t);
  		t = NULL;
  	}
  	port->sysctl_table = t;
  	return 0;
  }
  
  int parport_proc_unregister(struct parport *port)
  {
  	if (port->sysctl_table) {
  		struct parport_sysctl_table *t = port->sysctl_table;
  		port->sysctl_table = NULL;
  		unregister_sysctl_table(t->sysctl_header);
  		kfree(t);
  	}
  	return 0;
  }
  
  int parport_device_proc_register(struct pardevice *device)
  {
  	struct parport_device_sysctl_table *t;
  	struct parport * port = device->port;
  	
2451a8483   Silviu-Mihai Popescu   parport: use kmem...
526
  	t = kmemdup(&parport_device_sysctl_template, sizeof(*t), GFP_KERNEL);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
527
528
  	if (t == NULL)
  		return -ENOMEM;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
529
530
531
532
  
  	t->dev_dir[0].child = t->parport_dir;
  	t->parport_dir[0].child = t->port_dir;
  	t->port_dir[0].procname = port->name;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
533
534
  	t->port_dir[0].child = t->devices_root_dir;
  	t->devices_root_dir[0].child = t->device_dir;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
535
  	t->device_dir[0].procname = device->name;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
536
537
  	t->device_dir[0].child = t->vars;
  	t->vars[0].data = &device->timeslice;
0b4d41471   Eric W. Biederman   [PATCH] sysctl: r...
538
  	t->sysctl_header = register_sysctl_table(t->dev_dir);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
  	if (t->sysctl_header == NULL) {
  		kfree(t);
  		t = NULL;
  	}
  	device->sysctl_table = t;
  	return 0;
  }
  
  int parport_device_proc_unregister(struct pardevice *device)
  {
  	if (device->sysctl_table) {
  		struct parport_device_sysctl_table *t = device->sysctl_table;
  		device->sysctl_table = NULL;
  		unregister_sysctl_table(t->sysctl_header);
  		kfree(t);
  	}
  	return 0;
  }
  
  static int __init parport_default_proc_register(void)
  {
  	parport_default_sysctl_table.sysctl_header =
0b4d41471   Eric W. Biederman   [PATCH] sysctl: r...
561
  		register_sysctl_table(parport_default_sysctl_table.dev_dir);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
  	return 0;
  }
  
  static void __exit parport_default_proc_unregister(void)
  {
  	if (parport_default_sysctl_table.sysctl_header) {
  		unregister_sysctl_table(parport_default_sysctl_table.
  					sysctl_header);
  		parport_default_sysctl_table.sysctl_header = NULL;
  	}
  }
  
  #else /* no sysctl or no procfs*/
  
  int parport_proc_register(struct parport *pp)
  {
  	return 0;
  }
  
  int parport_proc_unregister(struct parport *pp)
  {
  	return 0;
  }
  
  int parport_device_proc_register(struct pardevice *device)
  {
  	return 0;
  }
  
  int parport_device_proc_unregister(struct pardevice *device)
  {
  	return 0;
  }
  
  static int __init parport_default_proc_register (void)
  {
  	return 0;
  }
  
  static void __exit parport_default_proc_unregister (void)
  {
  }
  #endif
  
  module_init(parport_default_proc_register)
  module_exit(parport_default_proc_unregister)