aboutsummaryrefslogtreecommitdiffstats
path: root/sound/pci/trident
diff options
context:
space:
mode:
Diffstat (limited to 'sound/pci/trident')
-rw-r--r--sound/pci/trident/trident_main.c22
-rw-r--r--sound/pci/trident/trident_memory.c37
2 files changed, 34 insertions, 25 deletions
diff --git a/sound/pci/trident/trident_main.c b/sound/pci/trident/trident_main.c
index a69b4206c69e..c612b435ca2b 100644
--- a/sound/pci/trident/trident_main.c
+++ b/sound/pci/trident/trident_main.c
@@ -2931,7 +2931,8 @@ static int snd_trident_pcm_mixer_build(struct snd_trident *trident,
2931{ 2931{
2932 struct snd_trident_pcm_mixer *tmix; 2932 struct snd_trident_pcm_mixer *tmix;
2933 2933
2934 snd_assert(trident != NULL && voice != NULL && substream != NULL, return -EINVAL); 2934 if (snd_BUG_ON(!trident || !voice || !substream))
2935 return -EINVAL;
2935 tmix = &trident->pcm_mixer[substream->number]; 2936 tmix = &trident->pcm_mixer[substream->number];
2936 tmix->voice = voice; 2937 tmix->voice = voice;
2937 tmix->vol = T4D_DEFAULT_PCM_VOL; 2938 tmix->vol = T4D_DEFAULT_PCM_VOL;
@@ -2946,7 +2947,8 @@ static int snd_trident_pcm_mixer_free(struct snd_trident *trident, struct snd_tr
2946{ 2947{
2947 struct snd_trident_pcm_mixer *tmix; 2948 struct snd_trident_pcm_mixer *tmix;
2948 2949
2949 snd_assert(trident != NULL && substream != NULL, return -EINVAL); 2950 if (snd_BUG_ON(!trident || !substream))
2951 return -EINVAL;
2950 tmix = &trident->pcm_mixer[substream->number]; 2952 tmix = &trident->pcm_mixer[substream->number];
2951 tmix->voice = NULL; 2953 tmix->voice = NULL;
2952 snd_trident_notify_pcm_change(trident, tmix, substream->number, 0); 2954 snd_trident_notify_pcm_change(trident, tmix, substream->number, 0);
@@ -3131,7 +3133,8 @@ static unsigned char snd_trident_gameport_read(struct gameport *gameport)
3131{ 3133{
3132 struct snd_trident *chip = gameport_get_port_data(gameport); 3134 struct snd_trident *chip = gameport_get_port_data(gameport);
3133 3135
3134 snd_assert(chip, return 0); 3136 if (snd_BUG_ON(!chip))
3137 return 0;
3135 return inb(TRID_REG(chip, GAMEPORT_LEGACY)); 3138 return inb(TRID_REG(chip, GAMEPORT_LEGACY));
3136} 3139}
3137 3140
@@ -3139,7 +3142,8 @@ static void snd_trident_gameport_trigger(struct gameport *gameport)
3139{ 3142{
3140 struct snd_trident *chip = gameport_get_port_data(gameport); 3143 struct snd_trident *chip = gameport_get_port_data(gameport);
3141 3144
3142 snd_assert(chip, return); 3145 if (snd_BUG_ON(!chip))
3146 return;
3143 outb(0xff, TRID_REG(chip, GAMEPORT_LEGACY)); 3147 outb(0xff, TRID_REG(chip, GAMEPORT_LEGACY));
3144} 3148}
3145 3149
@@ -3148,7 +3152,8 @@ static int snd_trident_gameport_cooked_read(struct gameport *gameport, int *axes
3148 struct snd_trident *chip = gameport_get_port_data(gameport); 3152 struct snd_trident *chip = gameport_get_port_data(gameport);
3149 int i; 3153 int i;
3150 3154
3151 snd_assert(chip, return 0); 3155 if (snd_BUG_ON(!chip))
3156 return 0;
3152 3157
3153 *buttons = (~inb(TRID_REG(chip, GAMEPORT_LEGACY)) >> 4) & 0xf; 3158 *buttons = (~inb(TRID_REG(chip, GAMEPORT_LEGACY)) >> 4) & 0xf;
3154 3159
@@ -3164,7 +3169,8 @@ static int snd_trident_gameport_open(struct gameport *gameport, int mode)
3164{ 3169{
3165 struct snd_trident *chip = gameport_get_port_data(gameport); 3170 struct snd_trident *chip = gameport_get_port_data(gameport);
3166 3171
3167 snd_assert(chip, return 0); 3172 if (snd_BUG_ON(!chip))
3173 return 0;
3168 3174
3169 switch (mode) { 3175 switch (mode) {
3170 case GAMEPORT_MODE_COOKED: 3176 case GAMEPORT_MODE_COOKED:
@@ -3891,8 +3897,8 @@ static void snd_trident_clear_voices(struct snd_trident * trident, unsigned shor
3891{ 3897{
3892 unsigned int i, val, mask[2] = { 0, 0 }; 3898 unsigned int i, val, mask[2] = { 0, 0 };
3893 3899
3894 snd_assert(v_min <= 63, return); 3900 if (snd_BUG_ON(v_min > 63 || v_max > 63))
3895 snd_assert(v_max <= 63, return); 3901 return;
3896 for (i = v_min; i <= v_max; i++) 3902 for (i = v_min; i <= v_max; i++)
3897 mask[i >> 5] |= 1 << (i & 0x1f); 3903 mask[i >> 5] |= 1 << (i & 0x1f);
3898 if (mask[0]) { 3904 if (mask[0]) {
diff --git a/sound/pci/trident/trident_memory.c b/sound/pci/trident/trident_memory.c
index 3fd7f1b29b0f..f9779e23fe57 100644
--- a/sound/pci/trident/trident_memory.c
+++ b/sound/pci/trident/trident_memory.c
@@ -194,11 +194,14 @@ snd_trident_alloc_sg_pages(struct snd_trident *trident,
194 struct snd_util_memblk *blk; 194 struct snd_util_memblk *blk;
195 struct snd_pcm_runtime *runtime = substream->runtime; 195 struct snd_pcm_runtime *runtime = substream->runtime;
196 int idx, page; 196 int idx, page;
197 struct snd_sg_buf *sgbuf = snd_pcm_substream_sgbuf(substream);
198 197
199 snd_assert(runtime->dma_bytes > 0 && runtime->dma_bytes <= SNDRV_TRIDENT_MAX_PAGES * SNDRV_TRIDENT_PAGE_SIZE, return NULL); 198 if (snd_BUG_ON(runtime->dma_bytes <= 0 ||
199 runtime->dma_bytes > SNDRV_TRIDENT_MAX_PAGES *
200 SNDRV_TRIDENT_PAGE_SIZE))
201 return NULL;
200 hdr = trident->tlb.memhdr; 202 hdr = trident->tlb.memhdr;
201 snd_assert(hdr != NULL, return NULL); 203 if (snd_BUG_ON(!hdr))
204 return NULL;
202 205
203 206
204 207
@@ -208,18 +211,14 @@ snd_trident_alloc_sg_pages(struct snd_trident *trident,
208 mutex_unlock(&hdr->block_mutex); 211 mutex_unlock(&hdr->block_mutex);
209 return NULL; 212 return NULL;
210 } 213 }
211 if (lastpg(blk) - firstpg(blk) >= sgbuf->pages) {
212 snd_printk(KERN_ERR "page calculation doesn't match: allocated pages = %d, trident = %d/%d\n", sgbuf->pages, firstpg(blk), lastpg(blk));
213 __snd_util_mem_free(hdr, blk);
214 mutex_unlock(&hdr->block_mutex);
215 return NULL;
216 }
217 214
218 /* set TLB entries */ 215 /* set TLB entries */
219 idx = 0; 216 idx = 0;
220 for (page = firstpg(blk); page <= lastpg(blk); page++, idx++) { 217 for (page = firstpg(blk); page <= lastpg(blk); page++, idx++) {
221 dma_addr_t addr = sgbuf->table[idx].addr; 218 unsigned long ofs = idx << PAGE_SHIFT;
222 unsigned long ptr = (unsigned long)sgbuf->table[idx].buf; 219 dma_addr_t addr = snd_pcm_sgbuf_get_addr(substream, ofs);
220 unsigned long ptr = (unsigned long)
221 snd_pcm_sgbuf_get_ptr(substream, ofs);
223 if (! is_valid_page(addr)) { 222 if (! is_valid_page(addr)) {
224 __snd_util_mem_free(hdr, blk); 223 __snd_util_mem_free(hdr, blk);
225 mutex_unlock(&hdr->block_mutex); 224 mutex_unlock(&hdr->block_mutex);
@@ -245,9 +244,13 @@ snd_trident_alloc_cont_pages(struct snd_trident *trident,
245 dma_addr_t addr; 244 dma_addr_t addr;
246 unsigned long ptr; 245 unsigned long ptr;
247 246
248 snd_assert(runtime->dma_bytes> 0 && runtime->dma_bytes <= SNDRV_TRIDENT_MAX_PAGES * SNDRV_TRIDENT_PAGE_SIZE, return NULL); 247 if (snd_BUG_ON(runtime->dma_bytes <= 0 ||
248 runtime->dma_bytes > SNDRV_TRIDENT_MAX_PAGES *
249 SNDRV_TRIDENT_PAGE_SIZE))
250 return NULL;
249 hdr = trident->tlb.memhdr; 251 hdr = trident->tlb.memhdr;
250 snd_assert(hdr != NULL, return NULL); 252 if (snd_BUG_ON(!hdr))
253 return NULL;
251 254
252 mutex_lock(&hdr->block_mutex); 255 mutex_lock(&hdr->block_mutex);
253 blk = search_empty(hdr, runtime->dma_bytes); 256 blk = search_empty(hdr, runtime->dma_bytes);
@@ -279,8 +282,8 @@ struct snd_util_memblk *
279snd_trident_alloc_pages(struct snd_trident *trident, 282snd_trident_alloc_pages(struct snd_trident *trident,
280 struct snd_pcm_substream *substream) 283 struct snd_pcm_substream *substream)
281{ 284{
282 snd_assert(trident != NULL, return NULL); 285 if (snd_BUG_ON(!trident || !substream))
283 snd_assert(substream != NULL, return NULL); 286 return NULL;
284 if (substream->dma_buffer.dev.type == SNDRV_DMA_TYPE_DEV_SG) 287 if (substream->dma_buffer.dev.type == SNDRV_DMA_TYPE_DEV_SG)
285 return snd_trident_alloc_sg_pages(trident, substream); 288 return snd_trident_alloc_sg_pages(trident, substream);
286 else 289 else
@@ -297,8 +300,8 @@ int snd_trident_free_pages(struct snd_trident *trident,
297 struct snd_util_memhdr *hdr; 300 struct snd_util_memhdr *hdr;
298 int page; 301 int page;
299 302
300 snd_assert(trident != NULL, return -EINVAL); 303 if (snd_BUG_ON(!trident || !blk))
301 snd_assert(blk != NULL, return -EINVAL); 304 return -EINVAL;
302 305
303 hdr = trident->tlb.memhdr; 306 hdr = trident->tlb.memhdr;
304 mutex_lock(&hdr->block_mutex); 307 mutex_lock(&hdr->block_mutex);