diff mbox series

[14/18] brd: use memcpy_{to,from}_folio()

Message ID 20230918110510.66470-15-hare@suse.de (mailing list archive)
State New, archived
Headers show
Series block: update buffer_head for Large-block I/O | expand

Commit Message

Hannes Reinecke Sept. 18, 2023, 11:05 a.m. UTC
Simplify copy routines by using memcpy_to_folio()/memcpy_from_folio().

Signed-off-by: Hannes Reinecke <hare@suse.de>
---
 drivers/block/brd.c | 39 ++++-----------------------------------
 1 file changed, 4 insertions(+), 35 deletions(-)
diff mbox series

Patch

diff --git a/drivers/block/brd.c b/drivers/block/brd.c
index d6595b1a22e8..90e1b6c4fbc8 100644
--- a/drivers/block/brd.c
+++ b/drivers/block/brd.c
@@ -163,7 +163,6 @@  static void copy_to_brd(struct brd_device *brd, const void *src,
 			sector_t sector, size_t n)
 {
 	struct folio *folio;
-	void *dst;
 	unsigned int rd_sector_size = PAGE_SIZE;
 	unsigned int offset = brd_sector_offset(brd, sector);
 	size_t copy;
@@ -172,21 +171,7 @@  static void copy_to_brd(struct brd_device *brd, const void *src,
 	folio = brd_lookup_folio(brd, sector);
 	BUG_ON(!folio);
 
-	dst = kmap_local_folio(folio, offset);
-	memcpy(dst, src, copy);
-	kunmap_local(dst);
-
-	if (copy < n) {
-		src += copy;
-		sector += copy >> SECTOR_SHIFT;
-		copy = n - copy;
-		folio = brd_lookup_folio(brd, sector);
-		BUG_ON(!folio);
-
-		dst = kmap_local_folio(folio, 0);
-		memcpy(dst, src, copy);
-		kunmap_local(dst);
-	}
+	memcpy_to_folio(folio, offset, src, copy);
 }
 
 /*
@@ -196,32 +181,16 @@  static void copy_from_brd(void *dst, struct brd_device *brd,
 			sector_t sector, size_t n)
 {
 	struct folio *folio;
-	void *src;
 	unsigned int rd_sector_size = PAGE_SIZE;
 	unsigned int offset = brd_sector_offset(brd, sector);
 	size_t copy;
 
 	copy = min_t(size_t, n, rd_sector_size - offset);
 	folio = brd_lookup_folio(brd, sector);
-	if (folio) {
-		src = kmap_local_folio(folio, offset);
-		memcpy(dst, src, copy);
-		kunmap_local(src);
-	} else
+	if (folio)
+		memcpy_from_folio(dst, folio, offset, copy);
+	else
 		memset(dst, 0, copy);
-
-	if (copy < n) {
-		dst += copy;
-		sector += copy >> SECTOR_SHIFT;
-		copy = n - copy;
-		folio = brd_lookup_folio(brd, sector);
-		if (folio) {
-			src = kmap_local_folio(folio, 0);
-			memcpy(dst, src, copy);
-			kunmap_local(src);
-		} else
-			memset(dst, 0, copy);
-	}
 }
 
 /*