OMAP3 SRF: Generic shared resource f/w
[linux-ginger.git] / drivers / usb / mon / mon_text.c
blob9f1a9227ebe6571454ee3081d4df80ec5490f4c7
1 /*
2 * The USB Monitor, inspired by Dave Harding's USBMon.
4 * This is a text format reader.
5 */
7 #include <linux/kernel.h>
8 #include <linux/list.h>
9 #include <linux/usb.h>
10 #include <linux/time.h>
11 #include <linux/mutex.h>
12 #include <linux/debugfs.h>
13 #include <asm/uaccess.h>
15 #include "usb_mon.h"
18 * No, we do not want arbitrarily long data strings.
19 * Use the binary interface if you want to capture bulk data!
21 #define DATA_MAX 32
24 * Defined by USB 2.0 clause 9.3, table 9.2.
26 #define SETUP_MAX 8
29 * This limit exists to prevent OOMs when the user process stops reading.
30 * If usbmon were available to unprivileged processes, it might be open
31 * to a local DoS. But we have to keep to root in order to prevent
32 * password sniffing from HID devices.
34 #define EVENT_MAX (4*PAGE_SIZE / sizeof(struct mon_event_text))
37 * Potentially unlimited number; we limit it for similar allocations.
38 * The usbfs limits this to 128, but we're not quite as generous.
40 #define ISODESC_MAX 5
42 #define PRINTF_DFL 250 /* with 5 ISOs segs */
44 struct mon_iso_desc {
45 int status;
46 unsigned int offset;
47 unsigned int length; /* Unsigned here, signed in URB. Historic. */
50 struct mon_event_text {
51 struct list_head e_link;
52 int type; /* submit, complete, etc. */
53 unsigned long id; /* From pointer, most of the time */
54 unsigned int tstamp;
55 int busnum;
56 char devnum;
57 char epnum;
58 char is_in;
59 char xfertype;
60 int length; /* Depends on type: xfer length or act length */
61 int status;
62 int interval;
63 int start_frame;
64 int error_count;
65 char setup_flag;
66 char data_flag;
67 int numdesc; /* Full number */
68 struct mon_iso_desc isodesc[ISODESC_MAX];
69 unsigned char setup[SETUP_MAX];
70 unsigned char data[DATA_MAX];
73 #define SLAB_NAME_SZ 30
74 struct mon_reader_text {
75 struct kmem_cache *e_slab;
76 int nevents;
77 struct list_head e_list;
78 struct mon_reader r; /* In C, parent class can be placed anywhere */
80 wait_queue_head_t wait;
81 int printf_size;
82 char *printf_buf;
83 struct mutex printf_lock;
85 char slab_name[SLAB_NAME_SZ];
88 static struct dentry *mon_dir; /* Usually /sys/kernel/debug/usbmon */
90 static void mon_text_ctor(void *);
92 struct mon_text_ptr {
93 int cnt, limit;
94 char *pbuf;
97 static struct mon_event_text *
98 mon_text_read_wait(struct mon_reader_text *rp, struct file *file);
99 static void mon_text_read_head_t(struct mon_reader_text *rp,
100 struct mon_text_ptr *p, const struct mon_event_text *ep);
101 static void mon_text_read_head_u(struct mon_reader_text *rp,
102 struct mon_text_ptr *p, const struct mon_event_text *ep);
103 static void mon_text_read_statset(struct mon_reader_text *rp,
104 struct mon_text_ptr *p, const struct mon_event_text *ep);
105 static void mon_text_read_intstat(struct mon_reader_text *rp,
106 struct mon_text_ptr *p, const struct mon_event_text *ep);
107 static void mon_text_read_isostat(struct mon_reader_text *rp,
108 struct mon_text_ptr *p, const struct mon_event_text *ep);
109 static void mon_text_read_isodesc(struct mon_reader_text *rp,
110 struct mon_text_ptr *p, const struct mon_event_text *ep);
111 static void mon_text_read_data(struct mon_reader_text *rp,
112 struct mon_text_ptr *p, const struct mon_event_text *ep);
115 * mon_text_submit
116 * mon_text_complete
118 * May be called from an interrupt.
120 * This is called with the whole mon_bus locked, so no additional lock.
123 static inline char mon_text_get_setup(struct mon_event_text *ep,
124 struct urb *urb, char ev_type, struct mon_bus *mbus)
127 if (ep->xfertype != USB_ENDPOINT_XFER_CONTROL || ev_type != 'S')
128 return '-';
130 if (urb->setup_packet == NULL)
131 return 'Z'; /* '0' would be not as pretty. */
133 memcpy(ep->setup, urb->setup_packet, SETUP_MAX);
134 return 0;
137 static inline char mon_text_get_data(struct mon_event_text *ep, struct urb *urb,
138 int len, char ev_type, struct mon_bus *mbus)
140 if (len <= 0)
141 return 'L';
142 if (len >= DATA_MAX)
143 len = DATA_MAX;
145 if (ep->is_in) {
146 if (ev_type != 'C')
147 return '<';
148 } else {
149 if (ev_type != 'S')
150 return '>';
153 if (urb->transfer_buffer == NULL)
154 return 'Z'; /* '0' would be not as pretty. */
156 memcpy(ep->data, urb->transfer_buffer, len);
157 return 0;
160 static inline unsigned int mon_get_timestamp(void)
162 struct timeval tval;
163 unsigned int stamp;
165 do_gettimeofday(&tval);
166 stamp = tval.tv_sec & 0xFFFF; /* 2^32 = 4294967296. Limit to 4096s. */
167 stamp = stamp * 1000000 + tval.tv_usec;
168 return stamp;
171 static void mon_text_event(struct mon_reader_text *rp, struct urb *urb,
172 char ev_type, int status)
174 struct mon_event_text *ep;
175 unsigned int stamp;
176 struct usb_iso_packet_descriptor *fp;
177 struct mon_iso_desc *dp;
178 int i, ndesc;
180 stamp = mon_get_timestamp();
182 if (rp->nevents >= EVENT_MAX ||
183 (ep = kmem_cache_alloc(rp->e_slab, GFP_ATOMIC)) == NULL) {
184 rp->r.m_bus->cnt_text_lost++;
185 return;
188 ep->type = ev_type;
189 ep->id = (unsigned long) urb;
190 ep->busnum = urb->dev->bus->busnum;
191 ep->devnum = urb->dev->devnum;
192 ep->epnum = usb_endpoint_num(&urb->ep->desc);
193 ep->xfertype = usb_endpoint_type(&urb->ep->desc);
194 ep->is_in = usb_urb_dir_in(urb);
195 ep->tstamp = stamp;
196 ep->length = (ev_type == 'S') ?
197 urb->transfer_buffer_length : urb->actual_length;
198 /* Collecting status makes debugging sense for submits, too */
199 ep->status = status;
201 if (ep->xfertype == USB_ENDPOINT_XFER_INT) {
202 ep->interval = urb->interval;
203 } else if (ep->xfertype == USB_ENDPOINT_XFER_ISOC) {
204 ep->interval = urb->interval;
205 ep->start_frame = urb->start_frame;
206 ep->error_count = urb->error_count;
208 ep->numdesc = urb->number_of_packets;
209 if (ep->xfertype == USB_ENDPOINT_XFER_ISOC &&
210 urb->number_of_packets > 0) {
211 if ((ndesc = urb->number_of_packets) > ISODESC_MAX)
212 ndesc = ISODESC_MAX;
213 fp = urb->iso_frame_desc;
214 dp = ep->isodesc;
215 for (i = 0; i < ndesc; i++) {
216 dp->status = fp->status;
217 dp->offset = fp->offset;
218 dp->length = (ev_type == 'S') ?
219 fp->length : fp->actual_length;
220 fp++;
221 dp++;
225 ep->setup_flag = mon_text_get_setup(ep, urb, ev_type, rp->r.m_bus);
226 ep->data_flag = mon_text_get_data(ep, urb, ep->length, ev_type,
227 rp->r.m_bus);
229 rp->nevents++;
230 list_add_tail(&ep->e_link, &rp->e_list);
231 wake_up(&rp->wait);
234 static void mon_text_submit(void *data, struct urb *urb)
236 struct mon_reader_text *rp = data;
237 mon_text_event(rp, urb, 'S', -EINPROGRESS);
240 static void mon_text_complete(void *data, struct urb *urb, int status)
242 struct mon_reader_text *rp = data;
243 mon_text_event(rp, urb, 'C', status);
246 static void mon_text_error(void *data, struct urb *urb, int error)
248 struct mon_reader_text *rp = data;
249 struct mon_event_text *ep;
251 if (rp->nevents >= EVENT_MAX ||
252 (ep = kmem_cache_alloc(rp->e_slab, GFP_ATOMIC)) == NULL) {
253 rp->r.m_bus->cnt_text_lost++;
254 return;
257 ep->type = 'E';
258 ep->id = (unsigned long) urb;
259 ep->busnum = 0;
260 ep->devnum = urb->dev->devnum;
261 ep->epnum = usb_endpoint_num(&urb->ep->desc);
262 ep->xfertype = usb_endpoint_type(&urb->ep->desc);
263 ep->is_in = usb_urb_dir_in(urb);
264 ep->tstamp = 0;
265 ep->length = 0;
266 ep->status = error;
268 ep->setup_flag = '-';
269 ep->data_flag = 'E';
271 rp->nevents++;
272 list_add_tail(&ep->e_link, &rp->e_list);
273 wake_up(&rp->wait);
277 * Fetch next event from the circular buffer.
279 static struct mon_event_text *mon_text_fetch(struct mon_reader_text *rp,
280 struct mon_bus *mbus)
282 struct list_head *p;
283 unsigned long flags;
285 spin_lock_irqsave(&mbus->lock, flags);
286 if (list_empty(&rp->e_list)) {
287 spin_unlock_irqrestore(&mbus->lock, flags);
288 return NULL;
290 p = rp->e_list.next;
291 list_del(p);
292 --rp->nevents;
293 spin_unlock_irqrestore(&mbus->lock, flags);
294 return list_entry(p, struct mon_event_text, e_link);
299 static int mon_text_open(struct inode *inode, struct file *file)
301 struct mon_bus *mbus;
302 struct mon_reader_text *rp;
303 int rc;
305 mutex_lock(&mon_lock);
306 mbus = inode->i_private;
308 rp = kzalloc(sizeof(struct mon_reader_text), GFP_KERNEL);
309 if (rp == NULL) {
310 rc = -ENOMEM;
311 goto err_alloc;
313 INIT_LIST_HEAD(&rp->e_list);
314 init_waitqueue_head(&rp->wait);
315 mutex_init(&rp->printf_lock);
317 rp->printf_size = PRINTF_DFL;
318 rp->printf_buf = kmalloc(rp->printf_size, GFP_KERNEL);
319 if (rp->printf_buf == NULL) {
320 rc = -ENOMEM;
321 goto err_alloc_pr;
324 rp->r.m_bus = mbus;
325 rp->r.r_data = rp;
326 rp->r.rnf_submit = mon_text_submit;
327 rp->r.rnf_error = mon_text_error;
328 rp->r.rnf_complete = mon_text_complete;
330 snprintf(rp->slab_name, SLAB_NAME_SZ, "mon_text_%p", rp);
331 rp->e_slab = kmem_cache_create(rp->slab_name,
332 sizeof(struct mon_event_text), sizeof(long), 0,
333 mon_text_ctor);
334 if (rp->e_slab == NULL) {
335 rc = -ENOMEM;
336 goto err_slab;
339 mon_reader_add(mbus, &rp->r);
341 file->private_data = rp;
342 mutex_unlock(&mon_lock);
343 return 0;
345 // err_busy:
346 // kmem_cache_destroy(rp->e_slab);
347 err_slab:
348 kfree(rp->printf_buf);
349 err_alloc_pr:
350 kfree(rp);
351 err_alloc:
352 mutex_unlock(&mon_lock);
353 return rc;
357 * For simplicity, we read one record in one system call and throw out
358 * what does not fit. This means that the following does not work:
359 * dd if=/dbg/usbmon/0t bs=10
360 * Also, we do not allow seeks and do not bother advancing the offset.
362 static ssize_t mon_text_read_t(struct file *file, char __user *buf,
363 size_t nbytes, loff_t *ppos)
365 struct mon_reader_text *rp = file->private_data;
366 struct mon_event_text *ep;
367 struct mon_text_ptr ptr;
369 if (IS_ERR(ep = mon_text_read_wait(rp, file)))
370 return PTR_ERR(ep);
371 mutex_lock(&rp->printf_lock);
372 ptr.cnt = 0;
373 ptr.pbuf = rp->printf_buf;
374 ptr.limit = rp->printf_size;
376 mon_text_read_head_t(rp, &ptr, ep);
377 mon_text_read_statset(rp, &ptr, ep);
378 ptr.cnt += snprintf(ptr.pbuf + ptr.cnt, ptr.limit - ptr.cnt,
379 " %d", ep->length);
380 mon_text_read_data(rp, &ptr, ep);
382 if (copy_to_user(buf, rp->printf_buf, ptr.cnt))
383 ptr.cnt = -EFAULT;
384 mutex_unlock(&rp->printf_lock);
385 kmem_cache_free(rp->e_slab, ep);
386 return ptr.cnt;
389 static ssize_t mon_text_read_u(struct file *file, char __user *buf,
390 size_t nbytes, loff_t *ppos)
392 struct mon_reader_text *rp = file->private_data;
393 struct mon_event_text *ep;
394 struct mon_text_ptr ptr;
396 if (IS_ERR(ep = mon_text_read_wait(rp, file)))
397 return PTR_ERR(ep);
398 mutex_lock(&rp->printf_lock);
399 ptr.cnt = 0;
400 ptr.pbuf = rp->printf_buf;
401 ptr.limit = rp->printf_size;
403 mon_text_read_head_u(rp, &ptr, ep);
404 if (ep->type == 'E') {
405 mon_text_read_statset(rp, &ptr, ep);
406 } else if (ep->xfertype == USB_ENDPOINT_XFER_ISOC) {
407 mon_text_read_isostat(rp, &ptr, ep);
408 mon_text_read_isodesc(rp, &ptr, ep);
409 } else if (ep->xfertype == USB_ENDPOINT_XFER_INT) {
410 mon_text_read_intstat(rp, &ptr, ep);
411 } else {
412 mon_text_read_statset(rp, &ptr, ep);
414 ptr.cnt += snprintf(ptr.pbuf + ptr.cnt, ptr.limit - ptr.cnt,
415 " %d", ep->length);
416 mon_text_read_data(rp, &ptr, ep);
418 if (copy_to_user(buf, rp->printf_buf, ptr.cnt))
419 ptr.cnt = -EFAULT;
420 mutex_unlock(&rp->printf_lock);
421 kmem_cache_free(rp->e_slab, ep);
422 return ptr.cnt;
425 static struct mon_event_text *mon_text_read_wait(struct mon_reader_text *rp,
426 struct file *file)
428 struct mon_bus *mbus = rp->r.m_bus;
429 DECLARE_WAITQUEUE(waita, current);
430 struct mon_event_text *ep;
432 add_wait_queue(&rp->wait, &waita);
433 set_current_state(TASK_INTERRUPTIBLE);
434 while ((ep = mon_text_fetch(rp, mbus)) == NULL) {
435 if (file->f_flags & O_NONBLOCK) {
436 set_current_state(TASK_RUNNING);
437 remove_wait_queue(&rp->wait, &waita);
438 return ERR_PTR(-EWOULDBLOCK);
441 * We do not count nwaiters, because ->release is supposed
442 * to be called when all openers are gone only.
444 schedule();
445 if (signal_pending(current)) {
446 remove_wait_queue(&rp->wait, &waita);
447 return ERR_PTR(-EINTR);
449 set_current_state(TASK_INTERRUPTIBLE);
451 set_current_state(TASK_RUNNING);
452 remove_wait_queue(&rp->wait, &waita);
453 return ep;
456 static void mon_text_read_head_t(struct mon_reader_text *rp,
457 struct mon_text_ptr *p, const struct mon_event_text *ep)
459 char udir, utype;
461 udir = (ep->is_in ? 'i' : 'o');
462 switch (ep->xfertype) {
463 case USB_ENDPOINT_XFER_ISOC: utype = 'Z'; break;
464 case USB_ENDPOINT_XFER_INT: utype = 'I'; break;
465 case USB_ENDPOINT_XFER_CONTROL: utype = 'C'; break;
466 default: /* PIPE_BULK */ utype = 'B';
468 p->cnt += snprintf(p->pbuf + p->cnt, p->limit - p->cnt,
469 "%lx %u %c %c%c:%03u:%02u",
470 ep->id, ep->tstamp, ep->type,
471 utype, udir, ep->devnum, ep->epnum);
474 static void mon_text_read_head_u(struct mon_reader_text *rp,
475 struct mon_text_ptr *p, const struct mon_event_text *ep)
477 char udir, utype;
479 udir = (ep->is_in ? 'i' : 'o');
480 switch (ep->xfertype) {
481 case USB_ENDPOINT_XFER_ISOC: utype = 'Z'; break;
482 case USB_ENDPOINT_XFER_INT: utype = 'I'; break;
483 case USB_ENDPOINT_XFER_CONTROL: utype = 'C'; break;
484 default: /* PIPE_BULK */ utype = 'B';
486 p->cnt += snprintf(p->pbuf + p->cnt, p->limit - p->cnt,
487 "%lx %u %c %c%c:%d:%03u:%u",
488 ep->id, ep->tstamp, ep->type,
489 utype, udir, ep->busnum, ep->devnum, ep->epnum);
492 static void mon_text_read_statset(struct mon_reader_text *rp,
493 struct mon_text_ptr *p, const struct mon_event_text *ep)
496 if (ep->setup_flag == 0) { /* Setup packet is present and captured */
497 p->cnt += snprintf(p->pbuf + p->cnt, p->limit - p->cnt,
498 " s %02x %02x %04x %04x %04x",
499 ep->setup[0],
500 ep->setup[1],
501 (ep->setup[3] << 8) | ep->setup[2],
502 (ep->setup[5] << 8) | ep->setup[4],
503 (ep->setup[7] << 8) | ep->setup[6]);
504 } else if (ep->setup_flag != '-') { /* Unable to capture setup packet */
505 p->cnt += snprintf(p->pbuf + p->cnt, p->limit - p->cnt,
506 " %c __ __ ____ ____ ____", ep->setup_flag);
507 } else { /* No setup for this kind of URB */
508 p->cnt += snprintf(p->pbuf + p->cnt, p->limit - p->cnt,
509 " %d", ep->status);
513 static void mon_text_read_intstat(struct mon_reader_text *rp,
514 struct mon_text_ptr *p, const struct mon_event_text *ep)
516 p->cnt += snprintf(p->pbuf + p->cnt, p->limit - p->cnt,
517 " %d:%d", ep->status, ep->interval);
520 static void mon_text_read_isostat(struct mon_reader_text *rp,
521 struct mon_text_ptr *p, const struct mon_event_text *ep)
523 if (ep->type == 'S') {
524 p->cnt += snprintf(p->pbuf + p->cnt, p->limit - p->cnt,
525 " %d:%d:%d", ep->status, ep->interval, ep->start_frame);
526 } else {
527 p->cnt += snprintf(p->pbuf + p->cnt, p->limit - p->cnt,
528 " %d:%d:%d:%d",
529 ep->status, ep->interval, ep->start_frame, ep->error_count);
533 static void mon_text_read_isodesc(struct mon_reader_text *rp,
534 struct mon_text_ptr *p, const struct mon_event_text *ep)
536 int ndesc; /* Display this many */
537 int i;
538 const struct mon_iso_desc *dp;
540 p->cnt += snprintf(p->pbuf + p->cnt, p->limit - p->cnt,
541 " %d", ep->numdesc);
542 ndesc = ep->numdesc;
543 if (ndesc > ISODESC_MAX)
544 ndesc = ISODESC_MAX;
545 if (ndesc < 0)
546 ndesc = 0;
547 dp = ep->isodesc;
548 for (i = 0; i < ndesc; i++) {
549 p->cnt += snprintf(p->pbuf + p->cnt, p->limit - p->cnt,
550 " %d:%u:%u", dp->status, dp->offset, dp->length);
551 dp++;
555 static void mon_text_read_data(struct mon_reader_text *rp,
556 struct mon_text_ptr *p, const struct mon_event_text *ep)
558 int data_len, i;
560 if ((data_len = ep->length) > 0) {
561 if (ep->data_flag == 0) {
562 p->cnt += snprintf(p->pbuf + p->cnt, p->limit - p->cnt,
563 " =");
564 if (data_len >= DATA_MAX)
565 data_len = DATA_MAX;
566 for (i = 0; i < data_len; i++) {
567 if (i % 4 == 0) {
568 p->cnt += snprintf(p->pbuf + p->cnt,
569 p->limit - p->cnt,
570 " ");
572 p->cnt += snprintf(p->pbuf + p->cnt,
573 p->limit - p->cnt,
574 "%02x", ep->data[i]);
576 p->cnt += snprintf(p->pbuf + p->cnt, p->limit - p->cnt,
577 "\n");
578 } else {
579 p->cnt += snprintf(p->pbuf + p->cnt, p->limit - p->cnt,
580 " %c\n", ep->data_flag);
582 } else {
583 p->cnt += snprintf(p->pbuf + p->cnt, p->limit - p->cnt, "\n");
587 static int mon_text_release(struct inode *inode, struct file *file)
589 struct mon_reader_text *rp = file->private_data;
590 struct mon_bus *mbus;
591 /* unsigned long flags; */
592 struct list_head *p;
593 struct mon_event_text *ep;
595 mutex_lock(&mon_lock);
596 mbus = inode->i_private;
598 if (mbus->nreaders <= 0) {
599 printk(KERN_ERR TAG ": consistency error on close\n");
600 mutex_unlock(&mon_lock);
601 return 0;
603 mon_reader_del(mbus, &rp->r);
606 * In theory, e_list is protected by mbus->lock. However,
607 * after mon_reader_del has finished, the following is the case:
608 * - we are not on reader list anymore, so new events won't be added;
609 * - whole mbus may be dropped if it was orphaned.
610 * So, we better not touch mbus.
612 /* spin_lock_irqsave(&mbus->lock, flags); */
613 while (!list_empty(&rp->e_list)) {
614 p = rp->e_list.next;
615 ep = list_entry(p, struct mon_event_text, e_link);
616 list_del(p);
617 --rp->nevents;
618 kmem_cache_free(rp->e_slab, ep);
620 /* spin_unlock_irqrestore(&mbus->lock, flags); */
622 kmem_cache_destroy(rp->e_slab);
623 kfree(rp->printf_buf);
624 kfree(rp);
626 mutex_unlock(&mon_lock);
627 return 0;
630 static const struct file_operations mon_fops_text_t = {
631 .owner = THIS_MODULE,
632 .open = mon_text_open,
633 .llseek = no_llseek,
634 .read = mon_text_read_t,
635 .release = mon_text_release,
638 static const struct file_operations mon_fops_text_u = {
639 .owner = THIS_MODULE,
640 .open = mon_text_open,
641 .llseek = no_llseek,
642 .read = mon_text_read_u,
643 .release = mon_text_release,
646 int mon_text_add(struct mon_bus *mbus, const struct usb_bus *ubus)
648 struct dentry *d;
649 enum { NAMESZ = 10 };
650 char name[NAMESZ];
651 int busnum = ubus? ubus->busnum: 0;
652 int rc;
654 if (ubus != NULL) {
655 rc = snprintf(name, NAMESZ, "%dt", busnum);
656 if (rc <= 0 || rc >= NAMESZ)
657 goto err_print_t;
658 d = debugfs_create_file(name, 0600, mon_dir, mbus,
659 &mon_fops_text_t);
660 if (d == NULL)
661 goto err_create_t;
662 mbus->dent_t = d;
665 rc = snprintf(name, NAMESZ, "%du", busnum);
666 if (rc <= 0 || rc >= NAMESZ)
667 goto err_print_u;
668 d = debugfs_create_file(name, 0600, mon_dir, mbus, &mon_fops_text_u);
669 if (d == NULL)
670 goto err_create_u;
671 mbus->dent_u = d;
673 rc = snprintf(name, NAMESZ, "%ds", busnum);
674 if (rc <= 0 || rc >= NAMESZ)
675 goto err_print_s;
676 d = debugfs_create_file(name, 0600, mon_dir, mbus, &mon_fops_stat);
677 if (d == NULL)
678 goto err_create_s;
679 mbus->dent_s = d;
681 return 1;
683 err_create_s:
684 err_print_s:
685 debugfs_remove(mbus->dent_u);
686 mbus->dent_u = NULL;
687 err_create_u:
688 err_print_u:
689 if (ubus != NULL) {
690 debugfs_remove(mbus->dent_t);
691 mbus->dent_t = NULL;
693 err_create_t:
694 err_print_t:
695 return 0;
698 void mon_text_del(struct mon_bus *mbus)
700 debugfs_remove(mbus->dent_u);
701 if (mbus->dent_t != NULL)
702 debugfs_remove(mbus->dent_t);
703 debugfs_remove(mbus->dent_s);
707 * Slab interface: constructor.
709 static void mon_text_ctor(void *mem)
712 * Nothing to initialize. No, really!
713 * So, we fill it with garbage to emulate a reused object.
715 memset(mem, 0xe5, sizeof(struct mon_event_text));
718 int __init mon_text_init(void)
720 struct dentry *mondir;
722 mondir = debugfs_create_dir("usbmon", usb_debug_root);
723 if (IS_ERR(mondir)) {
724 printk(KERN_NOTICE TAG ": debugfs is not available\n");
725 return -ENODEV;
727 if (mondir == NULL) {
728 printk(KERN_NOTICE TAG ": unable to create usbmon directory\n");
729 return -ENODEV;
731 mon_dir = mondir;
732 return 0;
735 void mon_text_exit(void)
737 debugfs_remove(mon_dir);