From f7f9a0c8736d418af8d981000ea68ea43b395da4 Mon Sep 17 00:00:00 2001 From: "Matthew Wilcox (Oracle)" Date: Sat, 15 Jul 2023 23:03:52 -0400 Subject: [PATCH] iov_iter: Map the page later in copy_page_from_iter_atomic() Remove a couple of calls to kunmap_atomic() in the rare error cases. Signed-off-by: Matthew Wilcox (Oracle) Reviewed-by: Christoph Hellwig Reviewed-by: Kent Overstreet Reviewed-by: Darrick J. Wong --- lib/iov_iter.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/iov_iter.c b/lib/iov_iter.c index e4dc809d10754f..db58af77829125 100644 --- a/lib/iov_iter.c +++ b/lib/iov_iter.c @@ -569,20 +569,20 @@ EXPORT_SYMBOL(iov_iter_zero); size_t copy_page_from_iter_atomic(struct page *page, unsigned offset, size_t bytes, struct iov_iter *i) { - char *kaddr = kmap_atomic(page), *p = kaddr + offset; - if (!page_copy_sane(page, offset, bytes)) { - kunmap_atomic(kaddr); + char *p; + + if (!page_copy_sane(page, offset, bytes)) return 0; - } - if (WARN_ON_ONCE(!i->data_source)) { - kunmap_atomic(kaddr); + if (WARN_ON_ONCE(!i->data_source)) return 0; - } + + p = kmap_atomic(page) + offset; iterate_and_advance(i, bytes, base, len, off, copyin(p + off, base, len), memcpy_from_iter(i, p + off, base, len) ) - kunmap_atomic(kaddr); + kunmap_atomic(p); + return bytes; } EXPORT_SYMBOL(copy_page_from_iter_atomic);