Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

drm/etnaviv: Improve VA, PA, SIZE alignment checking

Alignment checking is only needed to be done in the upper caller function.
If those address and sizes are able to pass the check, it will certainly
pass the same test in the etnaviv_context_unmap() function. We don't need
examine it more than once.

Remove redundant alignment tests, move the those useless to upper caller
function.

Signed-off-by: Sui Jingfeng <sui.jingfeng@linux.dev>
Signed-off-by: Lucas Stach <l.stach@pengutronix.de>

authored by

Sui Jingfeng and committed by
Lucas Stach
a807cb22 0078a6f4

+8 -12
+8 -12
drivers/gpu/drm/etnaviv/etnaviv_mmu.c
··· 19 19 size_t unmapped_page, unmapped = 0; 20 20 size_t pgsize = SZ_4K; 21 21 22 - if (!IS_ALIGNED(iova | size, pgsize)) { 23 - pr_err("unaligned: iova 0x%lx size 0x%zx min_pagesz 0x%zx\n", 24 - iova, size, pgsize); 25 - return; 26 - } 27 - 28 22 while (unmapped < size) { 29 23 unmapped_page = context->global->ops->unmap(context, iova, 30 24 pgsize); ··· 38 44 size_t pgsize = SZ_4K; 39 45 size_t orig_size = size; 40 46 int ret = 0; 41 - 42 - if (!IS_ALIGNED(iova | paddr | size, pgsize)) { 43 - pr_err("unaligned: iova 0x%lx pa %pa size 0x%zx min_pagesz 0x%zx\n", 44 - iova, &paddr, size, pgsize); 45 - return -EINVAL; 46 - } 47 47 48 48 while (size) { 49 49 ret = context->global->ops->map(context, iova, paddr, pgsize, ··· 75 87 unsigned int bytes = min_t(unsigned int, da_len, va_len); 76 88 77 89 VERB("map[%d]: %08x %pap(%x)", i, da, &pa, bytes); 90 + 91 + if (!IS_ALIGNED(iova | pa | bytes, SZ_4K)) { 92 + dev_err(context->global->dev, 93 + "unaligned: iova 0x%x pa %pa size 0x%x\n", 94 + iova, &pa, bytes); 95 + ret = -EINVAL; 96 + goto fail; 97 + } 78 98 79 99 ret = etnaviv_context_map(context, da, pa, bytes, prot); 80 100 if (ret)