Skip to content

Commit 6ad3914

Browse files
GT119119broonie
authored andcommitted
ASoC: loongson: Fix invalid position error in ls_pcm_pointer
The "invalid position" error occurred when the DMA position descriptor returned an invalid address value (e.g., pos = -1048838144). This happened because the `bytes_to_frames()` function returns a signed value, but when `addr < runtime->dma_addr`, the subtraction produces a negative result that gets interpreted as a large unsigned integer in comparisons. when the addr is abnormal, for example,the DMA controller is abnormal in hardware,x=0 should not be a point(x == runtime->buffer_size),but a range, which includes the addr address being less than runtime ->dma1-adr, and the addr exceeding the DMA address range.the value of pos should not better a negative,return 0, maybe better. [ 32.834431][ 2] soc-audio soc-audio: invalid position: , pos = -1048838144 [ 32.845019][ 2] soc-audio soc-audio: invalid position: , pos = -1048838144 [ 32.855588][ 2] soc-audio soc-audio: invalid position: , pos = -1048838144 [ 32.866145][ 2] soc-audio soc-audio: invalid position: , pos = -1048838144 [ 32.995394][ 2] soc-audio soc-audio: invalid position: , pos = -1048838144 [ 33.006025][ 2] soc-audio soc-audio: invalid position: , pos = -1048838144 [ 33.016748][ 2] soc-audio soc-audio: invalid position: , pos = -1048838144 Signed-off-by: Li Jun <lijun01@kylinos.cn> [Remove XRUN reporting I'd mistakenly avised adding on prior review -- broonie] Link: https://patch.msgid.link/20260611010045.3668574-1-lijun01@kylinos.cn Signed-off-by: Mark Brown <broonie@kernel.org>
1 parent 3106284 commit 6ad3914

1 file changed

Lines changed: 10 additions & 2 deletions

File tree

sound/soc/loongson/loongson_dma.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,7 @@ loongson_pcm_pointer(struct snd_soc_component *component,
199199
struct snd_pcm_substream *substream)
200200
{
201201
struct snd_pcm_runtime *runtime = substream->runtime;
202+
struct device *dev = substream->pcm->card->dev;
202203
struct loongson_runtime_data *prtd = runtime->private_data;
203204
struct loongson_dma_desc *desc;
204205
snd_pcm_uframes_t x;
@@ -207,9 +208,16 @@ loongson_pcm_pointer(struct snd_soc_component *component,
207208
desc = dma_desc_save(prtd);
208209
addr = ((u64)desc->saddr_hi << 32) | desc->saddr;
209210

210-
x = bytes_to_frames(runtime, addr - runtime->dma_addr);
211-
if (x == runtime->buffer_size)
211+
if (addr < runtime->dma_addr ||
212+
addr > runtime->dma_addr + runtime->dma_bytes) {
213+
dev_warn(dev, "WARNING! dma_addr:0x%llx\n", addr);
212214
x = 0;
215+
} else {
216+
x = bytes_to_frames(runtime, addr - runtime->dma_addr);
217+
if (x == runtime->buffer_size)
218+
x = 0;
219+
}
220+
213221
return x;
214222
}
215223

0 commit comments

Comments
 (0)