diff options
author | Tomas Winkler <tomas.winkler@intel.com> | 2011-03-06 03:59:03 -0500 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@suse.de> | 2011-03-07 16:52:57 -0500 |
commit | 5917def58ab9f5848f2d1da835a33a490d0c8c69 (patch) | |
tree | b1ebd52a24a1af94a7b70613933269dc02d54123 /drivers/staging/easycap | |
parent | 07ba111f0d5127d4c830799605e2cd0922611bf5 (diff) |
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: Tomas Winkler <tomas.winkler@intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Diffstat (limited to 'drivers/staging/easycap')
-rw-r--r-- | drivers/staging/easycap/easycap_sound.c | 418 |
1 files changed, 205 insertions, 213 deletions
diff --git a/drivers/staging/easycap/easycap_sound.c b/drivers/staging/easycap/easycap_sound.c index 5829e26969d..a3402b00a8b 100644 --- a/drivers/staging/easycap/easycap_sound.c +++ b/drivers/staging/easycap/easycap_sound.c | |||
@@ -142,122 +142,118 @@ easycap_alsa_complete(struct urb *purb) | |||
142 | strerror(purb->iso_frame_desc[i].status), | 142 | strerror(purb->iso_frame_desc[i].status), |
143 | purb->iso_frame_desc[i].status); | 143 | purb->iso_frame_desc[i].status); |
144 | } | 144 | } |
145 | if (!purb->iso_frame_desc[i].status) { | 145 | if (purb->iso_frame_desc[i].status) { |
146 | more = purb->iso_frame_desc[i].actual_length; | 146 | JOM(12, "discarding audio samples because " |
147 | if (!more) | 147 | "%i=purb->iso_frame_desc[i].status\n", |
148 | peasycap->audio_mt++; | 148 | purb->iso_frame_desc[i].status); |
149 | else { | 149 | continue; |
150 | if (peasycap->audio_mt) { | 150 | } |
151 | JOM(12, "%4i empty audio urb frames\n", | 151 | more = purb->iso_frame_desc[i].actual_length; |
152 | peasycap->audio_mt); | 152 | if (more == 0) { |
153 | peasycap->audio_mt = 0; | 153 | peasycap->audio_mt++; |
154 | } | 154 | continue; |
155 | } | ||
156 | if (0 > more) { | ||
157 | SAM("MISTAKE: more is negative\n"); | ||
158 | return; | ||
159 | } | ||
155 | 160 | ||
156 | p1 = (u8 *)(purb->transfer_buffer + | 161 | if (peasycap->audio_mt) { |
157 | purb->iso_frame_desc[i].offset); | 162 | JOM(12, "%4i empty audio urb frames\n", |
158 | 163 | peasycap->audio_mt); | |
159 | /* | 164 | peasycap->audio_mt = 0; |
160 | * COPY more BYTES FROM ISOC BUFFER | 165 | } |
161 | * TO THE DMA BUFFER, CONVERTING | 166 | |
162 | * 8-BIT MONO TO 16-BIT SIGNED | 167 | p1 = (u8 *)(purb->transfer_buffer + |
163 | * LITTLE-ENDIAN SAMPLES IF NECESSARY | 168 | purb->iso_frame_desc[i].offset); |
164 | */ | 169 | |
165 | while (more) { | 170 | /* |
166 | if (0 > more) { | 171 | * COPY more BYTES FROM ISOC BUFFER |
167 | SAM("MISTAKE: more is negative\n"); | 172 | * TO THE DMA BUFFER, CONVERTING |
168 | return; | 173 | * 8-BIT MONO TO 16-BIT SIGNED |
169 | } | 174 | * LITTLE-ENDIAN SAMPLES IF NECESSARY |
170 | much = dma_bytes - peasycap->dma_fill; | 175 | */ |
171 | if (0 > much) { | 176 | while (more) { |
172 | SAM("MISTAKE: much is negative\n"); | 177 | much = dma_bytes - peasycap->dma_fill; |
173 | return; | 178 | if (0 > much) { |
174 | } | 179 | SAM("MISTAKE: much is negative\n"); |
175 | if (0 == much) { | 180 | return; |
176 | peasycap->dma_fill = 0; | 181 | } |
177 | peasycap->dma_next = fragment_bytes; | 182 | if (0 == much) { |
178 | JOM(8, "wrapped dma buffer\n"); | 183 | peasycap->dma_fill = 0; |
179 | } | 184 | peasycap->dma_next = fragment_bytes; |
180 | if (!peasycap->microphone) { | 185 | JOM(8, "wrapped dma buffer\n"); |
181 | if (much > more) | 186 | } |
182 | much = more; | 187 | if (!peasycap->microphone) { |
183 | memcpy(prt->dma_area + | 188 | if (much > more) |
184 | peasycap->dma_fill, | 189 | much = more; |
185 | p1, much); | 190 | memcpy(prt->dma_area + peasycap->dma_fill, |
186 | p1 += much; | 191 | p1, much); |
187 | more -= much; | 192 | p1 += much; |
188 | } else { | 193 | more -= much; |
194 | } else { | ||
189 | #ifdef UPSAMPLE | 195 | #ifdef UPSAMPLE |
190 | if (much % 16) | 196 | if (much % 16) |
191 | JOM(8, "MISTAKE? much" | 197 | JOM(8, "MISTAKE? much" |
192 | " is not divisible by 16\n"); | 198 | " is not divisible by 16\n"); |
193 | if (much > (16 * more)) | 199 | if (much > (16 * more)) |
194 | much = 16 * | 200 | much = 16 * more; |
195 | more; | 201 | p2 = (u8 *)(prt->dma_area + peasycap->dma_fill); |
196 | p2 = (u8 *)(prt->dma_area + peasycap->dma_fill); | 202 | |
197 | 203 | for (j = 0; j < (much / 16); j++) { | |
198 | for (j = 0; j < (much/16); j++) { | 204 | newaudio = ((int) *p1) - 128; |
199 | newaudio = ((int) *p1) - 128; | 205 | newaudio = 128 * newaudio; |
200 | newaudio = 128 * newaudio; | 206 | |
201 | 207 | delta = (newaudio - oldaudio) / 4; | |
202 | delta = (newaudio - oldaudio) / 4; | 208 | tmp = oldaudio + delta; |
203 | tmp = oldaudio + delta; | 209 | |
204 | 210 | for (k = 0; k < 4; k++) { | |
205 | for (k = 0; k < 4; k++) { | 211 | *p2 = (0x00FF & tmp); |
206 | *p2 = (0x00FF & tmp); | 212 | *(p2 + 1) = (0xFF00 & tmp) >> 8; |
207 | *(p2 + 1) = (0xFF00 & tmp) >> 8; | 213 | p2 += 2; |
208 | p2 += 2; | 214 | *p2 = (0x00FF & tmp); |
209 | *p2 = (0x00FF & tmp); | 215 | *(p2 + 1) = (0xFF00 & tmp) >> 8; |
210 | *(p2 + 1) = (0xFF00 & tmp) >> 8; | 216 | p2 += 2; |
211 | p2 += 2; | 217 | tmp += delta; |
212 | tmp += delta; | 218 | } |
213 | } | 219 | p1++; |
214 | p1++; | 220 | more--; |
215 | more--; | 221 | oldaudio = tmp; |
216 | oldaudio = tmp; | 222 | } |
217 | } | ||
218 | #else /*!UPSAMPLE*/ | 223 | #else /*!UPSAMPLE*/ |
219 | if (much > (2 * more)) | 224 | if (much > (2 * more)) |
220 | much = 2 * more; | 225 | much = 2 * more; |
221 | p2 = (u8 *)(prt->dma_area + peasycap->dma_fill); | 226 | p2 = (u8 *)(prt->dma_area + peasycap->dma_fill); |
222 | 227 | ||
223 | for (j = 0; j < (much / 2); j++) { | 228 | for (j = 0; j < (much / 2); j++) { |
224 | tmp = ((int) *p1) - 128; | 229 | tmp = ((int) *p1) - 128; |
225 | tmp = 128 * tmp; | 230 | tmp = 128 * tmp; |
226 | *p2 = (0x00FF & tmp); | 231 | *p2 = (0x00FF & tmp); |
227 | *(p2 + 1) = (0xFF00 & tmp) >> 8; | 232 | *(p2 + 1) = (0xFF00 & tmp) >> 8; |
228 | p1++; | 233 | p1++; |
229 | p2 += 2; | 234 | p2 += 2; |
230 | more--; | 235 | more--; |
231 | } | 236 | } |
232 | #endif /*UPSAMPLE*/ | 237 | #endif /*UPSAMPLE*/ |
233 | } | 238 | } |
234 | peasycap->dma_fill += much; | 239 | peasycap->dma_fill += much; |
235 | if (peasycap->dma_fill >= peasycap->dma_next) { | 240 | if (peasycap->dma_fill >= peasycap->dma_next) { |
236 | isfragment = peasycap->dma_fill / fragment_bytes; | 241 | isfragment = peasycap->dma_fill / fragment_bytes; |
237 | if (0 > isfragment) { | 242 | if (0 > isfragment) { |
238 | SAM("MISTAKE: isfragment is " | 243 | SAM("MISTAKE: isfragment is negative\n"); |
239 | "negative\n"); | 244 | return; |
240 | return; | 245 | } |
241 | } | 246 | peasycap->dma_read = (isfragment - 1) * fragment_bytes; |
242 | peasycap->dma_read = (isfragment - 1) * fragment_bytes; | 247 | peasycap->dma_next = (isfragment + 1) * fragment_bytes; |
243 | peasycap->dma_next = (isfragment + 1) * fragment_bytes; | 248 | if (dma_bytes < peasycap->dma_next) |
244 | if (dma_bytes < peasycap->dma_next) | 249 | peasycap->dma_next = fragment_bytes; |
245 | peasycap->dma_next = fragment_bytes; | 250 | |
246 | 251 | if (0 <= peasycap->dma_read) { | |
247 | if (0 <= peasycap->dma_read) { | 252 | JOM(8, "snd_pcm_period_elapsed(), %i=" |
248 | JOM(8, "snd_pcm_period_elap" | 253 | "isfragment\n", isfragment); |
249 | "sed(), %i=" | 254 | snd_pcm_period_elapsed(pss); |
250 | "isfragment\n", | ||
251 | isfragment); | ||
252 | snd_pcm_period_elapsed(pss); | ||
253 | } | ||
254 | } | ||
255 | } | 255 | } |
256 | } | 256 | } |
257 | } else { | ||
258 | JOM(12, "discarding audio samples because " | ||
259 | "%i=purb->iso_frame_desc[i].status\n", | ||
260 | purb->iso_frame_desc[i].status); | ||
261 | } | 257 | } |
262 | 258 | ||
263 | #ifdef UPSAMPLE | 259 | #ifdef UPSAMPLE |
@@ -271,18 +267,18 @@ easycap_alsa_complete(struct urb *purb) | |||
271 | */ | 267 | */ |
272 | /*---------------------------------------------------------------------------*/ | 268 | /*---------------------------------------------------------------------------*/ |
273 | resubmit: | 269 | resubmit: |
274 | if (peasycap->audio_isoc_streaming) { | 270 | if (peasycap->audio_isoc_streaming == 0) |
275 | rc = usb_submit_urb(purb, GFP_ATOMIC); | 271 | return; |
276 | if (rc) { | 272 | |
277 | if ((-ENODEV != rc) && (-ENOENT != rc)) { | 273 | rc = usb_submit_urb(purb, GFP_ATOMIC); |
278 | SAM("ERROR: while %i=audio_idle, " | 274 | if (rc) { |
279 | "usb_submit_urb() failed " | 275 | if ((-ENODEV != rc) && (-ENOENT != rc)) { |
280 | "with rc: -%s :%d\n", peasycap->audio_idle, | 276 | SAM("ERROR: while %i=audio_idle, usb_submit_urb failed " |
281 | strerror(rc), rc); | 277 | "with rc: -%s :%d\n", |
282 | } | 278 | peasycap->audio_idle, strerror(rc), rc); |
283 | if (0 < peasycap->audio_isoc_streaming) | ||
284 | (peasycap->audio_isoc_streaming)--; | ||
285 | } | 279 | } |
280 | if (0 < peasycap->audio_isoc_streaming) | ||
281 | peasycap->audio_isoc_streaming--; | ||
286 | } | 282 | } |
287 | return; | 283 | return; |
288 | } | 284 | } |
@@ -643,10 +639,9 @@ int easycap_alsa_probe(struct easycap *peasycap) | |||
643 | SAM("ERROR: Cannot do ALSA snd_card_register()\n"); | 639 | SAM("ERROR: Cannot do ALSA snd_card_register()\n"); |
644 | snd_card_free(psnd_card); | 640 | snd_card_free(psnd_card); |
645 | return -EFAULT; | 641 | return -EFAULT; |
646 | } else { | ||
647 | ; | ||
648 | SAM("registered %s\n", &psnd_card->id[0]); | ||
649 | } | 642 | } |
643 | |||
644 | SAM("registered %s\n", &psnd_card->id[0]); | ||
650 | return 0; | 645 | return 0; |
651 | } | 646 | } |
652 | #endif /*! CONFIG_EASYCAP_OSS */ | 647 | #endif /*! CONFIG_EASYCAP_OSS */ |
@@ -737,83 +732,79 @@ submit_audio_urbs(struct easycap *peasycap) | |||
737 | SAM("ERROR: peasycap->pusb_device is NULL\n"); | 732 | SAM("ERROR: peasycap->pusb_device is NULL\n"); |
738 | return -EFAULT; | 733 | return -EFAULT; |
739 | } | 734 | } |
740 | if (!peasycap->audio_isoc_streaming) { | 735 | |
741 | JOM(4, "initial submission of all audio urbs\n"); | 736 | if (peasycap->audio_isoc_streaming) { |
742 | rc = usb_set_interface(peasycap->pusb_device, | 737 | JOM(4, "already streaming audio urbs\n"); |
743 | peasycap->audio_interface, | 738 | return 0; |
744 | peasycap->audio_altsetting_on); | 739 | } |
745 | JOM(8, "usb_set_interface(.,%i,%i) returned %i\n", | 740 | |
746 | peasycap->audio_interface, | 741 | JOM(4, "initial submission of all audio urbs\n"); |
747 | peasycap->audio_altsetting_on, rc); | 742 | rc = usb_set_interface(peasycap->pusb_device, |
748 | 743 | peasycap->audio_interface, | |
749 | isbad = 0; | 744 | peasycap->audio_altsetting_on); |
750 | nospc = 0; | 745 | JOM(8, "usb_set_interface(.,%i,%i) returned %i\n", |
751 | m = 0; | 746 | peasycap->audio_interface, |
752 | list_for_each(plist_head, (peasycap->purb_audio_head)) { | 747 | peasycap->audio_altsetting_on, rc); |
753 | pdata_urb = list_entry(plist_head, struct data_urb, list_head); | 748 | |
754 | if (pdata_urb) { | 749 | isbad = 0; |
755 | purb = pdata_urb->purb; | 750 | nospc = 0; |
756 | if (purb) { | 751 | m = 0; |
757 | isbuf = pdata_urb->isbuf; | 752 | list_for_each(plist_head, peasycap->purb_audio_head) { |
758 | 753 | pdata_urb = list_entry(plist_head, struct data_urb, list_head); | |
759 | purb->interval = 1; | 754 | if (pdata_urb && pdata_urb->purb) { |
760 | purb->dev = peasycap->pusb_device; | 755 | purb = pdata_urb->purb; |
761 | purb->pipe = usb_rcvisocpipe(peasycap->pusb_device, | 756 | isbuf = pdata_urb->isbuf; |
762 | peasycap->audio_endpointnumber); | 757 | |
763 | purb->transfer_flags = URB_ISO_ASAP; | 758 | purb->interval = 1; |
764 | purb->transfer_buffer = peasycap->audio_isoc_buffer[isbuf].pgo; | 759 | purb->dev = peasycap->pusb_device; |
765 | purb->transfer_buffer_length = peasycap->audio_isoc_buffer_size; | 760 | purb->pipe = usb_rcvisocpipe(peasycap->pusb_device, |
761 | peasycap->audio_endpointnumber); | ||
762 | purb->transfer_flags = URB_ISO_ASAP; | ||
763 | purb->transfer_buffer = peasycap->audio_isoc_buffer[isbuf].pgo; | ||
764 | purb->transfer_buffer_length = peasycap->audio_isoc_buffer_size; | ||
766 | #ifdef CONFIG_EASYCAP_OSS | 765 | #ifdef CONFIG_EASYCAP_OSS |
767 | purb->complete = easyoss_complete; | 766 | purb->complete = easyoss_complete; |
768 | #else /* CONFIG_EASYCAP_OSS */ | 767 | #else /* CONFIG_EASYCAP_OSS */ |
769 | purb->complete = easycap_alsa_complete; | 768 | purb->complete = easycap_alsa_complete; |
770 | #endif /* CONFIG_EASYCAP_OSS */ | 769 | #endif /* CONFIG_EASYCAP_OSS */ |
771 | purb->context = peasycap; | 770 | purb->context = peasycap; |
772 | purb->start_frame = 0; | 771 | purb->start_frame = 0; |
773 | purb->number_of_packets = peasycap->audio_isoc_framesperdesc; | 772 | purb->number_of_packets = peasycap->audio_isoc_framesperdesc; |
774 | for (j = 0; j < peasycap->audio_isoc_framesperdesc; j++) { | 773 | for (j = 0; j < peasycap->audio_isoc_framesperdesc; j++) { |
775 | purb->iso_frame_desc[j].offset = j * peasycap->audio_isoc_maxframesize; | 774 | purb->iso_frame_desc[j].offset = j * peasycap->audio_isoc_maxframesize; |
776 | purb->iso_frame_desc[j].length = peasycap->audio_isoc_maxframesize; | 775 | purb->iso_frame_desc[j].length = peasycap->audio_isoc_maxframesize; |
777 | } | 776 | } |
778 | 777 | ||
779 | rc = usb_submit_urb(purb, GFP_KERNEL); | 778 | rc = usb_submit_urb(purb, GFP_KERNEL); |
780 | if (rc) { | 779 | if (rc) { |
781 | isbad++; | ||
782 | SAM("ERROR: usb_submit_urb() failed" | ||
783 | " for urb with rc: -%s: %d\n", | ||
784 | strerror(rc), rc); | ||
785 | } else { | ||
786 | m++; | ||
787 | } | ||
788 | } else { | ||
789 | isbad++; | ||
790 | } | ||
791 | } else { | ||
792 | isbad++; | 780 | isbad++; |
781 | SAM("ERROR: usb_submit_urb() failed" | ||
782 | " for urb with rc: -%s: %d\n", | ||
783 | strerror(rc), rc); | ||
784 | } else { | ||
785 | m++; | ||
793 | } | 786 | } |
794 | } | ||
795 | if (nospc) { | ||
796 | SAM("-ENOSPC=usb_submit_urb() for %i urbs\n", nospc); | ||
797 | SAM("..... possibly inadequate USB bandwidth\n"); | ||
798 | peasycap->audio_eof = 1; | ||
799 | } | ||
800 | if (isbad) { | ||
801 | JOM(4, "attempting cleanup instead of submitting\n"); | ||
802 | list_for_each(plist_head, (peasycap->purb_audio_head)) { | ||
803 | pdata_urb = list_entry(plist_head, struct data_urb, list_head); | ||
804 | if (pdata_urb) { | ||
805 | purb = pdata_urb->purb; | ||
806 | if (purb) | ||
807 | usb_kill_urb(purb); | ||
808 | } | ||
809 | } | ||
810 | peasycap->audio_isoc_streaming = 0; | ||
811 | } else { | 787 | } else { |
812 | peasycap->audio_isoc_streaming = m; | 788 | isbad++; |
813 | JOM(4, "submitted %i audio urbs\n", m); | ||
814 | } | 789 | } |
815 | } else | 790 | } |
816 | JOM(4, "already streaming audio urbs\n"); | 791 | if (nospc) { |
792 | SAM("-ENOSPC=usb_submit_urb() for %i urbs\n", nospc); | ||
793 | SAM("..... possibly inadequate USB bandwidth\n"); | ||
794 | peasycap->audio_eof = 1; | ||
795 | } | ||
796 | if (isbad) { | ||
797 | JOM(4, "attempting cleanup instead of submitting\n"); | ||
798 | list_for_each(plist_head, (peasycap->purb_audio_head)) { | ||
799 | pdata_urb = list_entry(plist_head, struct data_urb, list_head); | ||
800 | if (pdata_urb && pdata_urb->purb) | ||
801 | usb_kill_urb(pdata_urb->purb); | ||
802 | } | ||
803 | peasycap->audio_isoc_streaming = 0; | ||
804 | } else { | ||
805 | peasycap->audio_isoc_streaming = m; | ||
806 | JOM(4, "submitted %i audio urbs\n", m); | ||
807 | } | ||
817 | 808 | ||
818 | return 0; | 809 | return 0; |
819 | } | 810 | } |
@@ -834,29 +825,30 @@ kill_audio_urbs(struct easycap *peasycap) | |||
834 | SAY("ERROR: peasycap is NULL\n"); | 825 | SAY("ERROR: peasycap is NULL\n"); |
835 | return -EFAULT; | 826 | return -EFAULT; |
836 | } | 827 | } |
837 | if (peasycap->audio_isoc_streaming) { | 828 | |
838 | if (peasycap->purb_audio_head) { | 829 | if (!peasycap->audio_isoc_streaming) { |
839 | peasycap->audio_isoc_streaming = 0; | ||
840 | JOM(4, "killing audio urbs\n"); | ||
841 | m = 0; | ||
842 | list_for_each(plist_head, (peasycap->purb_audio_head)) { | ||
843 | pdata_urb = list_entry(plist_head, struct data_urb, list_head); | ||
844 | if (pdata_urb) { | ||
845 | if (pdata_urb->purb) { | ||
846 | usb_kill_urb(pdata_urb->purb); | ||
847 | m++; | ||
848 | } | ||
849 | } | ||
850 | } | ||
851 | JOM(4, "%i audio urbs killed\n", m); | ||
852 | } else { | ||
853 | SAM("ERROR: peasycap->purb_audio_head is NULL\n"); | ||
854 | return -EFAULT; | ||
855 | } | ||
856 | } else { | ||
857 | JOM(8, "%i=audio_isoc_streaming, no audio urbs killed\n", | 830 | JOM(8, "%i=audio_isoc_streaming, no audio urbs killed\n", |
858 | peasycap->audio_isoc_streaming); | 831 | peasycap->audio_isoc_streaming); |
832 | return 0; | ||
833 | } | ||
834 | |||
835 | if (!peasycap->purb_audio_head) { | ||
836 | SAM("ERROR: peasycap->purb_audio_head is NULL\n"); | ||
837 | return -EFAULT; | ||
859 | } | 838 | } |
839 | |||
840 | peasycap->audio_isoc_streaming = 0; | ||
841 | JOM(4, "killing audio urbs\n"); | ||
842 | m = 0; | ||
843 | list_for_each(plist_head, (peasycap->purb_audio_head)) { | ||
844 | pdata_urb = list_entry(plist_head, struct data_urb, list_head); | ||
845 | if (pdata_urb && pdata_urb->purb) { | ||
846 | usb_kill_urb(pdata_urb->purb); | ||
847 | m++; | ||
848 | } | ||
849 | } | ||
850 | JOM(4, "%i audio urbs killed\n", m); | ||
851 | |||
860 | return 0; | 852 | return 0; |
861 | } | 853 | } |
862 | /*****************************************************************************/ | 854 | /*****************************************************************************/ |