Commit 5917def5 authored by Tomas Winkler's avatar Tomas Winkler Committed by Greg Kroah-Hartman

staging/easycap: reduce code nesting in easycap_sound.c

Reshuffle error handling to reduce indentation nesting
This reduce number of lines exceeding 80 characters
from 41 to 15

use:
if (error)
	(return, goto, continue)
CODE

instead of:

if (good)
	<CODE>
else
	<EXCEPTION HANDLING>

Cc: Dan Carpenter <error27@gmail.com>
Cc: Mike Thomas <rmthomas@sciolus.org>
Signed-off-by: default avatarTomas Winkler <tomas.winkler@intel.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@suse.de>
parent 07ba111f
...@@ -142,11 +142,22 @@ easycap_alsa_complete(struct urb *purb) ...@@ -142,11 +142,22 @@ easycap_alsa_complete(struct urb *purb)
strerror(purb->iso_frame_desc[i].status), strerror(purb->iso_frame_desc[i].status),
purb->iso_frame_desc[i].status); purb->iso_frame_desc[i].status);
} }
if (!purb->iso_frame_desc[i].status) { if (purb->iso_frame_desc[i].status) {
JOM(12, "discarding audio samples because "
"%i=purb->iso_frame_desc[i].status\n",
purb->iso_frame_desc[i].status);
continue;
}
more = purb->iso_frame_desc[i].actual_length; more = purb->iso_frame_desc[i].actual_length;
if (!more) if (more == 0) {
peasycap->audio_mt++; peasycap->audio_mt++;
else { continue;
}
if (0 > more) {
SAM("MISTAKE: more is negative\n");
return;
}
if (peasycap->audio_mt) { if (peasycap->audio_mt) {
JOM(12, "%4i empty audio urb frames\n", JOM(12, "%4i empty audio urb frames\n",
peasycap->audio_mt); peasycap->audio_mt);
...@@ -163,10 +174,6 @@ easycap_alsa_complete(struct urb *purb) ...@@ -163,10 +174,6 @@ easycap_alsa_complete(struct urb *purb)
* LITTLE-ENDIAN SAMPLES IF NECESSARY * LITTLE-ENDIAN SAMPLES IF NECESSARY
*/ */
while (more) { while (more) {
if (0 > more) {
SAM("MISTAKE: more is negative\n");
return;
}
much = dma_bytes - peasycap->dma_fill; much = dma_bytes - peasycap->dma_fill;
if (0 > much) { if (0 > much) {
SAM("MISTAKE: much is negative\n"); SAM("MISTAKE: much is negative\n");
...@@ -180,8 +187,7 @@ easycap_alsa_complete(struct urb *purb) ...@@ -180,8 +187,7 @@ easycap_alsa_complete(struct urb *purb)
if (!peasycap->microphone) { if (!peasycap->microphone) {
if (much > more) if (much > more)
much = more; much = more;
memcpy(prt->dma_area + memcpy(prt->dma_area + peasycap->dma_fill,
peasycap->dma_fill,
p1, much); p1, much);
p1 += much; p1 += much;
more -= much; more -= much;
...@@ -191,11 +197,10 @@ easycap_alsa_complete(struct urb *purb) ...@@ -191,11 +197,10 @@ easycap_alsa_complete(struct urb *purb)
JOM(8, "MISTAKE? much" JOM(8, "MISTAKE? much"
" is not divisible by 16\n"); " is not divisible by 16\n");
if (much > (16 * more)) if (much > (16 * more))
much = 16 * much = 16 * more;
more;
p2 = (u8 *)(prt->dma_area + peasycap->dma_fill); p2 = (u8 *)(prt->dma_area + peasycap->dma_fill);
for (j = 0; j < (much/16); j++) { for (j = 0; j < (much / 16); j++) {
newaudio = ((int) *p1) - 128; newaudio = ((int) *p1) - 128;
newaudio = 128 * newaudio; newaudio = 128 * newaudio;
...@@ -235,8 +240,7 @@ easycap_alsa_complete(struct urb *purb) ...@@ -235,8 +240,7 @@ easycap_alsa_complete(struct urb *purb)
if (peasycap->dma_fill >= peasycap->dma_next) { if (peasycap->dma_fill >= peasycap->dma_next) {
isfragment = peasycap->dma_fill / fragment_bytes; isfragment = peasycap->dma_fill / fragment_bytes;
if (0 > isfragment) { if (0 > isfragment) {
SAM("MISTAKE: isfragment is " SAM("MISTAKE: isfragment is negative\n");
"negative\n");
return; return;
} }
peasycap->dma_read = (isfragment - 1) * fragment_bytes; peasycap->dma_read = (isfragment - 1) * fragment_bytes;
...@@ -245,20 +249,12 @@ easycap_alsa_complete(struct urb *purb) ...@@ -245,20 +249,12 @@ easycap_alsa_complete(struct urb *purb)
peasycap->dma_next = fragment_bytes; peasycap->dma_next = fragment_bytes;
if (0 <= peasycap->dma_read) { if (0 <= peasycap->dma_read) {
JOM(8, "snd_pcm_period_elap" JOM(8, "snd_pcm_period_elapsed(), %i="
"sed(), %i=" "isfragment\n", isfragment);
"isfragment\n",
isfragment);
snd_pcm_period_elapsed(pss); snd_pcm_period_elapsed(pss);
} }
} }
} }
}
} else {
JOM(12, "discarding audio samples because "
"%i=purb->iso_frame_desc[i].status\n",
purb->iso_frame_desc[i].status);
}
#ifdef UPSAMPLE #ifdef UPSAMPLE
peasycap->oldaudio = oldaudio; peasycap->oldaudio = oldaudio;
...@@ -271,18 +267,18 @@ easycap_alsa_complete(struct urb *purb) ...@@ -271,18 +267,18 @@ easycap_alsa_complete(struct urb *purb)
*/ */
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
resubmit: resubmit:
if (peasycap->audio_isoc_streaming) { if (peasycap->audio_isoc_streaming == 0)
return;
rc = usb_submit_urb(purb, GFP_ATOMIC); rc = usb_submit_urb(purb, GFP_ATOMIC);
if (rc) { if (rc) {
if ((-ENODEV != rc) && (-ENOENT != rc)) { if ((-ENODEV != rc) && (-ENOENT != rc)) {
SAM("ERROR: while %i=audio_idle, " SAM("ERROR: while %i=audio_idle, usb_submit_urb failed "
"usb_submit_urb() failed " "with rc: -%s :%d\n",
"with rc: -%s :%d\n", peasycap->audio_idle, peasycap->audio_idle, strerror(rc), rc);
strerror(rc), rc);
} }
if (0 < peasycap->audio_isoc_streaming) if (0 < peasycap->audio_isoc_streaming)
(peasycap->audio_isoc_streaming)--; peasycap->audio_isoc_streaming--;
}
} }
return; return;
} }
...@@ -643,10 +639,9 @@ int easycap_alsa_probe(struct easycap *peasycap) ...@@ -643,10 +639,9 @@ int easycap_alsa_probe(struct easycap *peasycap)
SAM("ERROR: Cannot do ALSA snd_card_register()\n"); SAM("ERROR: Cannot do ALSA snd_card_register()\n");
snd_card_free(psnd_card); snd_card_free(psnd_card);
return -EFAULT; return -EFAULT;
} else {
;
SAM("registered %s\n", &psnd_card->id[0]);
} }
SAM("registered %s\n", &psnd_card->id[0]);
return 0; return 0;
} }
#endif /*! CONFIG_EASYCAP_OSS */ #endif /*! CONFIG_EASYCAP_OSS */
...@@ -737,7 +732,12 @@ submit_audio_urbs(struct easycap *peasycap) ...@@ -737,7 +732,12 @@ submit_audio_urbs(struct easycap *peasycap)
SAM("ERROR: peasycap->pusb_device is NULL\n"); SAM("ERROR: peasycap->pusb_device is NULL\n");
return -EFAULT; return -EFAULT;
} }
if (!peasycap->audio_isoc_streaming) {
if (peasycap->audio_isoc_streaming) {
JOM(4, "already streaming audio urbs\n");
return 0;
}
JOM(4, "initial submission of all audio urbs\n"); JOM(4, "initial submission of all audio urbs\n");
rc = usb_set_interface(peasycap->pusb_device, rc = usb_set_interface(peasycap->pusb_device,
peasycap->audio_interface, peasycap->audio_interface,
...@@ -749,11 +749,10 @@ submit_audio_urbs(struct easycap *peasycap) ...@@ -749,11 +749,10 @@ submit_audio_urbs(struct easycap *peasycap)
isbad = 0; isbad = 0;
nospc = 0; nospc = 0;
m = 0; m = 0;
list_for_each(plist_head, (peasycap->purb_audio_head)) { list_for_each(plist_head, peasycap->purb_audio_head) {
pdata_urb = list_entry(plist_head, struct data_urb, list_head); pdata_urb = list_entry(plist_head, struct data_urb, list_head);
if (pdata_urb) { if (pdata_urb && pdata_urb->purb) {
purb = pdata_urb->purb; purb = pdata_urb->purb;
if (purb) {
isbuf = pdata_urb->isbuf; isbuf = pdata_urb->isbuf;
purb->interval = 1; purb->interval = 1;
...@@ -788,9 +787,6 @@ submit_audio_urbs(struct easycap *peasycap) ...@@ -788,9 +787,6 @@ submit_audio_urbs(struct easycap *peasycap)
} else { } else {
isbad++; isbad++;
} }
} else {
isbad++;
}
} }
if (nospc) { if (nospc) {
SAM("-ENOSPC=usb_submit_urb() for %i urbs\n", nospc); SAM("-ENOSPC=usb_submit_urb() for %i urbs\n", nospc);
...@@ -801,19 +797,14 @@ submit_audio_urbs(struct easycap *peasycap) ...@@ -801,19 +797,14 @@ submit_audio_urbs(struct easycap *peasycap)
JOM(4, "attempting cleanup instead of submitting\n"); JOM(4, "attempting cleanup instead of submitting\n");
list_for_each(plist_head, (peasycap->purb_audio_head)) { list_for_each(plist_head, (peasycap->purb_audio_head)) {
pdata_urb = list_entry(plist_head, struct data_urb, list_head); pdata_urb = list_entry(plist_head, struct data_urb, list_head);
if (pdata_urb) { if (pdata_urb && pdata_urb->purb)
purb = pdata_urb->purb; usb_kill_urb(pdata_urb->purb);
if (purb)
usb_kill_urb(purb);
}
} }
peasycap->audio_isoc_streaming = 0; peasycap->audio_isoc_streaming = 0;
} else { } else {
peasycap->audio_isoc_streaming = m; peasycap->audio_isoc_streaming = m;
JOM(4, "submitted %i audio urbs\n", m); JOM(4, "submitted %i audio urbs\n", m);
} }
} else
JOM(4, "already streaming audio urbs\n");
return 0; return 0;
} }
...@@ -834,29 +825,30 @@ kill_audio_urbs(struct easycap *peasycap) ...@@ -834,29 +825,30 @@ kill_audio_urbs(struct easycap *peasycap)
SAY("ERROR: peasycap is NULL\n"); SAY("ERROR: peasycap is NULL\n");
return -EFAULT; return -EFAULT;
} }
if (peasycap->audio_isoc_streaming) {
if (peasycap->purb_audio_head) { if (!peasycap->audio_isoc_streaming) {
JOM(8, "%i=audio_isoc_streaming, no audio urbs killed\n",
peasycap->audio_isoc_streaming);
return 0;
}
if (!peasycap->purb_audio_head) {
SAM("ERROR: peasycap->purb_audio_head is NULL\n");
return -EFAULT;
}
peasycap->audio_isoc_streaming = 0; peasycap->audio_isoc_streaming = 0;
JOM(4, "killing audio urbs\n"); JOM(4, "killing audio urbs\n");
m = 0; m = 0;
list_for_each(plist_head, (peasycap->purb_audio_head)) { list_for_each(plist_head, (peasycap->purb_audio_head)) {
pdata_urb = list_entry(plist_head, struct data_urb, list_head); pdata_urb = list_entry(plist_head, struct data_urb, list_head);
if (pdata_urb) { if (pdata_urb && pdata_urb->purb) {
if (pdata_urb->purb) {
usb_kill_urb(pdata_urb->purb); usb_kill_urb(pdata_urb->purb);
m++; m++;
} }
} }
}
JOM(4, "%i audio urbs killed\n", m); JOM(4, "%i audio urbs killed\n", m);
} else {
SAM("ERROR: peasycap->purb_audio_head is NULL\n");
return -EFAULT;
}
} else {
JOM(8, "%i=audio_isoc_streaming, no audio urbs killed\n",
peasycap->audio_isoc_streaming);
}
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