hc
2023-12-11 d2ccde1c8e90d38cee87a1b0309ad2827f3fd30d
kernel/drivers/media/usb/em28xx/em28xx-audio.c
....@@ -30,8 +30,6 @@
3030 #include <linux/spinlock.h>
3131 #include <linux/soundcard.h>
3232 #include <linux/slab.h>
33
-#include <linux/vmalloc.h>
34
-#include <linux/proc_fs.h>
3533 #include <linux/module.h>
3634 #include <sound/core.h>
3735 #include <sound/pcm.h>
....@@ -116,6 +114,7 @@
116114 stride = runtime->frame_bits >> 3;
117115
118116 for (i = 0; i < urb->number_of_packets; i++) {
117
+ unsigned long flags;
119118 int length =
120119 urb->iso_frame_desc[i].actual_length / stride;
121120 cp = (unsigned char *)urb->transfer_buffer +
....@@ -137,7 +136,7 @@
137136 length * stride);
138137 }
139138
140
- snd_pcm_stream_lock(substream);
139
+ snd_pcm_stream_lock_irqsave(substream, flags);
141140
142141 dev->adev.hwptr_done_capture += length;
143142 if (dev->adev.hwptr_done_capture >=
....@@ -153,7 +152,7 @@
153152 period_elapsed = 1;
154153 }
155154
156
- snd_pcm_stream_unlock(substream);
155
+ snd_pcm_stream_unlock_irqrestore(substream, flags);
157156 }
158157 if (period_elapsed)
159158 snd_pcm_period_elapsed(substream);
....@@ -188,28 +187,6 @@
188187 return err;
189188 }
190189 }
191
-
192
- return 0;
193
-}
194
-
195
-static int snd_pcm_alloc_vmalloc_buffer(struct snd_pcm_substream *subs,
196
- size_t size)
197
-{
198
- struct em28xx *dev = snd_pcm_substream_chip(subs);
199
- struct snd_pcm_runtime *runtime = subs->runtime;
200
-
201
- dprintk("Allocating vbuffer\n");
202
- if (runtime->dma_area) {
203
- if (runtime->dma_bytes > size)
204
- return 0;
205
-
206
- vfree(runtime->dma_area);
207
- }
208
- runtime->dma_area = vmalloc(size);
209
- if (!runtime->dma_area)
210
- return -ENOMEM;
211
-
212
- runtime->dma_bytes = size;
213190
214191 return 0;
215192 }
....@@ -341,59 +318,8 @@
341318 }
342319
343320 em28xx_audio_analog_set(dev);
344
- if (substream->runtime->dma_area) {
345
- dprintk("freeing\n");
346
- vfree(substream->runtime->dma_area);
347
- substream->runtime->dma_area = NULL;
348
- }
349321 mutex_unlock(&dev->lock);
350322 kref_put(&dev->ref, em28xx_free_device);
351
-
352
- return 0;
353
-}
354
-
355
-static int snd_em28xx_hw_capture_params(struct snd_pcm_substream *substream,
356
- struct snd_pcm_hw_params *hw_params)
357
-{
358
- int ret;
359
- struct em28xx *dev = snd_pcm_substream_chip(substream);
360
-
361
- if (dev->disconnected)
362
- return -ENODEV;
363
-
364
- dprintk("Setting capture parameters\n");
365
-
366
- ret = snd_pcm_alloc_vmalloc_buffer(substream,
367
- params_buffer_bytes(hw_params));
368
- if (ret < 0)
369
- return ret;
370
-#if 0
371
- /*
372
- * TODO: set up em28xx audio chip to deliver the correct audio format,
373
- * current default is 48000hz multiplexed => 96000hz mono
374
- * which shouldn't matter since analogue TV only supports mono
375
- */
376
- unsigned int channels, rate, format;
377
-
378
- format = params_format(hw_params);
379
- rate = params_rate(hw_params);
380
- channels = params_channels(hw_params);
381
-#endif
382
-
383
- return 0;
384
-}
385
-
386
-static int snd_em28xx_hw_capture_free(struct snd_pcm_substream *substream)
387
-{
388
- struct em28xx *dev = snd_pcm_substream_chip(substream);
389
- struct em28xx_audio *adev = &dev->adev;
390
-
391
- dprintk("Stop capture, if needed\n");
392
-
393
- if (atomic_read(&adev->stream_started) > 0) {
394
- atomic_set(&adev->stream_started, 0);
395
- schedule_work(&adev->wq_trigger);
396
- }
397323
398324 return 0;
399325 }
....@@ -436,13 +362,13 @@
436362 return -ENODEV;
437363
438364 switch (cmd) {
439
- case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: /* fall through */
440
- case SNDRV_PCM_TRIGGER_RESUME: /* fall through */
365
+ case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
366
+ case SNDRV_PCM_TRIGGER_RESUME:
441367 case SNDRV_PCM_TRIGGER_START:
442368 atomic_set(&dev->adev.stream_started, 1);
443369 break;
444
- case SNDRV_PCM_TRIGGER_PAUSE_PUSH: /* fall through */
445
- case SNDRV_PCM_TRIGGER_SUSPEND: /* fall through */
370
+ case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
371
+ case SNDRV_PCM_TRIGGER_SUSPEND:
446372 case SNDRV_PCM_TRIGGER_STOP:
447373 atomic_set(&dev->adev.stream_started, 0);
448374 break;
....@@ -469,14 +395,6 @@
469395 spin_unlock_irqrestore(&dev->adev.slock, flags);
470396
471397 return hwptr_done;
472
-}
473
-
474
-static struct page *snd_pcm_get_vmalloc_page(struct snd_pcm_substream *subs,
475
- unsigned long offset)
476
-{
477
- void *pageptr = subs->runtime->dma_area + offset;
478
-
479
- return vmalloc_to_page(pageptr);
480398 }
481399
482400 /*
....@@ -708,13 +626,9 @@
708626 static const struct snd_pcm_ops snd_em28xx_pcm_capture = {
709627 .open = snd_em28xx_capture_open,
710628 .close = snd_em28xx_pcm_close,
711
- .ioctl = snd_pcm_lib_ioctl,
712
- .hw_params = snd_em28xx_hw_capture_params,
713
- .hw_free = snd_em28xx_hw_capture_free,
714629 .prepare = snd_em28xx_prepare,
715630 .trigger = snd_em28xx_capture_trigger,
716631 .pointer = snd_em28xx_capture_pointer,
717
- .page = snd_pcm_get_vmalloc_page,
718632 };
719633
720634 static void em28xx_audio_free_urb(struct em28xx *dev)
....@@ -842,11 +756,11 @@
842756
843757 dev->adev.transfer_buffer = kcalloc(num_urb,
844758 sizeof(*dev->adev.transfer_buffer),
845
- GFP_ATOMIC);
759
+ GFP_KERNEL);
846760 if (!dev->adev.transfer_buffer)
847761 return -ENOMEM;
848762
849
- dev->adev.urb = kcalloc(num_urb, sizeof(*dev->adev.urb), GFP_ATOMIC);
763
+ dev->adev.urb = kcalloc(num_urb, sizeof(*dev->adev.urb), GFP_KERNEL);
850764 if (!dev->adev.urb) {
851765 kfree(dev->adev.transfer_buffer);
852766 return -ENOMEM;
....@@ -859,14 +773,14 @@
859773 int j, k;
860774 void *buf;
861775
862
- urb = usb_alloc_urb(npackets, GFP_ATOMIC);
776
+ urb = usb_alloc_urb(npackets, GFP_KERNEL);
863777 if (!urb) {
864778 em28xx_audio_free_urb(dev);
865779 return -ENOMEM;
866780 }
867781 dev->adev.urb[i] = urb;
868782
869
- buf = usb_alloc_coherent(udev, npackets * ep_size, GFP_ATOMIC,
783
+ buf = usb_alloc_coherent(udev, npackets * ep_size, GFP_KERNEL,
870784 &urb->transfer_dma);
871785 if (!buf) {
872786 dev_err(&dev->intf->dev,
....@@ -936,13 +850,14 @@
936850 goto card_free;
937851
938852 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_em28xx_pcm_capture);
853
+ snd_pcm_set_managed_buffer_all(pcm, SNDRV_DMA_TYPE_VMALLOC, NULL, 0, 0);
939854 pcm->info_flags = 0;
940855 pcm->private_data = dev;
941
- strcpy(pcm->name, "Empia 28xx Capture");
856
+ strscpy(pcm->name, "Empia 28xx Capture", sizeof(pcm->name));
942857
943
- strcpy(card->driver, "Em28xx-Audio");
944
- strcpy(card->shortname, "Em28xx Audio");
945
- strcpy(card->longname, "Empia Em28xx Audio");
858
+ strscpy(card->driver, "Em28xx-Audio", sizeof(card->driver));
859
+ strscpy(card->shortname, "Em28xx Audio", sizeof(card->shortname));
860
+ strscpy(card->longname, "Empia Em28xx Audio", sizeof(card->longname));
946861
947862 INIT_WORK(&adev->wq_trigger, audio_trigger);
948863