Merge tag 'for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/mst/vhost
[cris-mirror.git] / drivers / staging / comedi / proc.c
blob50d38938ac6f2e112ed53065259e8ed021270b51
1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3 * /proc interface for comedi
5 * COMEDI - Linux Control and Measurement Device Interface
6 * Copyright (C) 1998 David A. Schleef <ds@schleef.org>
7 */
9 /*
10 * This is some serious bloatware.
12 * Taken from Dave A.'s PCL-711 driver, 'cuz I thought it
13 * was cool.
16 #include "comedidev.h"
17 #include "comedi_internal.h"
18 #include <linux/proc_fs.h>
19 #include <linux/seq_file.h>
21 static int comedi_read(struct seq_file *m, void *v)
23 int i;
24 int devices_q = 0;
25 struct comedi_driver *driv;
27 seq_printf(m, "comedi version " COMEDI_RELEASE "\nformat string: %s\n",
28 "\"%2d: %-20s %-20s %4d\", i, driver_name, board_name, n_subdevices");
30 for (i = 0; i < COMEDI_NUM_BOARD_MINORS; i++) {
31 struct comedi_device *dev = comedi_dev_get_from_minor(i);
33 if (!dev)
34 continue;
36 down_read(&dev->attach_lock);
37 if (dev->attached) {
38 devices_q = 1;
39 seq_printf(m, "%2d: %-20s %-20s %4d\n",
40 i, dev->driver->driver_name,
41 dev->board_name, dev->n_subdevices);
43 up_read(&dev->attach_lock);
44 comedi_dev_put(dev);
46 if (!devices_q)
47 seq_puts(m, "no devices\n");
49 mutex_lock(&comedi_drivers_list_lock);
50 for (driv = comedi_drivers; driv; driv = driv->next) {
51 seq_printf(m, "%s:\n", driv->driver_name);
52 for (i = 0; i < driv->num_names; i++)
53 seq_printf(m, " %s\n",
54 *(char **)((char *)driv->board_name +
55 i * driv->offset));
57 if (!driv->num_names)
58 seq_printf(m, " %s\n", driv->driver_name);
60 mutex_unlock(&comedi_drivers_list_lock);
62 return 0;
66 * seq_file wrappers for procfile show routines.
68 static int comedi_proc_open(struct inode *inode, struct file *file)
70 return single_open(file, comedi_read, NULL);
73 static const struct file_operations comedi_proc_fops = {
74 .owner = THIS_MODULE,
75 .open = comedi_proc_open,
76 .read = seq_read,
77 .llseek = seq_lseek,
78 .release = single_release,
81 void __init comedi_proc_init(void)
83 if (!proc_create("comedi", 0444, NULL, &comedi_proc_fops))
84 pr_warn("comedi: unable to create proc entry\n");
87 void comedi_proc_cleanup(void)
89 remove_proc_entry("comedi", NULL);