Commit 8b1fad2f authored by Tomas Winkler's avatar Tomas Winkler Committed by Mauro Carvalho Chehab

[media] easycap: use usb_kill_urb wrapper functions

1. kill_video_usb can be used in all places where video urbs are killed
and reduce code repetition

2. remove unnecessary check for easycap == NULL in the function
as it is always checked by the calling function

3. rename the function to easycap_video_kill_urb to reduce
possibility of name conflict

4. implement also easycap_audio_kill_urb

5. simplify freeing urbs
Signed-off-by: default avatarTomas Winkler <tomas.winkler@intel.com>
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab@redhat.com>
parent 7dfdae8e
...@@ -472,7 +472,7 @@ struct easycap { ...@@ -472,7 +472,7 @@ struct easycap {
long easycap_unlocked_ioctl(struct file *, unsigned int, unsigned long); long easycap_unlocked_ioctl(struct file *, unsigned int, unsigned long);
int easycap_dqbuf(struct easycap *, int); int easycap_dqbuf(struct easycap *, int);
int submit_video_urbs(struct easycap *); int submit_video_urbs(struct easycap *);
int kill_video_urbs(struct easycap *); int easycap_video_kill_urbs(struct easycap *);
void easycap_testcard(struct easycap *, int); void easycap_testcard(struct easycap *, int);
int fillin_formats(void); int fillin_formats(void);
int newinput(struct easycap *, int); int newinput(struct easycap *, int);
...@@ -489,6 +489,7 @@ int adjust_hue(struct easycap *, int); ...@@ -489,6 +489,7 @@ int adjust_hue(struct easycap *, int);
*/ */
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
int easycap_alsa_probe(struct easycap *); int easycap_alsa_probe(struct easycap *);
int easycap_audio_kill_urbs(struct easycap *);
void easycap_alsa_complete(struct urb *); void easycap_alsa_complete(struct urb *);
int audio_setup(struct easycap *); int audio_setup(struct easycap *);
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
......
...@@ -124,7 +124,7 @@ int adjust_standard(struct easycap *peasycap, v4l2_std_id std_id) ...@@ -124,7 +124,7 @@ int adjust_standard(struct easycap *peasycap, v4l2_std_id std_id)
} }
if (peasycap->video_isoc_streaming) { if (peasycap->video_isoc_streaming) {
resubmit = true; resubmit = true;
kill_video_urbs(peasycap); easycap_video_kill_urbs(peasycap);
} else } else
resubmit = false; resubmit = false;
/*--------------------------------------------------------------------------*/ /*--------------------------------------------------------------------------*/
...@@ -557,7 +557,7 @@ int adjust_format(struct easycap *peasycap, ...@@ -557,7 +557,7 @@ int adjust_format(struct easycap *peasycap,
peasycap->bytesperpixel * peasycap->width * peasycap->height; peasycap->bytesperpixel * peasycap->width * peasycap->height;
if (peasycap->video_isoc_streaming) { if (peasycap->video_isoc_streaming) {
resubmit = true; resubmit = true;
kill_video_urbs(peasycap); easycap_video_kill_urbs(peasycap);
} else } else
resubmit = false; resubmit = false;
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
......
...@@ -401,7 +401,7 @@ newinput(struct easycap *peasycap, int input) ...@@ -401,7 +401,7 @@ newinput(struct easycap *peasycap, int input)
peasycap->audio_idle = 1; peasycap->audio_idle = 1;
if (peasycap->video_isoc_streaming) { if (peasycap->video_isoc_streaming) {
resubmit = true; resubmit = true;
kill_video_urbs(peasycap); easycap_video_kill_urbs(peasycap);
} else { } else {
resubmit = false; resubmit = false;
} }
...@@ -620,43 +620,53 @@ int submit_video_urbs(struct easycap *peasycap) ...@@ -620,43 +620,53 @@ int submit_video_urbs(struct easycap *peasycap)
peasycap->video_eof = 1; peasycap->video_eof = 1;
} }
if (isbad) { if (isbad)
JOM(4, "attempting cleanup instead of submitting\n"); easycap_video_kill_urbs(peasycap);
list_for_each(plist_head, (peasycap->purb_video_head)) { else
pdata_urb = list_entry(plist_head,
struct data_urb, list_head);
if (pdata_urb) {
purb = pdata_urb->purb;
if (purb)
usb_kill_urb(purb);
}
}
peasycap->video_isoc_streaming = 0;
} else {
peasycap->video_isoc_streaming = 1; peasycap->video_isoc_streaming = 1;
JOM(4, "submitted %i video urbs\n", m);
}
} else { } else {
JOM(4, "already streaming video urbs\n"); JOM(4, "already streaming video urbs\n");
} }
return 0; return 0;
} }
/*****************************************************************************/ /*****************************************************************************/
int kill_video_urbs(struct easycap *peasycap) int easycap_audio_kill_urbs(struct easycap *peasycap)
{ {
int m; int m;
struct list_head *plist_head; struct list_head *plist_head;
struct data_urb *pdata_urb; struct data_urb *pdata_urb;
if (!peasycap) { if (!peasycap->audio_isoc_streaming)
SAY("ERROR: peasycap is NULL\n"); return 0;
if (!peasycap->purb_audio_head) {
SAM("ERROR: peasycap->purb_audio_head is NULL\n");
return -EFAULT; return -EFAULT;
} }
if (!peasycap->video_isoc_streaming) {
JOM(8, "%i=video_isoc_streaming, no video urbs killed\n", peasycap->audio_isoc_streaming = 0;
peasycap->video_isoc_streaming); m = 0;
return 0; list_for_each(plist_head, peasycap->purb_audio_head) {
pdata_urb = list_entry(plist_head, struct data_urb, list_head);
if (pdata_urb && pdata_urb->purb) {
usb_kill_urb(pdata_urb->purb);
m++;
}
} }
JOM(4, "%i audio urbs killed\n", m);
return 0;
}
int easycap_video_kill_urbs(struct easycap *peasycap)
{
int m;
struct list_head *plist_head;
struct data_urb *pdata_urb;
if (!peasycap->video_isoc_streaming)
return 0;
if (!peasycap->purb_video_head) { if (!peasycap->purb_video_head) {
SAM("ERROR: peasycap->purb_video_head is NULL\n"); SAM("ERROR: peasycap->purb_video_head is NULL\n");
return -EFAULT; return -EFAULT;
...@@ -694,8 +704,8 @@ static int videodev_release(struct video_device *pvideo_device) ...@@ -694,8 +704,8 @@ static int videodev_release(struct video_device *pvideo_device)
SAY("ending unsuccessfully\n"); SAY("ending unsuccessfully\n");
return -EFAULT; return -EFAULT;
} }
if (0 != kill_video_urbs(peasycap)) { if (easycap_video_kill_urbs(peasycap)) {
SAM("ERROR: kill_video_urbs() failed\n"); SAM("ERROR: easycap_video_kill_urbs() failed\n");
return -EFAULT; return -EFAULT;
} }
JOM(4, "ending successfully\n"); JOM(4, "ending successfully\n");
...@@ -738,20 +748,15 @@ static void easycap_delete(struct kref *pkref) ...@@ -738,20 +748,15 @@ static void easycap_delete(struct kref *pkref)
*/ */
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
if (peasycap->purb_video_head) { if (peasycap->purb_video_head) {
JOM(4, "freeing video urbs\n");
m = 0; m = 0;
list_for_each(plist_head, (peasycap->purb_video_head)) { list_for_each(plist_head, peasycap->purb_video_head) {
pdata_urb = list_entry(plist_head, pdata_urb = list_entry(plist_head,
struct data_urb, list_head); struct data_urb, list_head);
if (!pdata_urb) { if (pdata_urb && pdata_urb->purb) {
JOM(4, "ERROR: pdata_urb is NULL\n"); usb_free_urb(pdata_urb->purb);
} else { pdata_urb->purb = NULL;
if (pdata_urb->purb) { peasycap->allocation_video_urb--;
usb_free_urb(pdata_urb->purb); m++;
pdata_urb->purb = NULL;
peasycap->allocation_video_urb -= 1;
m++;
}
} }
} }
...@@ -767,7 +772,6 @@ static void easycap_delete(struct kref *pkref) ...@@ -767,7 +772,6 @@ static void easycap_delete(struct kref *pkref)
peasycap->allocation_video_struct -= peasycap->allocation_video_struct -=
sizeof(struct data_urb); sizeof(struct data_urb);
kfree(pdata_urb); kfree(pdata_urb);
pdata_urb = NULL;
m++; m++;
} }
} }
...@@ -832,15 +836,11 @@ static void easycap_delete(struct kref *pkref) ...@@ -832,15 +836,11 @@ static void easycap_delete(struct kref *pkref)
list_for_each(plist_head, (peasycap->purb_audio_head)) { list_for_each(plist_head, (peasycap->purb_audio_head)) {
pdata_urb = list_entry(plist_head, pdata_urb = list_entry(plist_head,
struct data_urb, list_head); struct data_urb, list_head);
if (!pdata_urb) if (pdata_urb && pdata_urb->purb) {
JOM(4, "ERROR: pdata_urb is NULL\n"); usb_free_urb(pdata_urb->purb);
else { pdata_urb->purb = NULL;
if (pdata_urb->purb) { peasycap->allocation_audio_urb--;
usb_free_urb(pdata_urb->purb); m++;
pdata_urb->purb = NULL;
peasycap->allocation_audio_urb -= 1;
m++;
}
} }
} }
JOM(4, "%i audio urbs freed\n", m); JOM(4, "%i audio urbs freed\n", m);
...@@ -855,7 +855,6 @@ static void easycap_delete(struct kref *pkref) ...@@ -855,7 +855,6 @@ static void easycap_delete(struct kref *pkref)
peasycap->allocation_audio_struct -= peasycap->allocation_audio_struct -=
sizeof(struct data_urb); sizeof(struct data_urb);
kfree(pdata_urb); kfree(pdata_urb);
pdata_urb = NULL;
m++; m++;
} }
} }
...@@ -1084,7 +1083,7 @@ int easycap_dqbuf(struct easycap *peasycap, int mode) ...@@ -1084,7 +1083,7 @@ int easycap_dqbuf(struct easycap *peasycap, int mode)
JOM(8, " ... failed returning -EIO\n"); JOM(8, " ... failed returning -EIO\n");
peasycap->video_eof = 1; peasycap->video_eof = 1;
peasycap->audio_eof = 1; peasycap->audio_eof = 1;
kill_video_urbs(peasycap); easycap_video_kill_urbs(peasycap);
return -EIO; return -EIO;
} }
peasycap->status = 0; peasycap->status = 0;
...@@ -1094,7 +1093,7 @@ int easycap_dqbuf(struct easycap *peasycap, int mode) ...@@ -1094,7 +1093,7 @@ int easycap_dqbuf(struct easycap *peasycap, int mode)
#endif /*PERSEVERE*/ #endif /*PERSEVERE*/
peasycap->video_eof = 1; peasycap->video_eof = 1;
peasycap->audio_eof = 1; peasycap->audio_eof = 1;
kill_video_urbs(peasycap); easycap_video_kill_urbs(peasycap);
JOM(8, "returning -EIO\n"); JOM(8, "returning -EIO\n");
return -EIO; return -EIO;
} }
...@@ -1147,7 +1146,7 @@ int easycap_dqbuf(struct easycap *peasycap, int mode) ...@@ -1147,7 +1146,7 @@ int easycap_dqbuf(struct easycap *peasycap, int mode)
JOM(8, " ... failed returning -EIO\n"); JOM(8, " ... failed returning -EIO\n");
peasycap->video_eof = 1; peasycap->video_eof = 1;
peasycap->audio_eof = 1; peasycap->audio_eof = 1;
kill_video_urbs(peasycap); easycap_video_kill_urbs(peasycap);
return -EIO; return -EIO;
} }
peasycap->status = 0; peasycap->status = 0;
...@@ -1157,7 +1156,7 @@ int easycap_dqbuf(struct easycap *peasycap, int mode) ...@@ -1157,7 +1156,7 @@ int easycap_dqbuf(struct easycap *peasycap, int mode)
#endif /*PERSEVERE*/ #endif /*PERSEVERE*/
peasycap->video_eof = 1; peasycap->video_eof = 1;
peasycap->audio_eof = 1; peasycap->audio_eof = 1;
kill_video_urbs(peasycap); easycap_video_kill_urbs(peasycap);
JOM(8, "returning -EIO\n"); JOM(8, "returning -EIO\n");
return -EIO; return -EIO;
} }
...@@ -3969,12 +3968,9 @@ static void easycap_usb_disconnect(struct usb_interface *pusb_interface) ...@@ -3969,12 +3968,9 @@ static void easycap_usb_disconnect(struct usb_interface *pusb_interface)
{ {
struct usb_host_interface *pusb_host_interface; struct usb_host_interface *pusb_host_interface;
struct usb_interface_descriptor *pusb_interface_descriptor; struct usb_interface_descriptor *pusb_interface_descriptor;
u8 bInterfaceNumber;
struct easycap *peasycap; struct easycap *peasycap;
int minor, kd;
struct list_head *plist_head; u8 bInterfaceNumber;
struct data_urb *pdata_urb;
int minor, m, kd;
JOT(4, "\n"); JOT(4, "\n");
...@@ -4009,45 +4005,14 @@ static void easycap_usb_disconnect(struct usb_interface *pusb_interface) ...@@ -4009,45 +4005,14 @@ static void easycap_usb_disconnect(struct usb_interface *pusb_interface)
peasycap->audio_eof = 1; peasycap->audio_eof = 1;
wake_up_interruptible(&(peasycap->wq_video)); wake_up_interruptible(&(peasycap->wq_video));
wake_up_interruptible(&(peasycap->wq_audio)); wake_up_interruptible(&(peasycap->wq_audio));
/*---------------------------------------------------------------------------*/
switch (bInterfaceNumber) { switch (bInterfaceNumber) {
case 0: { case 0:
if (peasycap->purb_video_head) { easycap_video_kill_urbs(peasycap);
JOM(4, "killing video urbs\n");
m = 0;
list_for_each(plist_head, peasycap->purb_video_head) {
pdata_urb = list_entry(plist_head,
struct data_urb, list_head);
if (pdata_urb) {
if (pdata_urb->purb) {
usb_kill_urb(pdata_urb->purb);
m++;
}
}
}
JOM(4, "%i video urbs killed\n", m);
}
break; break;
} case 2:
/*---------------------------------------------------------------------------*/ easycap_audio_kill_urbs(peasycap);
case 2: {
if (peasycap->purb_audio_head) {
JOM(4, "killing audio urbs\n");
m = 0;
list_for_each(plist_head, peasycap->purb_audio_head) {
pdata_urb = list_entry(plist_head,
struct data_urb, list_head);
if (pdata_urb) {
if (pdata_urb->purb) {
usb_kill_urb(pdata_urb->purb);
m++;
}
}
}
JOM(4, "%i audio urbs killed\n", m);
}
break; break;
}
default: default:
break; break;
} }
......
...@@ -138,18 +138,11 @@ static int submit_audio_urbs(struct easycap *peasycap) ...@@ -138,18 +138,11 @@ static int submit_audio_urbs(struct easycap *peasycap)
SAM("..... possibly inadequate USB bandwidth\n"); SAM("..... possibly inadequate USB bandwidth\n");
peasycap->audio_eof = 1; peasycap->audio_eof = 1;
} }
if (isbad) {
JOM(4, "attempting cleanup instead of submitting\n"); if (isbad)
list_for_each(plist_head, (peasycap->purb_audio_head)) { easycap_audio_kill_urbs(peasycap);
pdata_urb = list_entry(plist_head, struct data_urb, list_head); else
if (pdata_urb && pdata_urb->purb)
usb_kill_urb(pdata_urb->purb);
}
peasycap->audio_isoc_streaming = 0;
} else {
peasycap->audio_isoc_streaming = m; peasycap->audio_isoc_streaming = m;
JOM(4, "submitted %i audio urbs\n", m);
}
return 0; return 0;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment