static inline unsigned int calc_linear_pos(struct via82xx_modem *chip, struct viadev *viadev, unsigned int idx, unsigned int count) { unsigned int size, res; size = viadev->idx_table[idx].size; res = viadev->idx_table[idx].offset + size - count; /* check the validity of the calculated position */ if (size < count) { dev_err(chip->card->dev, "invalid via82xx_cur_ptr (size = %d, count = %d)\n", (int)size, (int)count); res = viadev->lastpos; } else if (check_invalid_pos(viadev, res)) { #ifdef POINTER_DEBUG dev_dbg(chip->card->dev, "fail: idx = %i/%i, lastpos = 0x%x, bufsize2 = 0x%x, offsize = 0x%x, size = 0x%x, count = 0x%x\n", idx, viadev->tbl_entries, viadev->lastpos, viadev->bufsize2, viadev->idx_table[idx].offset, viadev->idx_table[idx].size, count); #endif if (count && size < count) { dev_dbg(chip->card->dev, "invalid via82xx_cur_ptr, using last valid pointer\n"); res = viadev->lastpos; } else { if (! count) /* bogus count 0 on the DMA boundary? */ res = viadev->idx_table[idx].offset; else /* count register returns full size * when end of buffer is reached */ res = viadev->idx_table[idx].offset + size; if (check_invalid_pos(viadev, res)) { dev_dbg(chip->card->dev, "invalid via82xx_cur_ptr (2), using last valid pointer\n"); res = viadev->lastpos; } } } viadev->lastpos = res; /* remember the last position */ if (res >= viadev->bufsize) res -= viadev->bufsize; return res; }
static inline unsigned int calc_linear_pos(struct viadev *viadev, unsigned int idx, unsigned int count) { unsigned int size, res; size = viadev->idx_table[idx].size; res = viadev->idx_table[idx].offset + size - count; /* */ if (size < count) { snd_printd(KERN_ERR "invalid via82xx_cur_ptr (size = %d, count = %d)\n", (int)size, (int)count); res = viadev->lastpos; } else if (check_invalid_pos(viadev, res)) { #ifdef POINTER_DEBUG printk(KERN_DEBUG "fail: idx = %i/%i, lastpos = 0x%x, " "bufsize2 = 0x%x, offsize = 0x%x, size = 0x%x, " "count = 0x%x\n", idx, viadev->tbl_entries, viadev->lastpos, viadev->bufsize2, viadev->idx_table[idx].offset, viadev->idx_table[idx].size, count); #endif if (count && size < count) { snd_printd(KERN_ERR "invalid via82xx_cur_ptr, " "using last valid pointer\n"); res = viadev->lastpos; } else { if (! count) /* */ res = viadev->idx_table[idx].offset; else /* */ res = viadev->idx_table[idx].offset + size; if (check_invalid_pos(viadev, res)) { snd_printd(KERN_ERR "invalid via82xx_cur_ptr (2), " "using last valid pointer\n"); res = viadev->lastpos; } } } viadev->lastpos = res; /* */ if (res >= viadev->bufsize) res -= viadev->bufsize; return res; }