Skip to content

Commit

Permalink
sound: ua101: use vmalloc buffer helper functions
Browse files Browse the repository at this point in the history
Remove this duplicate of snd_pcm_alloc_vmalloc_buffer and use the
equivalent core functions instead.

Signed-off-by: Clemens Ladisch <clemens@ladisch.de>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
  • Loading branch information
cladisch authored and tiwai committed Dec 18, 2009
1 parent c55675e commit 5b4b2a4
Showing 1 changed file with 7 additions and 45 deletions.
52 changes: 7 additions & 45 deletions sound/usb/ua101.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
#include <linux/slab.h>
#include <linux/usb.h>
#include <linux/usb/audio.h>
#include <linux/vmalloc.h>
#include <sound/core.h>
#include <sound/initval.h>
#include <sound/pcm.h>
Expand Down Expand Up @@ -145,42 +144,6 @@ static struct usb_driver ua101_driver;
static void abort_alsa_playback(struct ua101 *ua);
static void abort_alsa_capture(struct ua101 *ua);

/* allocate virtual buffer; may be called more than once */
static int snd_pcm_alloc_vmalloc_buffer(struct snd_pcm_substream *subs,
size_t size)
{
struct snd_pcm_runtime *runtime = subs->runtime;

if (runtime->dma_area) {
if (runtime->dma_bytes >= size)
return 0; /* already large enough */
vfree(runtime->dma_area);
}
runtime->dma_area = vmalloc_user(size);
if (!runtime->dma_area)
return -ENOMEM;
runtime->dma_bytes = size;
return 0;
}

/* free virtual buffer; may be called more than once */
static int snd_pcm_free_vmalloc_buffer(struct snd_pcm_substream *subs)
{
struct snd_pcm_runtime *runtime = subs->runtime;

vfree(runtime->dma_area);
runtime->dma_area = NULL;
return 0;
}

/* get the physical page pointer at the given offset */
static struct page *snd_pcm_get_vmalloc_page(struct snd_pcm_substream *subs,
unsigned long offset)
{
void *pageptr = subs->runtime->dma_area + offset;
return vmalloc_to_page(pageptr);
}

static const char *usb_error_string(int err)
{
switch (err) {
Expand Down Expand Up @@ -791,8 +754,8 @@ static int capture_pcm_hw_params(struct snd_pcm_substream *substream,
if (err < 0)
return err;

return snd_pcm_alloc_vmalloc_buffer(substream,
params_buffer_bytes(hw_params));
return snd_pcm_lib_alloc_vmalloc_buffer(substream,
params_buffer_bytes(hw_params));
}

static int playback_pcm_hw_params(struct snd_pcm_substream *substream,
Expand All @@ -809,14 +772,13 @@ static int playback_pcm_hw_params(struct snd_pcm_substream *substream,
if (err < 0)
return err;

return snd_pcm_alloc_vmalloc_buffer(substream,
params_buffer_bytes(hw_params));
return snd_pcm_lib_alloc_vmalloc_buffer(substream,
params_buffer_bytes(hw_params));
}

static int ua101_pcm_hw_free(struct snd_pcm_substream *substream)
{
snd_pcm_free_vmalloc_buffer(substream);
return 0;
return snd_pcm_lib_free_vmalloc_buffer(substream);
}

static int capture_pcm_prepare(struct snd_pcm_substream *substream)
Expand Down Expand Up @@ -948,7 +910,7 @@ static struct snd_pcm_ops capture_pcm_ops = {
.prepare = capture_pcm_prepare,
.trigger = capture_pcm_trigger,
.pointer = capture_pcm_pointer,
.page = snd_pcm_get_vmalloc_page,
.page = snd_pcm_lib_get_vmalloc_page,
};

static struct snd_pcm_ops playback_pcm_ops = {
Expand All @@ -960,7 +922,7 @@ static struct snd_pcm_ops playback_pcm_ops = {
.prepare = playback_pcm_prepare,
.trigger = playback_pcm_trigger,
.pointer = playback_pcm_pointer,
.page = snd_pcm_get_vmalloc_page,
.page = snd_pcm_lib_get_vmalloc_page,
};

static const struct uac_format_type_i_discrete_descriptor *
Expand Down

0 comments on commit 5b4b2a4

Please sign in to comment.