remoteproc/mediatek: fix boundary check
authorTzung-Bi Shih <tzungbi@google.com>
Mon, 16 Nov 2020 08:44:11 +0000 (16:44 +0800)
committerBjorn Andersson <bjorn.andersson@linaro.org>
Sat, 21 Nov 2020 03:45:34 +0000 (21:45 -0600)
It is valid if offset+length == sram_size.

For example, sram_size=100, offset=99, length=1.  Accessing offset 99
with length 1 is valid.

Reviewed-by: Mathieu Poirier <mathieu.poirier@linaro.org>
Signed-off-by: Tzung-Bi Shih <tzungbi@google.com>
Link: https://lore.kernel.org/r/20201116084413.3312631-2-tzungbi@google.com
Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
drivers/remoteproc/mtk_scp.c

index a1e23b5..0abbeb6 100644 (file)
@@ -408,11 +408,11 @@ static void *scp_da_to_va(struct rproc *rproc, u64 da, size_t len)
 
        if (da < scp->sram_size) {
                offset = da;
-               if (offset >= 0 && (offset + len) < scp->sram_size)
+               if (offset >= 0 && (offset + len) <= scp->sram_size)
                        return (void __force *)scp->sram_base + offset;
        } else if (scp->dram_size) {
                offset = da - scp->dma_addr;
-               if (offset >= 0 && (offset + len) < scp->dram_size)
+               if (offset >= 0 && (offset + len) <= scp->dram_size)
                        return scp->cpu_addr + offset;
        }