public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: "Németh Márton" <nm127@freemail.hu>
To: Pete Zaitcev <zaitcev@redhat.com>
Cc: Greg Kroah-Hartman <gregkh@suse.de>,
	linux-usb@vger.kernel.org, LKML <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH, RFC] usbmon: correct computing of the ISO packets with mmap
Date: Tue, 16 Nov 2010 07:00:55 +0100	[thread overview]
Message-ID: <4CE21E17.70107@freemail.hu> (raw)
In-Reply-To: <4CE0C9B8.1010403@freemail.hu>

Németh Márton wrote:
> Hi Pete,
> Pete Zaitcev wrote:
>> On Sun, 14 Nov 2010 21:24:46 +0100
>> Németh Márton <nm127@freemail.hu> wrote:
>>
>>> Sure, I'm happy as long as I can capture the whole data content of the ISO
>>> packets.
>> Great. So, what do you think about the attached? It differs from your
>> code in one important aspect: output buffer sizes are not adjusted.
>> Your patch attempts that, but uses actual_length, which is not
>> defined during submission events. So I skipped that.
> 
> I think there are four cases for ISO communication URBs:
> 
> ev_type == 'S' && usb_urb_dir_in(urb)  ---> we don't need the data
> ev_type == 'C' && usb_urb_dir_in(urb)  ---> data is available, we'll need it
> ev_type == 'S' && usb_urb_dir_out(urb)  ---> data is available, we'll need it
> ev_type == 'C' && usb_urb_dir_out(urb)  ---> we don't need the data
> 
> I cannot say for sure which field contains the length in case of ISO out submit
> URBs.
> 
> I'll test the patch later in my environment.

I tested this patch with ISO in traffic and it works for me.

>> diff --git a/drivers/usb/mon/mon_bin.c b/drivers/usb/mon/mon_bin.c
>> index 44cb37b..15c5e46 100644
>> --- a/drivers/usb/mon/mon_bin.c
>> +++ b/drivers/usb/mon/mon_bin.c
>> @@ -437,6 +437,28 @@ static unsigned int mon_bin_get_data(const struct mon_reader_bin *rp,
>>  	return length;
>>  }
>>  
>> +/*
>> + * This is the look-ahead pass in case of 'Ci', when actual_length cannot
>> + * be used to determine the length of the whole contiguous buffer.
>> + */
>> +static unsigned int mon_bin_collate_isodesc(const struct mon_reader_bin *rp,
>> +    struct urb *urb, unsigned int ndesc)
>> +{
>> +	struct usb_iso_packet_descriptor *fp;
>> +	unsigned int length;
>> +
>> +	length = 0;
>> +	fp = urb->iso_frame_desc;
>> +	while (ndesc-- != 0) {
>> +		if (fp->status == 0 && fp->actual_length != 0) {
>> +			if (fp->offset + fp->actual_length > length)
>> +				length = fp->offset + fp->actual_length;
> 
> I don't know whether the compiler will optimize the two times computing the
> expression (fp->offset + fp->actual_length). Maybe I would use a local variable
> to compute the sum before the "if" and then use just the local variable.
> 
>> +		}
>> +		fp++;
>> +	}
>> +	return length;
>> +}
>> +
>>  static void mon_bin_get_isodesc(const struct mon_reader_bin *rp,
>>      unsigned int offset, struct urb *urb, char ev_type, unsigned int ndesc)
>>  {
>> @@ -479,6 +501,10 @@ static void mon_bin_event(struct mon_reader_bin *rp, struct urb *urb,
>>  	/*
>>  	 * Find the maximum allowable length, then allocate space.
>>  	 */
>> +	urb_length = (ev_type == 'S') ?
>> +	    urb->transfer_buffer_length : urb->actual_length;
>> +	length = urb_length;
>> +
>>  	if (usb_endpoint_xfer_isoc(epd)) {
>>  		if (urb->number_of_packets < 0) {
>>  			ndesc = 0;
>> @@ -487,14 +513,16 @@ static void mon_bin_event(struct mon_reader_bin *rp, struct urb *urb,
>>  		} else {
>>  			ndesc = urb->number_of_packets;
>>  		}
>> +		if (ev_type == 'C' && usb_urb_dir_in(urb))
>> +			length = mon_bin_collate_isodesc(rp, urb, ndesc);
>>  	} else {
>>  		ndesc = 0;
>>  	}
>>  	lendesc = ndesc*sizeof(struct mon_bin_isodesc);
>>  
>> -	urb_length = (ev_type == 'S') ?
>> -	    urb->transfer_buffer_length : urb->actual_length;
>> -	length = urb_length;
>> +	/* not an issue unless there's a subtle bug in a HCD somewhere */
>> +	if (length >= urb->transfer_buffer_length)
>> +		length = urb->transfer_buffer_length;
>>  
>>  	if (length >= rp->b_size/5)
>>  		length = rp->b_size/5;
>>
>>
> 
> 


  parent reply	other threads:[~2010-11-16  6:01 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-11-09  6:40 usbmon: size of different fields? Németh Márton
2010-11-09 14:50 ` Pete Zaitcev
2010-11-09 20:05   ` Németh Márton
2010-11-09 21:23     ` [Wireshark-dev] " Guy Harris
2010-11-10 15:21       ` Pete Zaitcev
2010-11-10 17:36         ` Guy Harris
2010-11-13 22:15     ` [PATCH, RFC] usbmon: correct computing of the ISO packets with mmap Németh Márton
2010-11-14 19:40       ` Pete Zaitcev
2010-11-14 20:24         ` Németh Márton
2010-11-14 21:08           ` Pete Zaitcev
2010-11-14 23:25           ` Pete Zaitcev
2010-11-15  3:01             ` Alan Stern
2010-11-15  3:42               ` Pete Zaitcev
2010-11-15 15:01                 ` Alan Stern
2010-11-15  5:48             ` Németh Márton
2010-11-15  6:12               ` Pete Zaitcev
2010-11-15 15:06                 ` Alan Stern
2010-11-16  6:00               ` Németh Márton [this message]
2010-11-09 15:05 ` usbmon: size of different fields? Alan Stern

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4CE21E17.70107@freemail.hu \
    --to=nm127@freemail.hu \
    --cc=gregkh@suse.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=zaitcev@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox