Message ID | 20180619215521.13688-7-bigeasy@linutronix.de (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
On Tuesday, June 19, 2018 11:55 PM, Sebastian Andrzej Siewior wrote: > Using usb_fill_int_urb() helps to find code which initializes an > URB. A grep for members of the struct (like ->complete) reveal lots > of other things, too. Acked-by: Daniel Mack <zonque@gmail.com> > Cc: Jaroslav Kysela <perex@perex.cz> > Cc: Takashi Iwai <tiwai@suse.com> > Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de> > --- > sound/usb/caiaq/audio.c | 23 +++++++++++------------ > 1 file changed, 11 insertions(+), 12 deletions(-) > > diff --git a/sound/usb/caiaq/audio.c b/sound/usb/caiaq/audio.c > index 15344d39a6cd..e10d5790099f 100644 > --- a/sound/usb/caiaq/audio.c > +++ b/sound/usb/caiaq/audio.c > @@ -736,16 +736,17 @@ static struct urb **alloc_urbs(struct snd_usb_caiaqdev *cdev, int dir, int *ret) > } > > for (i = 0; i < N_URBS; i++) { > + void *buf; > + > urbs[i] = usb_alloc_urb(FRAMES_PER_URB, GFP_KERNEL); > if (!urbs[i]) { > *ret = -ENOMEM; > return urbs; > } > > - urbs[i]->transfer_buffer = > - kmalloc_array(BYTES_PER_FRAME, FRAMES_PER_URB, > - GFP_KERNEL); > - if (!urbs[i]->transfer_buffer) { > + buf = kmalloc_array(BYTES_PER_FRAME, FRAMES_PER_URB, > + GFP_KERNEL); > + if (!buf) { > *ret = -ENOMEM; > return urbs; > } > @@ -758,15 +759,13 @@ static struct urb **alloc_urbs(struct snd_usb_caiaqdev *cdev, int dir, int *ret) > iso->length = BYTES_PER_FRAME; > } > > - urbs[i]->dev = usb_dev; > - urbs[i]->pipe = pipe; > - urbs[i]->transfer_buffer_length = FRAMES_PER_URB > - * BYTES_PER_FRAME; > - urbs[i]->context = &cdev->data_cb_info[i]; > - urbs[i]->interval = 1; > + usb_fill_int_urb(urbs[i], usb_dev, pipe, buf, > + FRAMES_PER_URB * BYTES_PER_FRAME, > + (dir == SNDRV_PCM_STREAM_CAPTURE) ? > + read_completed : write_completed, > + &cdev->data_cb_info[i], 1); > + > urbs[i]->number_of_packets = FRAMES_PER_URB; > - urbs[i]->complete = (dir == SNDRV_PCM_STREAM_CAPTURE) ? > - read_completed : write_completed; > } > > *ret = 0; >
On 2018-06-21 22:19:32 [+0200], Daniel Mack wrote: > On Tuesday, June 19, 2018 11:55 PM, Sebastian Andrzej Siewior wrote: > > Using usb_fill_int_urb() helps to find code which initializes an > > URB. A grep for members of the struct (like ->complete) reveal lots > > of other things, too. > > Acked-by: Daniel Mack <zonque@gmail.com> nope, please don't. Takashi, please ignore the usb_fill_.* patches. I will be doing another spin with usb_fill_iso_urb() instead. Sebastian
On Thu, 21 Jun 2018 23:16:39 +0200, Sebastian Andrzej Siewior wrote: > > On 2018-06-21 22:19:32 [+0200], Daniel Mack wrote: > > On Tuesday, June 19, 2018 11:55 PM, Sebastian Andrzej Siewior wrote: > > > Using usb_fill_int_urb() helps to find code which initializes an > > > URB. A grep for members of the struct (like ->complete) reveal lots > > > of other things, too. > > > > Acked-by: Daniel Mack <zonque@gmail.com> > > nope, please don't. > Takashi, please ignore the usb_fill_.* patches. I will be doing another > spin with usb_fill_iso_urb() instead. This sounds like a better approach, indeed. thanks, Takashi
On Thursday, June 21, 2018 11:16 PM, Sebastian Andrzej Siewior wrote: > On 2018-06-21 22:19:32 [+0200], Daniel Mack wrote: >> On Tuesday, June 19, 2018 11:55 PM, Sebastian Andrzej Siewior wrote: >>> Using usb_fill_int_urb() helps to find code which initializes an >>> URB. A grep for members of the struct (like ->complete) reveal lots >>> of other things, too. >> >> Acked-by: Daniel Mack <zonque@gmail.com> > > nope, please don't. > Takashi, please ignore the usb_fill_.* patches. I will be doing another > spin with usb_fill_iso_urb() instead. Hmm, there is no such thing as usb_fill_iso_urb() in my tree, are you going to add that? The only part that needs attention is the interval parameter, which is passed to usb_fill_int_urb() as 1 now, and hence urb->interval will also be 1, just like the open-coded version before. Unless I miss anything, your conversion should work, but I haven't tested it yet. But I agree the function name is misleading, so we should probably get a usb_fill_iso_urb() and use it where appropriate. AFAICS, it will be identical to usb_fill_bulk_urb(), as the endpoint type is encoded in the pipe. Maybe it's worth adding a check? Thanks, Daniel
On 2018-06-22 12:01:13 [+0200], Daniel Mack wrote: > Hmm, there is no such thing as usb_fill_iso_urb() in my tree, are you going > to add that? Yes. > The only part that needs attention is the interval parameter, which is > passed to usb_fill_int_urb() as 1 now, and hence urb->interval will also be > 1, just like the open-coded version before. Unless I miss anything, your > conversion should work, but I haven't tested it yet. It should work in most cases. The point is that the argument expects bInterval (from the endpoint) which has a different encoding on FS vs HS/SS for INTR endpoints but not for ISOC endpoints and I got this wrong initially. > But I agree the function name is misleading, so we should probably get a > usb_fill_iso_urb() and use it where appropriate. AFAICS, it will be > identical to usb_fill_bulk_urb(), as the endpoint type is encoded in the > pipe. Maybe it's worth adding a check? What check? it should be identical to INTR without the speed check (always the HS version should be used). I need to check if it makes sense to extend the parameters to cover ->number_of_packets and so on. Any way, I plan to first RFC the function, land it upstream and then convert the users. > Thanks, > Daniel Sebastian
diff --git a/sound/usb/caiaq/audio.c b/sound/usb/caiaq/audio.c index 15344d39a6cd..e10d5790099f 100644 --- a/sound/usb/caiaq/audio.c +++ b/sound/usb/caiaq/audio.c @@ -736,16 +736,17 @@ static struct urb **alloc_urbs(struct snd_usb_caiaqdev *cdev, int dir, int *ret) } for (i = 0; i < N_URBS; i++) { + void *buf; + urbs[i] = usb_alloc_urb(FRAMES_PER_URB, GFP_KERNEL); if (!urbs[i]) { *ret = -ENOMEM; return urbs; } - urbs[i]->transfer_buffer = - kmalloc_array(BYTES_PER_FRAME, FRAMES_PER_URB, - GFP_KERNEL); - if (!urbs[i]->transfer_buffer) { + buf = kmalloc_array(BYTES_PER_FRAME, FRAMES_PER_URB, + GFP_KERNEL); + if (!buf) { *ret = -ENOMEM; return urbs; } @@ -758,15 +759,13 @@ static struct urb **alloc_urbs(struct snd_usb_caiaqdev *cdev, int dir, int *ret) iso->length = BYTES_PER_FRAME; } - urbs[i]->dev = usb_dev; - urbs[i]->pipe = pipe; - urbs[i]->transfer_buffer_length = FRAMES_PER_URB - * BYTES_PER_FRAME; - urbs[i]->context = &cdev->data_cb_info[i]; - urbs[i]->interval = 1; + usb_fill_int_urb(urbs[i], usb_dev, pipe, buf, + FRAMES_PER_URB * BYTES_PER_FRAME, + (dir == SNDRV_PCM_STREAM_CAPTURE) ? + read_completed : write_completed, + &cdev->data_cb_info[i], 1); + urbs[i]->number_of_packets = FRAMES_PER_URB; - urbs[i]->complete = (dir == SNDRV_PCM_STREAM_CAPTURE) ? - read_completed : write_completed; } *ret = 0;
Using usb_fill_int_urb() helps to find code which initializes an URB. A grep for members of the struct (like ->complete) reveal lots of other things, too. Cc: Daniel Mack <zonque@gmail.com> Cc: Jaroslav Kysela <perex@perex.cz> Cc: Takashi Iwai <tiwai@suse.com> Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de> --- sound/usb/caiaq/audio.c | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-)