Skip to content

Commit

Permalink
ALSA: sh: Convert to the new PCM ops
Browse files Browse the repository at this point in the history
Replace the copy and the silence ops with the new PCM ops.
Fixed also the user-space buffer copy with the proper
copy_from_user*() variant.

Reviewed-by: Takashi Sakamoto <[email protected]>
Signed-off-by: Takashi Iwai <[email protected]>
  • Loading branch information
tiwai committed Jun 2, 2017
1 parent 4b83eff commit 1cc2f8b
Showing 1 changed file with 30 additions and 24 deletions.
54 changes: 30 additions & 24 deletions sound/sh/sh_dac_audio.c
Original file line number Diff line number Diff line change
Expand Up @@ -184,23 +184,36 @@ static int snd_sh_dac_pcm_trigger(struct snd_pcm_substream *substream, int cmd)
return 0;
}

static int snd_sh_dac_pcm_copy(struct snd_pcm_substream *substream, int channel,
snd_pcm_uframes_t pos, void __user *src, snd_pcm_uframes_t count)
static int snd_sh_dac_pcm_copy(struct snd_pcm_substream *substream,
int channel, unsigned long pos,
void __user *src, unsigned long count)
{
/* channel is not used (interleaved data) */
struct snd_sh_dac *chip = snd_pcm_substream_chip(substream);
struct snd_pcm_runtime *runtime = substream->runtime;
ssize_t b_count = frames_to_bytes(runtime , count);
ssize_t b_pos = frames_to_bytes(runtime , pos);

if (count < 0)
return -EINVAL;
if (copy_from_user_toio(chip->data_buffer + pos, src, count))
return -EFAULT;
chip->buffer_end = chip->data_buffer + pos + count;

if (!count)
return 0;
if (chip->empty) {
chip->empty = 0;
dac_audio_start_timer(chip);
}

return 0;
}

memcpy_toio(chip->data_buffer + b_pos, src, b_count);
chip->buffer_end = chip->data_buffer + b_pos + b_count;
static int snd_sh_dac_pcm_copy_kernel(struct snd_pcm_substream *substream,
int channel, unsigned long pos,
void *src, unsigned long count)
{
/* channel is not used (interleaved data) */
struct snd_sh_dac *chip = snd_pcm_substream_chip(substream);
struct snd_pcm_runtime *runtime = substream->runtime;

memcpy_toio(chip->data_buffer + pos, src, count);
chip->buffer_end = chip->data_buffer + pos + count;

if (chip->empty) {
chip->empty = 0;
Expand All @@ -211,23 +224,15 @@ static int snd_sh_dac_pcm_copy(struct snd_pcm_substream *substream, int channel,
}

static int snd_sh_dac_pcm_silence(struct snd_pcm_substream *substream,
int channel, snd_pcm_uframes_t pos,
snd_pcm_uframes_t count)
int channel, unsigned long pos,
unsigned long count)
{
/* channel is not used (interleaved data) */
struct snd_sh_dac *chip = snd_pcm_substream_chip(substream);
struct snd_pcm_runtime *runtime = substream->runtime;
ssize_t b_count = frames_to_bytes(runtime , count);
ssize_t b_pos = frames_to_bytes(runtime , pos);

if (count < 0)
return -EINVAL;

if (!count)
return 0;

memset_io(chip->data_buffer + b_pos, 0, b_count);
chip->buffer_end = chip->data_buffer + b_pos + b_count;
memset_io(chip->data_buffer + pos, 0, count);
chip->buffer_end = chip->data_buffer + pos + count;

if (chip->empty) {
chip->empty = 0;
Expand Down Expand Up @@ -256,8 +261,9 @@ static struct snd_pcm_ops snd_sh_dac_pcm_ops = {
.prepare = snd_sh_dac_pcm_prepare,
.trigger = snd_sh_dac_pcm_trigger,
.pointer = snd_sh_dac_pcm_pointer,
.copy = snd_sh_dac_pcm_copy,
.silence = snd_sh_dac_pcm_silence,
.copy_user = snd_sh_dac_pcm_copy,
.copy_kernel = snd_sh_dac_pcm_copy_kernel,
.fill_silence = snd_sh_dac_pcm_silence,
.mmap = snd_pcm_lib_mmap_iomem,
};

Expand Down

0 comments on commit 1cc2f8b

Please sign in to comment.