From 9a8039439a6cee003c7da0eedf7a54486c7145f7 Mon Sep 17 00:00:00 2001 From: Richard Yao Date: Sat, 15 Oct 2022 22:54:57 -0400 Subject: [PATCH] Cleanup: Simplify userspace abd_free_chunks() Clang's static analyzer complained that we could use after free here if the inner loop ever iterated. That is a false positive, but upon inspection, the userland abd_alloc_chunks() function never will put multiple consecutive pages into a `struct scatterlist`, so there is no need to loop. We delete the inner loop. Reviewed-by: Brian Behlendorf Signed-off-by: Richard Yao Closes #14042 --- module/os/linux/zfs/abd_os.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/module/os/linux/zfs/abd_os.c b/module/os/linux/zfs/abd_os.c index fcdd76852..e9b28becf 100644 --- a/module/os/linux/zfs/abd_os.c +++ b/module/os/linux/zfs/abd_os.c @@ -597,10 +597,8 @@ abd_free_chunks(abd_t *abd) struct scatterlist *sg; abd_for_each_sg(abd, sg, n, i) { - for (int j = 0; j < sg->length; j += PAGESIZE) { - struct page *p = nth_page(sg_page(sg), j >> PAGE_SHIFT); - umem_free(p, PAGESIZE); - } + struct page *p = nth_page(sg_page(sg), 0); + umem_free(p, PAGESIZE); } abd_free_sg_table(abd); }