diff mbox series

[4/4] brd: use memcpy_from_page() in copy_from_brd()

Message ID 20230328195626.12075-5-kch@nvidia.com (mailing list archive)
State New, archived
Headers show
Series brd: usr memcpy_[to|from]_page() in brd | expand

Commit Message

Chaitanya Kulkarni March 28, 2023, 7:56 p.m. UTC
In copy_from_brd() it uses kmap_atomic() call on the page in question to
create source page mapping on buffer (src), then it uses memcpy() call
to copy the data from mapped buffer (src) with added offset and size
equals to number of bytes stored in copy variable.
Then it uses the kunmap_atomic(), also from :include/linux/highmem.h:

From :include/linux/highmem.h:
"kmap_atomic - Atomically map a page for temporary usage - Deprecated!"

Use memcpy_from_page() helper does the same job of mapping and copying
except it uses non deprecated kmap_local_page() and kunmap_local().

Signed-off-by: Chaitanya Kulkarni <kch@nvidia.com>
---
 drivers/block/brd.c | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)
diff mbox series

Patch

diff --git a/drivers/block/brd.c b/drivers/block/brd.c
index 3df4b45eded3..c1251159bd13 100644
--- a/drivers/block/brd.c
+++ b/drivers/block/brd.c
@@ -216,7 +216,6 @@  static void copy_from_brd(void *dst, struct brd_device *brd,
 			sector_t sector, size_t n)
 {
 	struct page *page;
-	void *src;
 	unsigned int offset = (sector & (PAGE_SECTORS-1)) << SECTOR_SHIFT;
 	size_t copy;
 
@@ -232,11 +231,9 @@  static void copy_from_brd(void *dst, struct brd_device *brd,
 		sector += copy >> SECTOR_SHIFT;
 		copy = n - copy;
 		page = brd_lookup_page(brd, sector);
-		if (page) {
-			src = kmap_atomic(page);
-			memcpy(dst, src, copy);
-			kunmap_atomic(src);
-		} else
+		if (page)
+			memcpy_from_page(dst, page, 0, copy);
+		else
 			memset(dst, 0, copy);
 	}
 }