On 10/16/2026 10:05 AM, Alistair Francis wrote:
On Fri, 2026-10-02 at 22:02 +0800, Tao Ding wrote:
Validate the address before subtracting the channel base and use
hwaddr
for channel calculations to prevent unsigned underflow and
truncation.
Resolves: Coverity CID 1685514
Reported-by: Alistair Francis<[email protected]>
Signed-off-by: Tao Ding<[email protected]>
---
Compared to patchv1, the modification of ch has been removed.
Because ch is an unsigned int, it is sufficient.
hw/dma/k230_gsdma.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/hw/dma/k230_gsdma.c b/hw/dma/k230_gsdma.c
index 7635cd19e8..e422b436a2 100644
--- a/hw/dma/k230_gsdma.c
+++ b/hw/dma/k230_gsdma.c
@@ -329,6 +329,9 @@ static uint64_t k230_gsdma_read(void *opaque,
hwaddr addr, unsigned int size)
break;
}
+ if (addr < K230_GSDMA_CH_BASE) {
+ goto out;
+ }
This isn't right, you already have a `if (addr < K230_GSDMA_CH_BASE)`
check above, just use that but return.
That way we don't log a read that doesn't actually happen, and can
avoid a goto
Alistair
Yes, we can return in the if in the default above.
But some addresses arrive here through other branches of the switch, and these
addresses are smaller than K230_SSDMA_CH_SASE.
If there is no goto, overflow errors will occur when calculating "ch".
The next patch will use conditional judgment to avoid using goto.
ch = (addr - K230_GSDMA_CH_BASE) / K230_GSDMA_CH_STRIDE;
ch_off = (addr - K230_GSDMA_CH_BASE) % K230_GSDMA_CH_STRIDE;
if (ch < K230_GSDMA_NUM_SDMA_CHANNELS) {
@@ -355,6 +358,7 @@ static uint64_t k230_gsdma_read(void *opaque,
hwaddr addr, unsigned int size)
}
}
+out:
trace_k230_gsdma_read(addr, size, ret);
return ret;
}