Linux Audio

Check our new training course

Linux BSP upgrade and security maintenance

Need help to get security updates for your Linux BSP?
Loading...
v3.1
 1/*
 2 * The USB Monitor, inspired by Dave Harding's USBMon.
 3 *
 4 * This is the 's' or 'stat' reader which debugs usbmon itself.
 5 * Note that this code blows through locks, so make sure that
 6 * /dbg/usbmon/0s is well protected from non-root users.
 7 *
 8 */
 9
10#include <linux/kernel.h>
11#include <linux/slab.h>
 
12#include <linux/usb.h>
13#include <linux/fs.h>
14#include <asm/uaccess.h>
15
16#include "usb_mon.h"
17
18#define STAT_BUF_SIZE  80
19
20struct snap {
21	int slen;
22	char str[STAT_BUF_SIZE];
23};
24
25static int mon_stat_open(struct inode *inode, struct file *file)
26{
27	struct mon_bus *mbus;
28	struct snap *sp;
29
30	if ((sp = kmalloc(sizeof(struct snap), GFP_KERNEL)) == NULL)
31		return -ENOMEM;
32
33	mbus = inode->i_private;
34
35	sp->slen = snprintf(sp->str, STAT_BUF_SIZE,
36	    "nreaders %d events %u text_lost %u\n",
37	    mbus->nreaders, mbus->cnt_events, mbus->cnt_text_lost);
38
39	file->private_data = sp;
40	return 0;
41}
42
43static ssize_t mon_stat_read(struct file *file, char __user *buf,
44				size_t nbytes, loff_t *ppos)
45{
46	struct snap *sp = file->private_data;
47
48	return simple_read_from_buffer(buf, nbytes, ppos, sp->str, sp->slen);
49}
50
51static int mon_stat_release(struct inode *inode, struct file *file)
52{
53	struct snap *sp = file->private_data;
54	file->private_data = NULL;
55	kfree(sp);
56	return 0;
57}
58
59const struct file_operations mon_fops_stat = {
60	.owner =	THIS_MODULE,
61	.open =		mon_stat_open,
62	.llseek =	no_llseek,
63	.read =		mon_stat_read,
64	/* .write =	mon_stat_write, */
65	/* .poll =		mon_stat_poll, */
66	/* .unlocked_ioctl =	mon_stat_ioctl, */
67	.release =	mon_stat_release,
68};
v3.5.6
 1/*
 2 * The USB Monitor, inspired by Dave Harding's USBMon.
 3 *
 4 * This is the 's' or 'stat' reader which debugs usbmon itself.
 5 * Note that this code blows through locks, so make sure that
 6 * /dbg/usbmon/0s is well protected from non-root users.
 7 *
 8 */
 9
10#include <linux/kernel.h>
11#include <linux/slab.h>
12#include <linux/export.h>
13#include <linux/usb.h>
14#include <linux/fs.h>
15#include <asm/uaccess.h>
16
17#include "usb_mon.h"
18
19#define STAT_BUF_SIZE  80
20
21struct snap {
22	int slen;
23	char str[STAT_BUF_SIZE];
24};
25
26static int mon_stat_open(struct inode *inode, struct file *file)
27{
28	struct mon_bus *mbus;
29	struct snap *sp;
30
31	if ((sp = kmalloc(sizeof(struct snap), GFP_KERNEL)) == NULL)
32		return -ENOMEM;
33
34	mbus = inode->i_private;
35
36	sp->slen = snprintf(sp->str, STAT_BUF_SIZE,
37	    "nreaders %d events %u text_lost %u\n",
38	    mbus->nreaders, mbus->cnt_events, mbus->cnt_text_lost);
39
40	file->private_data = sp;
41	return 0;
42}
43
44static ssize_t mon_stat_read(struct file *file, char __user *buf,
45				size_t nbytes, loff_t *ppos)
46{
47	struct snap *sp = file->private_data;
48
49	return simple_read_from_buffer(buf, nbytes, ppos, sp->str, sp->slen);
50}
51
52static int mon_stat_release(struct inode *inode, struct file *file)
53{
54	struct snap *sp = file->private_data;
55	file->private_data = NULL;
56	kfree(sp);
57	return 0;
58}
59
60const struct file_operations mon_fops_stat = {
61	.owner =	THIS_MODULE,
62	.open =		mon_stat_open,
63	.llseek =	no_llseek,
64	.read =		mon_stat_read,
65	/* .write =	mon_stat_write, */
66	/* .poll =		mon_stat_poll, */
67	/* .unlocked_ioctl =	mon_stat_ioctl, */
68	.release =	mon_stat_release,
69};