Implement the "error" event in usbmon.

Signed-off-by: Pete Zaitcev <[EMAIL PROTECTED]>

---

This has to go on top of the patch I sent earlier today.

I hoped I'd come with a clever way to have this combined with the submission
event, but nothing comes to mind which weren't unduly complicated.
So at least let's get rid of XXX.

diff -urp -X dontdiff linux-2.6.17-rc5-usbmon1/drivers/usb/mon/mon_main.c 
linux-2.6.17-rc5-lem/drivers/usb/mon/mon_main.c
--- linux-2.6.17-rc5-usbmon1/drivers/usb/mon/mon_main.c 2006-06-09 
21:24:05.000000000 -0700
+++ linux-2.6.17-rc5-lem/drivers/usb/mon/mon_main.c     2006-06-09 
21:01:33.000000000 -0700
@@ -114,20 +114,32 @@ out_unlocked:
 
 /*
  */
-static void mon_submit_error(struct usb_bus *ubus, struct urb *urb, int err)
+static void mon_submit_error(struct usb_bus *ubus, struct urb *urb, int error)
 {
        struct mon_bus *mbus;
+       unsigned long flags;
+       struct list_head *pos;
+       struct mon_reader *r;
 
        mbus = ubus->mon_bus;
        if (mbus == NULL)
                goto out_unlocked;
 
-       /*
-        * XXX Capture the error code and the 'E' event.
-        */
+       spin_lock_irqsave(&mbus->lock, flags);
+       if (mbus->nreaders == 0)
+               goto out_locked;
+
+       mbus->cnt_events++;
+       list_for_each (pos, &mbus->r_list) {
+               r = list_entry(pos, struct mon_reader, r_link);
+               r->rnf_error(r->r_data, urb, error);
+       }
 
+       spin_unlock_irqrestore(&mbus->lock, flags);
        return;
 
+out_locked:
+       spin_unlock_irqrestore(&mbus->lock, flags);
 out_unlocked:
        return;
 }
diff -urp -X dontdiff linux-2.6.17-rc5-usbmon1/drivers/usb/mon/mon_text.c 
linux-2.6.17-rc5-lem/drivers/usb/mon/mon_text.c
--- linux-2.6.17-rc5-usbmon1/drivers/usb/mon/mon_text.c 2006-06-09 
21:24:05.000000000 -0700
+++ linux-2.6.17-rc5-lem/drivers/usb/mon/mon_text.c     2006-06-09 
21:08:11.000000000 -0700
@@ -182,6 +182,32 @@ static void mon_text_complete(void *data
        mon_text_event(rp, urb, 'C');
 }
 
+static void mon_text_error(void *data, struct urb *urb, int error)
+{
+       struct mon_reader_text *rp = data;
+       struct mon_event_text *ep;
+
+       if (rp->nevents >= EVENT_MAX ||
+           (ep = kmem_cache_alloc(rp->e_slab, SLAB_ATOMIC)) == NULL) {
+               rp->r.m_bus->cnt_text_lost++;
+               return;
+       }
+
+       ep->type = 'E';
+       ep->pipe = urb->pipe;
+       ep->id = (unsigned long) urb;
+       ep->tstamp = 0;
+       ep->length = 0;
+       ep->status = error;
+
+       ep->setup_flag = '-';
+       ep->data_flag = 'E';
+
+       rp->nevents++;
+       list_add_tail(&ep->e_link, &rp->e_list);
+       wake_up(&rp->wait);
+}
+
 /*
  * Fetch next event from the circular buffer.
  */
@@ -235,6 +261,7 @@ static int mon_text_open(struct inode *i
        rp->r.m_bus = mbus;
        rp->r.r_data = rp;
        rp->r.rnf_submit = mon_text_submit;
+       rp->r.rnf_error = mon_text_error;
        rp->r.rnf_complete = mon_text_complete;
 
        snprintf(rp->slab_name, SLAB_NAME_SZ, "mon%dt_%lx", ubus->busnum,
diff -urp -X dontdiff linux-2.6.17-rc5-usbmon1/drivers/usb/mon/usb_mon.h 
linux-2.6.17-rc5-lem/drivers/usb/mon/usb_mon.h
--- linux-2.6.17-rc5-usbmon1/drivers/usb/mon/usb_mon.h  2006-06-09 
21:24:05.000000000 -0700
+++ linux-2.6.17-rc5-lem/drivers/usb/mon/usb_mon.h      2006-06-09 
20:56:48.000000000 -0700
@@ -40,6 +40,7 @@ struct mon_reader {
        void *r_data;           /* Use container_of instead? */
 
        void (*rnf_submit)(void *data, struct urb *urb);
+       void (*rnf_error)(void *data, struct urb *urb, int error);
        void (*rnf_complete)(void *data, struct urb *urb);
 };
 


_______________________________________________
linux-usb-devel@lists.sourceforge.net
To unsubscribe, use the last form field at:
https://lists.sourceforge.net/lists/listinfo/linux-usb-devel

Reply via email to