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)
strerror(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;
if (!more)
if (more == 0) {
peasycap->audio_mt++;
else {
continue;
}
if (0 > more) {
SAM("MISTAKE: more is negative\n");
return;
}
if (peasycap->audio_mt) {
JOM(12, "%4i empty audio urb frames\n",
peasycap->audio_mt);
......@@ -163,10 +174,6 @@ easycap_alsa_complete(struct urb *purb)
* LITTLE-ENDIAN SAMPLES IF NECESSARY
*/
while (more) {
if (0 > more) {
SAM("MISTAKE: more is negative\n");
return;
}
much = dma_bytes - peasycap->dma_fill;
if (0 > much) {
SAM("MISTAKE: much is negative\n");
......@@ -180,8 +187,7 @@ easycap_alsa_complete(struct urb *purb)
if (!peasycap->microphone) {
if (much > more)
much = more;
memcpy(prt->dma_area +
peasycap->dma_fill,
memcpy(prt->dma_area + peasycap->dma_fill,
p1, much);
p1 += much;
more -= much;
......@@ -191,11 +197,10 @@ easycap_alsa_complete(struct urb *purb)
JOM(8, "MISTAKE? much"
" is not divisible by 16\n");
if (much > (16 * more))
much = 16 *
more;
much = 16 * more;
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 = 128 * newaudio;
......@@ -235,8 +240,7 @@ easycap_alsa_complete(struct urb *purb)
if (peasycap->dma_fill >= peasycap->dma_next) {
isfragment = peasycap->dma_fill / fragment_bytes;
if (0 > isfragment) {
SAM("MISTAKE: isfragment is "
"negative\n");
SAM("MISTAKE: isfragment is negative\n");
return;
}
peasycap->dma_read = (isfragment - 1) * fragment_bytes;
......@@ -245,20 +249,12 @@ easycap_alsa_complete(struct urb *purb)
peasycap->dma_next = fragment_bytes;
if (0 <= peasycap->dma_read) {
JOM(8, "snd_pcm_period_elap"
"sed(), %i="
"isfragment\n",
isfragment);
JOM(8, "snd_pcm_period_elapsed(), %i="
"isfragment\n", isfragment);
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
peasycap->oldaudio = oldaudio;
......@@ -271,18 +267,18 @@ easycap_alsa_complete(struct urb *purb)
*/
/*---------------------------------------------------------------------------*/
resubmit:
if (peasycap->audio_isoc_streaming) {
if (peasycap->audio_isoc_streaming == 0)
return;
rc = usb_submit_urb(purb, GFP_ATOMIC);
if (rc) {
if ((-ENODEV != rc) && (-ENOENT != rc)) {
SAM("ERROR: while %i=audio_idle, "
"usb_submit_urb() failed "
"with rc: -%s :%d\n", peasycap->audio_idle,
strerror(rc), rc);
SAM("ERROR: while %i=audio_idle, usb_submit_urb failed "
"with rc: -%s :%d\n",
peasycap->audio_idle, strerror(rc), rc);
}
if (0 < peasycap->audio_isoc_streaming)
(peasycap->audio_isoc_streaming)--;
}
peasycap->audio_isoc_streaming--;
}
return;
}
......@@ -643,10 +639,9 @@ int easycap_alsa_probe(struct easycap *peasycap)
SAM("ERROR: Cannot do ALSA snd_card_register()\n");
snd_card_free(psnd_card);
return -EFAULT;
} else {
;
SAM("registered %s\n", &psnd_card->id[0]);
}
SAM("registered %s\n", &psnd_card->id[0]);
return 0;
}
#endif /*! CONFIG_EASYCAP_OSS */
......@@ -737,7 +732,12 @@ submit_audio_urbs(struct easycap *peasycap)
SAM("ERROR: peasycap->pusb_device is NULL\n");
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");
rc = usb_set_interface(peasycap->pusb_device,
peasycap->audio_interface,
......@@ -749,11 +749,10 @@ submit_audio_urbs(struct easycap *peasycap)
isbad = 0;
nospc = 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);
if (pdata_urb) {
if (pdata_urb && pdata_urb->purb) {
purb = pdata_urb->purb;
if (purb) {
isbuf = pdata_urb->isbuf;
purb->interval = 1;
......@@ -788,9 +787,6 @@ submit_audio_urbs(struct easycap *peasycap)
} else {
isbad++;
}
} else {
isbad++;
}
}
if (nospc) {
SAM("-ENOSPC=usb_submit_urb() for %i urbs\n", nospc);
......@@ -801,19 +797,14 @@ submit_audio_urbs(struct easycap *peasycap)
JOM(4, "attempting cleanup instead of submitting\n");
list_for_each(plist_head, (peasycap->purb_audio_head)) {
pdata_urb = list_entry(plist_head, struct data_urb, list_head);
if (pdata_urb) {
purb = pdata_urb->purb;
if (purb)
usb_kill_urb(purb);
}
if (pdata_urb && pdata_urb->purb)
usb_kill_urb(pdata_urb->purb);
}
peasycap->audio_isoc_streaming = 0;
} else {
peasycap->audio_isoc_streaming = m;
JOM(4, "submitted %i audio urbs\n", m);
}
} else
JOM(4, "already streaming audio urbs\n");
return 0;
}
......@@ -834,29 +825,30 @@ kill_audio_urbs(struct easycap *peasycap)
SAY("ERROR: peasycap is NULL\n");
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;
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) {
if (pdata_urb && pdata_urb->purb) {
usb_kill_urb(pdata_urb->purb);
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;
}
/*****************************************************************************/
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