diff options
Diffstat (limited to 'sound/pci/rme9652/hdspm.c')
-rw-r--r-- | sound/pci/rme9652/hdspm.c | 52 |
1 files changed, 27 insertions, 25 deletions
diff --git a/sound/pci/rme9652/hdspm.c b/sound/pci/rme9652/hdspm.c index ab423bc82342..98762f909d64 100644 --- a/sound/pci/rme9652/hdspm.c +++ b/sound/pci/rme9652/hdspm.c | |||
@@ -535,7 +535,8 @@ static inline void snd_hdspm_initialize_midi_flush(struct hdspm * hdspm); | |||
535 | static int hdspm_update_simple_mixer_controls(struct hdspm * hdspm); | 535 | static int hdspm_update_simple_mixer_controls(struct hdspm * hdspm); |
536 | static int hdspm_autosync_ref(struct hdspm * hdspm); | 536 | static int hdspm_autosync_ref(struct hdspm * hdspm); |
537 | static int snd_hdspm_set_defaults(struct hdspm * hdspm); | 537 | static int snd_hdspm_set_defaults(struct hdspm * hdspm); |
538 | static void hdspm_set_sgbuf(struct hdspm * hdspm, struct snd_sg_buf *sgbuf, | 538 | static void hdspm_set_sgbuf(struct hdspm * hdspm, |
539 | struct snd_pcm_substream *substream, | ||
539 | unsigned int reg, int channels); | 540 | unsigned int reg, int channels); |
540 | 541 | ||
541 | static inline int HDSPM_bit2freq(int n) | 542 | static inline int HDSPM_bit2freq(int n) |
@@ -845,7 +846,7 @@ static void hdspm_set_dds_value(struct hdspm *hdspm, int rate) | |||
845 | n = 110100480000000ULL; /* Value checked for AES32 and MADI */ | 846 | n = 110100480000000ULL; /* Value checked for AES32 and MADI */ |
846 | div64_32(&n, rate, &r); | 847 | div64_32(&n, rate, &r); |
847 | /* n should be less than 2^32 for being written to FREQ register */ | 848 | /* n should be less than 2^32 for being written to FREQ register */ |
848 | snd_assert((n >> 32) == 0); | 849 | snd_BUG_ON(n >> 32); |
849 | hdspm_write(hdspm, HDSPM_freqReg, (u32)n); | 850 | hdspm_write(hdspm, HDSPM_freqReg, (u32)n); |
850 | } | 851 | } |
851 | 852 | ||
@@ -2617,8 +2618,8 @@ static int snd_hdspm_get_playback_mixer(struct snd_kcontrol *kcontrol, | |||
2617 | 2618 | ||
2618 | channel = ucontrol->id.index - 1; | 2619 | channel = ucontrol->id.index - 1; |
2619 | 2620 | ||
2620 | snd_assert(channel >= 0 | 2621 | if (snd_BUG_ON(channel < 0 || channel >= HDSPM_MAX_CHANNELS)) |
2621 | || channel < HDSPM_MAX_CHANNELS, return -EINVAL); | 2622 | return -EINVAL; |
2622 | 2623 | ||
2623 | mapped_channel = hdspm->channel_map[channel]; | 2624 | mapped_channel = hdspm->channel_map[channel]; |
2624 | if (mapped_channel < 0) | 2625 | if (mapped_channel < 0) |
@@ -2652,8 +2653,8 @@ static int snd_hdspm_put_playback_mixer(struct snd_kcontrol *kcontrol, | |||
2652 | 2653 | ||
2653 | channel = ucontrol->id.index - 1; | 2654 | channel = ucontrol->id.index - 1; |
2654 | 2655 | ||
2655 | snd_assert(channel >= 0 | 2656 | if (snd_BUG_ON(channel < 0 || channel >= HDSPM_MAX_CHANNELS)) |
2656 | || channel < HDSPM_MAX_CHANNELS, return -EINVAL); | 2657 | return -EINVAL; |
2657 | 2658 | ||
2658 | mapped_channel = hdspm->channel_map[channel]; | 2659 | mapped_channel = hdspm->channel_map[channel]; |
2659 | if (mapped_channel < 0) | 2660 | if (mapped_channel < 0) |
@@ -3496,8 +3497,8 @@ static char *hdspm_channel_buffer_location(struct hdspm * hdspm, | |||
3496 | { | 3497 | { |
3497 | int mapped_channel; | 3498 | int mapped_channel; |
3498 | 3499 | ||
3499 | snd_assert(channel >= 0 | 3500 | if (snd_BUG_ON(channel < 0 || channel >= HDSPM_MAX_CHANNELS)) |
3500 | || channel < HDSPM_MAX_CHANNELS, return NULL); | 3501 | return NULL; |
3501 | 3502 | ||
3502 | mapped_channel = hdspm->channel_map[channel]; | 3503 | mapped_channel = hdspm->channel_map[channel]; |
3503 | if (mapped_channel < 0) | 3504 | if (mapped_channel < 0) |
@@ -3520,14 +3521,15 @@ static int snd_hdspm_playback_copy(struct snd_pcm_substream *substream, | |||
3520 | struct hdspm *hdspm = snd_pcm_substream_chip(substream); | 3521 | struct hdspm *hdspm = snd_pcm_substream_chip(substream); |
3521 | char *channel_buf; | 3522 | char *channel_buf; |
3522 | 3523 | ||
3523 | snd_assert(pos + count <= HDSPM_CHANNEL_BUFFER_BYTES / 4, | 3524 | if (snd_BUG_ON(pos + count > HDSPM_CHANNEL_BUFFER_BYTES / 4)) |
3524 | return -EINVAL); | 3525 | return -EINVAL; |
3525 | 3526 | ||
3526 | channel_buf = | 3527 | channel_buf = |
3527 | hdspm_channel_buffer_location(hdspm, substream->pstr->stream, | 3528 | hdspm_channel_buffer_location(hdspm, substream->pstr->stream, |
3528 | channel); | 3529 | channel); |
3529 | 3530 | ||
3530 | snd_assert(channel_buf != NULL, return -EIO); | 3531 | if (snd_BUG_ON(!channel_buf)) |
3532 | return -EIO; | ||
3531 | 3533 | ||
3532 | return copy_from_user(channel_buf + pos * 4, src, count * 4); | 3534 | return copy_from_user(channel_buf + pos * 4, src, count * 4); |
3533 | } | 3535 | } |
@@ -3539,13 +3541,14 @@ static int snd_hdspm_capture_copy(struct snd_pcm_substream *substream, | |||
3539 | struct hdspm *hdspm = snd_pcm_substream_chip(substream); | 3541 | struct hdspm *hdspm = snd_pcm_substream_chip(substream); |
3540 | char *channel_buf; | 3542 | char *channel_buf; |
3541 | 3543 | ||
3542 | snd_assert(pos + count <= HDSPM_CHANNEL_BUFFER_BYTES / 4, | 3544 | if (snd_BUG_ON(pos + count > HDSPM_CHANNEL_BUFFER_BYTES / 4)) |
3543 | return -EINVAL); | 3545 | return -EINVAL; |
3544 | 3546 | ||
3545 | channel_buf = | 3547 | channel_buf = |
3546 | hdspm_channel_buffer_location(hdspm, substream->pstr->stream, | 3548 | hdspm_channel_buffer_location(hdspm, substream->pstr->stream, |
3547 | channel); | 3549 | channel); |
3548 | snd_assert(channel_buf != NULL, return -EIO); | 3550 | if (snd_BUG_ON(!channel_buf)) |
3551 | return -EIO; | ||
3549 | return copy_to_user(dst, channel_buf + pos * 4, count * 4); | 3552 | return copy_to_user(dst, channel_buf + pos * 4, count * 4); |
3550 | } | 3553 | } |
3551 | 3554 | ||
@@ -3559,7 +3562,8 @@ static int snd_hdspm_hw_silence(struct snd_pcm_substream *substream, | |||
3559 | channel_buf = | 3562 | channel_buf = |
3560 | hdspm_channel_buffer_location(hdspm, substream->pstr->stream, | 3563 | hdspm_channel_buffer_location(hdspm, substream->pstr->stream, |
3561 | channel); | 3564 | channel); |
3562 | snd_assert(channel_buf != NULL, return -EIO); | 3565 | if (snd_BUG_ON(!channel_buf)) |
3566 | return -EIO; | ||
3563 | memset(channel_buf + pos * 4, 0, count * 4); | 3567 | memset(channel_buf + pos * 4, 0, count * 4); |
3564 | return 0; | 3568 | return 0; |
3565 | } | 3569 | } |
@@ -3601,8 +3605,6 @@ static int snd_hdspm_hw_params(struct snd_pcm_substream *substream, | |||
3601 | int i; | 3605 | int i; |
3602 | pid_t this_pid; | 3606 | pid_t this_pid; |
3603 | pid_t other_pid; | 3607 | pid_t other_pid; |
3604 | struct snd_sg_buf *sgbuf; | ||
3605 | |||
3606 | 3608 | ||
3607 | spin_lock_irq(&hdspm->lock); | 3609 | spin_lock_irq(&hdspm->lock); |
3608 | 3610 | ||
@@ -3670,11 +3672,9 @@ static int snd_hdspm_hw_params(struct snd_pcm_substream *substream, | |||
3670 | if (err < 0) | 3672 | if (err < 0) |
3671 | return err; | 3673 | return err; |
3672 | 3674 | ||
3673 | sgbuf = snd_pcm_substream_sgbuf(substream); | ||
3674 | |||
3675 | if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { | 3675 | if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { |
3676 | 3676 | ||
3677 | hdspm_set_sgbuf(hdspm, sgbuf, HDSPM_pageAddressBufferOut, | 3677 | hdspm_set_sgbuf(hdspm, substream, HDSPM_pageAddressBufferOut, |
3678 | params_channels(params)); | 3678 | params_channels(params)); |
3679 | 3679 | ||
3680 | for (i = 0; i < params_channels(params); ++i) | 3680 | for (i = 0; i < params_channels(params); ++i) |
@@ -3685,7 +3685,7 @@ static int snd_hdspm_hw_params(struct snd_pcm_substream *substream, | |||
3685 | snd_printdd("Allocated sample buffer for playback at %p\n", | 3685 | snd_printdd("Allocated sample buffer for playback at %p\n", |
3686 | hdspm->playback_buffer); | 3686 | hdspm->playback_buffer); |
3687 | } else { | 3687 | } else { |
3688 | hdspm_set_sgbuf(hdspm, sgbuf, HDSPM_pageAddressBufferIn, | 3688 | hdspm_set_sgbuf(hdspm, substream, HDSPM_pageAddressBufferIn, |
3689 | params_channels(params)); | 3689 | params_channels(params)); |
3690 | 3690 | ||
3691 | for (i = 0; i < params_channels(params); ++i) | 3691 | for (i = 0; i < params_channels(params); ++i) |
@@ -3700,7 +3700,7 @@ static int snd_hdspm_hw_params(struct snd_pcm_substream *substream, | |||
3700 | snd_printdd("Allocated sample buffer for %s at 0x%08X\n", | 3700 | snd_printdd("Allocated sample buffer for %s at 0x%08X\n", |
3701 | substream->stream == SNDRV_PCM_STREAM_PLAYBACK ? | 3701 | substream->stream == SNDRV_PCM_STREAM_PLAYBACK ? |
3702 | "playback" : "capture", | 3702 | "playback" : "capture", |
3703 | snd_pcm_sgbuf_get_addr(sgbuf, 0)); | 3703 | snd_pcm_sgbuf_get_addr(substream, 0)); |
3704 | */ | 3704 | */ |
3705 | /* | 3705 | /* |
3706 | snd_printdd("set_hwparams: %s %d Hz, %d channels, bs = %d\n", | 3706 | snd_printdd("set_hwparams: %s %d Hz, %d channels, bs = %d\n", |
@@ -3744,7 +3744,8 @@ static int snd_hdspm_channel_info(struct snd_pcm_substream *substream, | |||
3744 | struct hdspm *hdspm = snd_pcm_substream_chip(substream); | 3744 | struct hdspm *hdspm = snd_pcm_substream_chip(substream); |
3745 | int mapped_channel; | 3745 | int mapped_channel; |
3746 | 3746 | ||
3747 | snd_assert(info->channel < HDSPM_MAX_CHANNELS, return -EINVAL); | 3747 | if (snd_BUG_ON(info->channel >= HDSPM_MAX_CHANNELS)) |
3748 | return -EINVAL; | ||
3748 | 3749 | ||
3749 | mapped_channel = hdspm->channel_map[info->channel]; | 3750 | mapped_channel = hdspm->channel_map[info->channel]; |
3750 | if (mapped_channel < 0) | 3751 | if (mapped_channel < 0) |
@@ -4249,13 +4250,14 @@ static int __devinit snd_hdspm_preallocate_memory(struct hdspm * hdspm) | |||
4249 | return 0; | 4250 | return 0; |
4250 | } | 4251 | } |
4251 | 4252 | ||
4252 | static void hdspm_set_sgbuf(struct hdspm * hdspm, struct snd_sg_buf *sgbuf, | 4253 | static void hdspm_set_sgbuf(struct hdspm * hdspm, |
4254 | struct snd_pcm_substream *substream, | ||
4253 | unsigned int reg, int channels) | 4255 | unsigned int reg, int channels) |
4254 | { | 4256 | { |
4255 | int i; | 4257 | int i; |
4256 | for (i = 0; i < (channels * 16); i++) | 4258 | for (i = 0; i < (channels * 16); i++) |
4257 | hdspm_write(hdspm, reg + 4 * i, | 4259 | hdspm_write(hdspm, reg + 4 * i, |
4258 | snd_pcm_sgbuf_get_addr(sgbuf, (size_t) 4096 * i)); | 4260 | snd_pcm_sgbuf_get_addr(substream, 4096 * i)); |
4259 | } | 4261 | } |
4260 | 4262 | ||
4261 | /* ------------- ALSA Devices ---------------------------- */ | 4263 | /* ------------- ALSA Devices ---------------------------- */ |