/* the minimum size is snd_minimum_buffer. it should be power of 2.  */
static int preallocate_pcm_pages(struct snd_pcm_substream *substream, size_t size)
/* the minimum size is snd_minimum_buffer. it should be power of 2.  */
static int preallocate_pcm_pages(struct snd_pcm_substream *substream, size_t size)
{
	struct snd_dma_buffer *dmab = &substream->dma_buffer;
	int err;
	if (snd_dma_get_reserved_buf(dmab, substream->dma_buf_id) > 0) {
		if (dmab->bytes >= size)
			return 0;
		snd_dma_free_pages(dmab);
		dmab->bytes = 0;
	}
	do {
		if ((err = snd_dma_alloc_pages(dmab->dev.type, dmab->dev.dev,
					       size, dmab)) < 0) {
			if (err != -ENOMEM)
				return err;
		} else
			return 0;
		size >>= 1;
	} while (size >= snd_minimum_buffer);
	dmab->bytes = 0;
	return 0;
}