public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] usbmon binary format reader loses synchronization
@ 2008-11-13 12:59 Ingo van Lil
  2008-11-13 21:46 ` Pete Zaitcev
  2008-11-14  5:15 ` Pete Zaitcev
  0 siblings, 2 replies; 4+ messages in thread
From: Ingo van Lil @ 2008-11-13 12:59 UTC (permalink / raw)
  To: Pete Zaitcev; +Cc: linux-kernel

Hello Pete,

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.

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.

Cheers,
Ingo

Signed-off-by: Ingo van Lil <inguin@gmx.de>
---
diff -urN a/drivers/usb/mon/mon_bin.c b/drivers/usb/mon/mon_bin.c
--- a/drivers/usb/mon/mon_bin.c	2008-07-13 23:51:29.000000000 +0200
+++ b/drivers/usb/mon/mon_bin.c	2008-11-13 11:44:03.000000000 +0100
@@ -681,7 +681,7 @@
 	}
 
 	if (rp->b_read >= sizeof(struct mon_bin_hdr)) {
-		step_len = min(nbytes, (size_t)ep->len_cap);
+		step_len = min(nbytes, sizeof(struct mon_bin_hdr) + (size_t)ep->len_cap - rp->b_read);
 		offset = rp->b_out + PKT_SIZE;
 		offset += rp->b_read - sizeof(struct mon_bin_hdr);
 		if (offset >= rp->b_size)

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] usbmon binary format reader loses synchronization
  2008-11-13 12:59 [PATCH] usbmon binary format reader loses synchronization Ingo van Lil
@ 2008-11-13 21:46 ` Pete Zaitcev
  2008-11-14  5:15 ` Pete Zaitcev
  1 sibling, 0 replies; 4+ messages in thread
From: Pete Zaitcev @ 2008-11-13 21:46 UTC (permalink / raw)
  To: Ingo van Lil; +Cc: linux-kernel, zaitcev

On Thu, 13 Nov 2008 13:59:45 +0100, Ingo van Lil <inguin@gmx.de> wrote:

> +++ b/drivers/usb/mon/mon_bin.c	2008-11-13 11:44:03.000000000 +0100
> @@ -681,7 +681,7 @@
>  	}
>  
>  	if (rp->b_read >= sizeof(struct mon_bin_hdr)) {
> -		step_len = min(nbytes, (size_t)ep->len_cap);
> +		step_len = min(nbytes, sizeof(struct mon_bin_hdr) + (size_t)ep->len_cap - rp->b_read);
>  		offset = rp->b_out + PKT_SIZE;

I cannot tell right away if this is the best fix, but I'll look
into this. Thanks a lot!

-- Pete

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] usbmon binary format reader loses synchronization
  2008-11-13 12:59 [PATCH] usbmon binary format reader loses synchronization Ingo van Lil
  2008-11-13 21:46 ` Pete Zaitcev
@ 2008-11-14  5:15 ` Pete Zaitcev
  2008-11-14  9:44   ` Ingo van Lil
  1 sibling, 1 reply; 4+ messages in thread
From: Pete Zaitcev @ 2008-11-14  5:15 UTC (permalink / raw)
  To: Ingo van Lil; +Cc: linux-kernel, linux-usb

On Thu, 13 Nov 2008 13:59:45 +0100, Ingo van Lil <inguin@gmx.de> wrote:

> 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.

I think you nailed the problem. I only want shorter lines.
How about this:

diff --git a/drivers/usb/mon/mon_bin.c b/drivers/usb/mon/mon_bin.c
index c9de3f0..e06810a 100644
--- a/drivers/usb/mon/mon_bin.c
+++ b/drivers/usb/mon/mon_bin.c
@@ -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)

Also, please send me signed-off-by if you want it.

-- Pete

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] usbmon binary format reader loses synchronization
  2008-11-14  5:15 ` Pete Zaitcev
@ 2008-11-14  9:44   ` Ingo van Lil
  0 siblings, 0 replies; 4+ messages in thread
From: Ingo van Lil @ 2008-11-14  9:44 UTC (permalink / raw)
  To: Pete Zaitcev; +Cc: linux-kernel, linux-usb

Pete Zaitcev wrote:

>> 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.
> 
> I think you nailed the problem. I only want shorter lines.
> How about this:

Looks good to me, and works just fine.

Signed-off-by: Ingo van Lil <inguin@gmx.de>

Regards,
Ingo

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2008-11-14  9:45 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-11-13 12:59 [PATCH] usbmon binary format reader loses synchronization Ingo van Lil
2008-11-13 21:46 ` Pete Zaitcev
2008-11-14  5:15 ` Pete Zaitcev
2008-11-14  9:44   ` Ingo van Lil

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox