diff options
Diffstat (limited to 'sound/core/pcm_memory.c')
-rw-r--r-- | sound/core/pcm_memory.c | 40 |
1 files changed, 33 insertions, 7 deletions
diff --git a/sound/core/pcm_memory.c b/sound/core/pcm_memory.c index ff07b4a9992..a6d42808828 100644 --- a/sound/core/pcm_memory.c +++ b/sound/core/pcm_memory.c | |||
@@ -50,8 +50,6 @@ static int preallocate_pcm_pages(struct snd_pcm_substream *substream, size_t siz | |||
50 | struct snd_dma_buffer *dmab = &substream->dma_buffer; | 50 | struct snd_dma_buffer *dmab = &substream->dma_buffer; |
51 | int err; | 51 | int err; |
52 | 52 | ||
53 | snd_assert(size > 0, return -EINVAL); | ||
54 | |||
55 | /* already reserved? */ | 53 | /* already reserved? */ |
56 | if (snd_dma_get_reserved_buf(dmab, substream->dma_buf_id) > 0) { | 54 | if (snd_dma_get_reserved_buf(dmab, substream->dma_buf_id) > 0) { |
57 | if (dmab->bytes >= size) | 55 | if (dmab->bytes >= size) |
@@ -326,6 +324,32 @@ struct page *snd_pcm_sgbuf_ops_page(struct snd_pcm_substream *substream, unsigne | |||
326 | 324 | ||
327 | EXPORT_SYMBOL(snd_pcm_sgbuf_ops_page); | 325 | EXPORT_SYMBOL(snd_pcm_sgbuf_ops_page); |
328 | 326 | ||
327 | /* | ||
328 | * compute the max chunk size with continuous pages on sg-buffer | ||
329 | */ | ||
330 | unsigned int snd_pcm_sgbuf_get_chunk_size(struct snd_pcm_substream *substream, | ||
331 | unsigned int ofs, unsigned int size) | ||
332 | { | ||
333 | struct snd_sg_buf *sg = snd_pcm_substream_sgbuf(substream); | ||
334 | unsigned int start, end, pg; | ||
335 | |||
336 | start = ofs >> PAGE_SHIFT; | ||
337 | end = (ofs + size - 1) >> PAGE_SHIFT; | ||
338 | /* check page continuity */ | ||
339 | pg = sg->table[start].addr >> PAGE_SHIFT; | ||
340 | for (;;) { | ||
341 | start++; | ||
342 | if (start > end) | ||
343 | break; | ||
344 | pg++; | ||
345 | if ((sg->table[start].addr >> PAGE_SHIFT) != pg) | ||
346 | return (start << PAGE_SHIFT) - ofs; | ||
347 | } | ||
348 | /* ok, all on continuous pages */ | ||
349 | return size; | ||
350 | } | ||
351 | EXPORT_SYMBOL(snd_pcm_sgbuf_get_chunk_size); | ||
352 | |||
329 | /** | 353 | /** |
330 | * snd_pcm_lib_malloc_pages - allocate the DMA buffer | 354 | * snd_pcm_lib_malloc_pages - allocate the DMA buffer |
331 | * @substream: the substream to allocate the DMA buffer to | 355 | * @substream: the substream to allocate the DMA buffer to |
@@ -342,10 +366,12 @@ int snd_pcm_lib_malloc_pages(struct snd_pcm_substream *substream, size_t size) | |||
342 | struct snd_pcm_runtime *runtime; | 366 | struct snd_pcm_runtime *runtime; |
343 | struct snd_dma_buffer *dmab = NULL; | 367 | struct snd_dma_buffer *dmab = NULL; |
344 | 368 | ||
345 | snd_assert(substream->dma_buffer.dev.type != SNDRV_DMA_TYPE_UNKNOWN, return -EINVAL); | 369 | if (PCM_RUNTIME_CHECK(substream)) |
346 | snd_assert(substream != NULL, return -EINVAL); | 370 | return -EINVAL; |
371 | if (snd_BUG_ON(substream->dma_buffer.dev.type == | ||
372 | SNDRV_DMA_TYPE_UNKNOWN)) | ||
373 | return -EINVAL; | ||
347 | runtime = substream->runtime; | 374 | runtime = substream->runtime; |
348 | snd_assert(runtime != NULL, return -EINVAL); | ||
349 | 375 | ||
350 | if (runtime->dma_buffer_p) { | 376 | if (runtime->dma_buffer_p) { |
351 | /* perphaps, we might free the large DMA memory region | 377 | /* perphaps, we might free the large DMA memory region |
@@ -391,9 +417,9 @@ int snd_pcm_lib_free_pages(struct snd_pcm_substream *substream) | |||
391 | { | 417 | { |
392 | struct snd_pcm_runtime *runtime; | 418 | struct snd_pcm_runtime *runtime; |
393 | 419 | ||
394 | snd_assert(substream != NULL, return -EINVAL); | 420 | if (PCM_RUNTIME_CHECK(substream)) |
421 | return -EINVAL; | ||
395 | runtime = substream->runtime; | 422 | runtime = substream->runtime; |
396 | snd_assert(runtime != NULL, return -EINVAL); | ||
397 | if (runtime->dma_area == NULL) | 423 | if (runtime->dma_area == NULL) |
398 | return 0; | 424 | return 0; |
399 | if (runtime->dma_buffer_p != &substream->dma_buffer) { | 425 | if (runtime->dma_buffer_p != &substream->dma_buffer) { |