]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/commitdiff
USB: usbmon: fix read(2)
authorPete Zaitcev <zaitcev@redhat.com>
Fri, 14 Nov 2008 16:47:41 +0000 (09:47 -0700)
committerGreg Kroah-Hartman <gregkh@kvm.kroah.org>
Thu, 20 Nov 2008 06:01:35 +0000 (22:01 -0800)
There's a bug in the usbmon binary reader: When using read() to fetch
the packets and a packet's data is partially read, the next read call
will once again return up to len_cap bytes of data. The b_read counter
is not regarded when determining the remaining chunk size.

So, when dumping USB data with "cat /dev/usbmon0 > usbmon.trace" while
reading from a USB storage device and analyzing the dump file
afterwards it will get out of sync after a couple of packets.

Signed-off-by: Ingo van Lil <inguin@gmx.de>
Signed-off-by: Pete Zaitcev <zaitcev@redhat.com>
Cc: stable <stable@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
drivers/usb/mon/mon_bin.c

index c9de3f027aab07a9907b331f25c7723ac012d8e3..e06810aef2dfedbec54f8b232b4219d79fba5536 100644 (file)
@@ -687,7 +687,10 @@ static ssize_t mon_bin_read(struct file *file, char __user *buf,
        }
 
        if (rp->b_read >= sizeof(struct mon_bin_hdr)) {
-               step_len = min(nbytes, (size_t)ep->len_cap);
+               step_len = ep->len_cap;
+               step_len -= rp->b_read - sizeof(struct mon_bin_hdr);
+               if (step_len > nbytes)
+                       step_len = nbytes;
                offset = rp->b_out + PKT_SIZE;
                offset += rp->b_read - sizeof(struct mon_bin_hdr);
                if (offset >= rp->b_size)