提交 5917def5 编写于 作者: T Tomas Winkler 提交者: 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: NTomas Winkler <tomas.winkler@intel.com>
Signed-off-by: NGreg Kroah-Hartman <gregkh@suse.de>
上级 07ba111f
...@@ -142,122 +142,118 @@ easycap_alsa_complete(struct urb *purb) ...@@ -142,122 +142,118 @@ 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) {
more = purb->iso_frame_desc[i].actual_length; JOM(12, "discarding audio samples because "
if (!more) "%i=purb->iso_frame_desc[i].status\n",
peasycap->audio_mt++; purb->iso_frame_desc[i].status);
else { continue;
if (peasycap->audio_mt) { }
JOM(12, "%4i empty audio urb frames\n", more = purb->iso_frame_desc[i].actual_length;
peasycap->audio_mt); if (more == 0) {
peasycap->audio_mt = 0; peasycap->audio_mt++;
} continue;
}
if (0 > more) {
SAM("MISTAKE: more is negative\n");
return;
}
p1 = (u8 *)(purb->transfer_buffer + if (peasycap->audio_mt) {
purb->iso_frame_desc[i].offset); JOM(12, "%4i empty audio urb frames\n",
peasycap->audio_mt);
/* peasycap->audio_mt = 0;
* COPY more BYTES FROM ISOC BUFFER }
* TO THE DMA BUFFER, CONVERTING
* 8-BIT MONO TO 16-BIT SIGNED p1 = (u8 *)(purb->transfer_buffer +
* LITTLE-ENDIAN SAMPLES IF NECESSARY purb->iso_frame_desc[i].offset);
*/
while (more) { /*
if (0 > more) { * COPY more BYTES FROM ISOC BUFFER
SAM("MISTAKE: more is negative\n"); * TO THE DMA BUFFER, CONVERTING
return; * 8-BIT MONO TO 16-BIT SIGNED
} * LITTLE-ENDIAN SAMPLES IF NECESSARY
much = dma_bytes - peasycap->dma_fill; */
if (0 > much) { while (more) {
SAM("MISTAKE: much is negative\n"); much = dma_bytes - peasycap->dma_fill;
return; if (0 > much) {
} SAM("MISTAKE: much is negative\n");
if (0 == much) { return;
peasycap->dma_fill = 0; }
peasycap->dma_next = fragment_bytes; if (0 == much) {
JOM(8, "wrapped dma buffer\n"); peasycap->dma_fill = 0;
} peasycap->dma_next = fragment_bytes;
if (!peasycap->microphone) { JOM(8, "wrapped dma buffer\n");
if (much > more) }
much = more; if (!peasycap->microphone) {
memcpy(prt->dma_area + if (much > more)
peasycap->dma_fill, much = more;
p1, much); memcpy(prt->dma_area + peasycap->dma_fill,
p1 += much; p1, much);
more -= much; p1 += much;
} else { more -= much;
} else {
#ifdef UPSAMPLE #ifdef UPSAMPLE
if (much % 16) if (much % 16)
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;
delta = (newaudio - oldaudio) / 4;
delta = (newaudio - oldaudio) / 4; tmp = oldaudio + delta;
tmp = oldaudio + delta;
for (k = 0; k < 4; k++) {
for (k = 0; k < 4; k++) { *p2 = (0x00FF & tmp);
*p2 = (0x00FF & tmp); *(p2 + 1) = (0xFF00 & tmp) >> 8;
*(p2 + 1) = (0xFF00 & tmp) >> 8; p2 += 2;
p2 += 2; *p2 = (0x00FF & tmp);
*p2 = (0x00FF & tmp); *(p2 + 1) = (0xFF00 & tmp) >> 8;
*(p2 + 1) = (0xFF00 & tmp) >> 8; p2 += 2;
p2 += 2; tmp += delta;
tmp += delta; }
} p1++;
p1++; more--;
more--; oldaudio = tmp;
oldaudio = tmp; }
}
#else /*!UPSAMPLE*/ #else /*!UPSAMPLE*/
if (much > (2 * more)) if (much > (2 * more))
much = 2 * more; much = 2 * more;
p2 = (u8 *)(prt->dma_area + peasycap->dma_fill); p2 = (u8 *)(prt->dma_area + peasycap->dma_fill);
for (j = 0; j < (much / 2); j++) { for (j = 0; j < (much / 2); j++) {
tmp = ((int) *p1) - 128; tmp = ((int) *p1) - 128;
tmp = 128 * tmp; tmp = 128 * tmp;
*p2 = (0x00FF & tmp); *p2 = (0x00FF & tmp);
*(p2 + 1) = (0xFF00 & tmp) >> 8; *(p2 + 1) = (0xFF00 & tmp) >> 8;
p1++; p1++;
p2 += 2; p2 += 2;
more--; more--;
} }
#endif /*UPSAMPLE*/ #endif /*UPSAMPLE*/
} }
peasycap->dma_fill += much; peasycap->dma_fill += much;
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; peasycap->dma_next = (isfragment + 1) * fragment_bytes;
peasycap->dma_next = (isfragment + 1) * fragment_bytes; if (dma_bytes < peasycap->dma_next)
if (dma_bytes < peasycap->dma_next) 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_elapsed(), %i="
JOM(8, "snd_pcm_period_elap" "isfragment\n", isfragment);
"sed(), %i=" snd_pcm_period_elapsed(pss);
"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 #ifdef UPSAMPLE
...@@ -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)
rc = usb_submit_urb(purb, GFP_ATOMIC); return;
if (rc) {
if ((-ENODEV != rc) && (-ENOENT != rc)) { rc = usb_submit_urb(purb, GFP_ATOMIC);
SAM("ERROR: while %i=audio_idle, " if (rc) {
"usb_submit_urb() failed " if ((-ENODEV != rc) && (-ENOENT != rc)) {
"with rc: -%s :%d\n", peasycap->audio_idle, SAM("ERROR: while %i=audio_idle, usb_submit_urb failed "
strerror(rc), rc); "with rc: -%s :%d\n",
} peasycap->audio_idle, strerror(rc), rc);
if (0 < peasycap->audio_isoc_streaming)
(peasycap->audio_isoc_streaming)--;
} }
if (0 < 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,83 +732,79 @@ submit_audio_urbs(struct easycap *peasycap) ...@@ -737,83 +732,79 @@ 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) {
JOM(4, "initial submission of all audio urbs\n"); if (peasycap->audio_isoc_streaming) {
rc = usb_set_interface(peasycap->pusb_device, JOM(4, "already streaming audio urbs\n");
peasycap->audio_interface, return 0;
peasycap->audio_altsetting_on); }
JOM(8, "usb_set_interface(.,%i,%i) returned %i\n",
peasycap->audio_interface, JOM(4, "initial submission of all audio urbs\n");
peasycap->audio_altsetting_on, rc); rc = usb_set_interface(peasycap->pusb_device,
peasycap->audio_interface,
isbad = 0; peasycap->audio_altsetting_on);
nospc = 0; JOM(8, "usb_set_interface(.,%i,%i) returned %i\n",
m = 0; peasycap->audio_interface,
list_for_each(plist_head, (peasycap->purb_audio_head)) { peasycap->audio_altsetting_on, rc);
pdata_urb = list_entry(plist_head, struct data_urb, list_head);
if (pdata_urb) { isbad = 0;
purb = pdata_urb->purb; nospc = 0;
if (purb) { m = 0;
isbuf = pdata_urb->isbuf; list_for_each(plist_head, peasycap->purb_audio_head) {
pdata_urb = list_entry(plist_head, struct data_urb, list_head);
purb->interval = 1; if (pdata_urb && pdata_urb->purb) {
purb->dev = peasycap->pusb_device; purb = pdata_urb->purb;
purb->pipe = usb_rcvisocpipe(peasycap->pusb_device, isbuf = pdata_urb->isbuf;
peasycap->audio_endpointnumber);
purb->transfer_flags = URB_ISO_ASAP; purb->interval = 1;
purb->transfer_buffer = peasycap->audio_isoc_buffer[isbuf].pgo; purb->dev = peasycap->pusb_device;
purb->transfer_buffer_length = peasycap->audio_isoc_buffer_size; purb->pipe = usb_rcvisocpipe(peasycap->pusb_device,
peasycap->audio_endpointnumber);
purb->transfer_flags = URB_ISO_ASAP;
purb->transfer_buffer = peasycap->audio_isoc_buffer[isbuf].pgo;
purb->transfer_buffer_length = peasycap->audio_isoc_buffer_size;
#ifdef CONFIG_EASYCAP_OSS #ifdef CONFIG_EASYCAP_OSS
purb->complete = easyoss_complete; purb->complete = easyoss_complete;
#else /* CONFIG_EASYCAP_OSS */ #else /* CONFIG_EASYCAP_OSS */
purb->complete = easycap_alsa_complete; purb->complete = easycap_alsa_complete;
#endif /* CONFIG_EASYCAP_OSS */ #endif /* CONFIG_EASYCAP_OSS */
purb->context = peasycap; purb->context = peasycap;
purb->start_frame = 0; purb->start_frame = 0;
purb->number_of_packets = peasycap->audio_isoc_framesperdesc; purb->number_of_packets = peasycap->audio_isoc_framesperdesc;
for (j = 0; j < peasycap->audio_isoc_framesperdesc; j++) { for (j = 0; j < peasycap->audio_isoc_framesperdesc; j++) {
purb->iso_frame_desc[j].offset = j * peasycap->audio_isoc_maxframesize; purb->iso_frame_desc[j].offset = j * peasycap->audio_isoc_maxframesize;
purb->iso_frame_desc[j].length = peasycap->audio_isoc_maxframesize; purb->iso_frame_desc[j].length = peasycap->audio_isoc_maxframesize;
} }
rc = usb_submit_urb(purb, GFP_KERNEL); rc = usb_submit_urb(purb, GFP_KERNEL);
if (rc) { if (rc) {
isbad++;
SAM("ERROR: usb_submit_urb() failed"
" for urb with rc: -%s: %d\n",
strerror(rc), rc);
} else {
m++;
}
} else {
isbad++;
}
} else {
isbad++; isbad++;
SAM("ERROR: usb_submit_urb() failed"
" for urb with rc: -%s: %d\n",
strerror(rc), rc);
} else {
m++;
} }
}
if (nospc) {
SAM("-ENOSPC=usb_submit_urb() for %i urbs\n", nospc);
SAM("..... possibly inadequate USB bandwidth\n");
peasycap->audio_eof = 1;
}
if (isbad) {
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);
}
}
peasycap->audio_isoc_streaming = 0;
} else { } else {
peasycap->audio_isoc_streaming = m; isbad++;
JOM(4, "submitted %i audio urbs\n", m);
} }
} else }
JOM(4, "already streaming audio urbs\n"); if (nospc) {
SAM("-ENOSPC=usb_submit_urb() for %i urbs\n", nospc);
SAM("..... possibly inadequate USB bandwidth\n");
peasycap->audio_eof = 1;
}
if (isbad) {
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 && 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);
}
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) {
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) {
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", JOM(8, "%i=audio_isoc_streaming, no audio urbs killed\n",
peasycap->audio_isoc_streaming); 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 && pdata_urb->purb) {
usb_kill_urb(pdata_urb->purb);
m++;
}
}
JOM(4, "%i audio urbs killed\n", m);
return 0; return 0;
} }
/*****************************************************************************/ /*****************************************************************************/
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册