diff mbox series

[RFC,2/8] brd: use memcpy_from_page() in copy_from_brd()

Message ID 20210207190425.38107-3-chaitanya.kulkarni@wdc.com (mailing list archive)
State New, archived
Headers show
Series use core page calls instead of kmaps | expand

Commit Message

Chaitanya Kulkarni Feb. 7, 2021, 7:04 p.m. UTC
Signed-off-by: Chaitanya Kulkarni <chaitanya.kulkarni@wdc.com>
---
 drivers/block/brd.c | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)

Comments

Ira Weiny Feb. 8, 2021, 4:35 a.m. UTC | #1
On Sun, Feb 07, 2021 at 11:04:19AM -0800, Chaitanya Kulkarni wrote:
> Signed-off-by: Chaitanya Kulkarni <chaitanya.kulkarni@wdc.com>
> ---
>  drivers/block/brd.c | 9 +++------
>  1 file changed, 3 insertions(+), 6 deletions(-)
> 
> diff --git a/drivers/block/brd.c b/drivers/block/brd.c
> index d41b7d489e9f..c1f6d768a1b3 100644
> --- a/drivers/block/brd.c
> +++ b/drivers/block/brd.c
> @@ -220,7 +220,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;
>  
> @@ -236,11 +235,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, offset, copy);

Why 'offset'?

Ira

> +		else
>  			memset(dst, 0, copy);
>  	}
>  }
> -- 
> 2.22.1
>
Chaitanya Kulkarni Feb. 8, 2021, 5:47 a.m. UTC | #2
>> @@ -236,11 +235,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, offset, copy);
> Why 'offset'?
Will fix it in the V1.
> Ira
>
>> +		else
>>  			memset(dst, 0, copy);
>>  	}
>>  }
>> -- 
>> 2.22.1
>>
diff mbox series

Patch

diff --git a/drivers/block/brd.c b/drivers/block/brd.c
index d41b7d489e9f..c1f6d768a1b3 100644
--- a/drivers/block/brd.c
+++ b/drivers/block/brd.c
@@ -220,7 +220,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;
 
@@ -236,11 +235,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, offset, copy);
+		else
 			memset(dst, 0, copy);
 	}
 }