public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v4] staging: rts5208: Convert kmap() to kmap_local_page()
@ 2022-03-30 14:33 Fabio M. De Francesco
  2022-03-30 15:32 ` Dan Carpenter
  2022-03-30 21:11 ` Ira Weiny
  0 siblings, 2 replies; 3+ messages in thread
From: Fabio M. De Francesco @ 2022-03-30 14:33 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Benjamin Philip, Bart Van Assche,
	Martin K. Petersen, Eric W. Biederman, Colin Ian King,
	Samuel Sjöberg, Charlie Sands, linux-staging, linux-kernel,
	Dan Carpenter, ira.weiny, outreachy
  Cc: Fabio M. De Francesco

The use of kmap() is being deprecated in favor of kmap_local_page()
where it is feasible.

With kmap_local_page(), the mapping is per thread, CPU local and not
globally visible. Therefore rtsx_stor_access_xfer_buf() is a function
where the use of kmap_local_page() in place of kmap() is correctly
suited.

Convert to kmap_local_page() but, instead of open coding it, use the
helpers memcpy_to_page() and memcpy_from_page().

Make a minor change to a comment related to scatter-gather.

Signed-off-by: Fabio M. De Francesco <fmdefrancesco@gmail.com>
---

v1 -> v2: Rework the commit message and use the appropriate helpers
instead of open coding the use of kmap_local_page()/kunmap_local_page().
(Thanks to Ira Weiny <ira.weiny@intel.com>).

v2 -> v3: Use memcpy_{to,from}_page() arguments correctly.
(Thanks to Dan Carpenter <dan.carpenter@oracle.com>).

v3 -> v4: According to a suggestion by Ira Weiny, change the test
of a comment related to the use of scatter-gather.

 drivers/staging/rts5208/rtsx_transport.c | 12 +++++-------
 1 file changed, 5 insertions(+), 7 deletions(-)

diff --git a/drivers/staging/rts5208/rtsx_transport.c b/drivers/staging/rts5208/rtsx_transport.c
index 805dc18fac0a..d5ad49de4c56 100644
--- a/drivers/staging/rts5208/rtsx_transport.c
+++ b/drivers/staging/rts5208/rtsx_transport.c
@@ -55,9 +55,9 @@ unsigned int rtsx_stor_access_xfer_buf(unsigned char *buffer,
 		*offset += cnt;
 
 	/*
-	 * Using scatter-gather.  We have to go through the list one entry
-	 * at a time.  Each s-g entry contains some number of pages, and
-	 * each page has to be kmap()'ed separately.
+	 * Using scatter-gather. We have to go through the list one entry
+	 * at a time. Each s-g entry contains some number of pages which
+	 * have to be copied one at a time.
 	 */
 	} else {
 		struct scatterlist *sg =
@@ -92,13 +92,11 @@ unsigned int rtsx_stor_access_xfer_buf(unsigned char *buffer,
 			while (sglen > 0) {
 				unsigned int plen = min(sglen, (unsigned int)
 						PAGE_SIZE - poff);
-				unsigned char *ptr = kmap(page);
 
 				if (dir == TO_XFER_BUF)
-					memcpy(ptr + poff, buffer + cnt, plen);
+					memcpy_to_page(page, poff, buffer + cnt, plen);
 				else
-					memcpy(buffer + cnt, ptr + poff, plen);
-				kunmap(page);
+					memcpy_from_page(buffer + cnt, page, poff, plen);
 
 				/* Start at the beginning of the next page */
 				poff = 0;
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH v4] staging: rts5208: Convert kmap() to kmap_local_page()
  2022-03-30 14:33 [PATCH v4] staging: rts5208: Convert kmap() to kmap_local_page() Fabio M. De Francesco
@ 2022-03-30 15:32 ` Dan Carpenter
  2022-03-30 21:11 ` Ira Weiny
  1 sibling, 0 replies; 3+ messages in thread
From: Dan Carpenter @ 2022-03-30 15:32 UTC (permalink / raw)
  To: Fabio M. De Francesco
  Cc: Greg Kroah-Hartman, Benjamin Philip, Bart Van Assche,
	Martin K. Petersen, Eric W. Biederman, Colin Ian King,
	Samuel Sjöberg, Charlie Sands, linux-staging, linux-kernel,
	ira.weiny, outreachy

On Wed, Mar 30, 2022 at 04:33:31PM +0200, Fabio M. De Francesco wrote:
> The use of kmap() is being deprecated in favor of kmap_local_page()
> where it is feasible.
> 
> With kmap_local_page(), the mapping is per thread, CPU local and not
> globally visible. Therefore rtsx_stor_access_xfer_buf() is a function
> where the use of kmap_local_page() in place of kmap() is correctly
> suited.
> 
> Convert to kmap_local_page() but, instead of open coding it, use the
> helpers memcpy_to_page() and memcpy_from_page().
> 
> Make a minor change to a comment related to scatter-gather.
> 
> Signed-off-by: Fabio M. De Francesco <fmdefrancesco@gmail.com>
> ---

LGTM.

Reviewed-by: Dan Carpenter <dan.carpenter@oracle.com>

regards,
dan carpenter


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH v4] staging: rts5208: Convert kmap() to kmap_local_page()
  2022-03-30 14:33 [PATCH v4] staging: rts5208: Convert kmap() to kmap_local_page() Fabio M. De Francesco
  2022-03-30 15:32 ` Dan Carpenter
@ 2022-03-30 21:11 ` Ira Weiny
  1 sibling, 0 replies; 3+ messages in thread
From: Ira Weiny @ 2022-03-30 21:11 UTC (permalink / raw)
  To: Fabio M. De Francesco
  Cc: Greg Kroah-Hartman, Benjamin Philip, Bart Van Assche,
	Martin K. Petersen, Eric W. Biederman, Colin Ian King,
	Samuel Sjöberg, Charlie Sands, linux-staging, linux-kernel,
	Dan Carpenter, outreachy

On Wed, Mar 30, 2022 at 04:33:31PM +0200, Fabio M. De Francesco wrote:
> The use of kmap() is being deprecated in favor of kmap_local_page()
> where it is feasible.
> 
> With kmap_local_page(), the mapping is per thread, CPU local and not
> globally visible. Therefore rtsx_stor_access_xfer_buf() is a function
> where the use of kmap_local_page() in place of kmap() is correctly
> suited.
> 
> Convert to kmap_local_page() but, instead of open coding it, use the
> helpers memcpy_to_page() and memcpy_from_page().
> 
> Make a minor change to a comment related to scatter-gather.
> 
> Signed-off-by: Fabio M. De Francesco <fmdefrancesco@gmail.com>

Thanks!

Reviewed-by: Ira Weiny <ira.weiny@intel.com>

> ---
> 
> v1 -> v2: Rework the commit message and use the appropriate helpers
> instead of open coding the use of kmap_local_page()/kunmap_local_page().
> (Thanks to Ira Weiny <ira.weiny@intel.com>).
> 
> v2 -> v3: Use memcpy_{to,from}_page() arguments correctly.
> (Thanks to Dan Carpenter <dan.carpenter@oracle.com>).
> 
> v3 -> v4: According to a suggestion by Ira Weiny, change the test
> of a comment related to the use of scatter-gather.
> 
>  drivers/staging/rts5208/rtsx_transport.c | 12 +++++-------
>  1 file changed, 5 insertions(+), 7 deletions(-)
> 
> diff --git a/drivers/staging/rts5208/rtsx_transport.c b/drivers/staging/rts5208/rtsx_transport.c
> index 805dc18fac0a..d5ad49de4c56 100644
> --- a/drivers/staging/rts5208/rtsx_transport.c
> +++ b/drivers/staging/rts5208/rtsx_transport.c
> @@ -55,9 +55,9 @@ unsigned int rtsx_stor_access_xfer_buf(unsigned char *buffer,
>  		*offset += cnt;
>  
>  	/*
> -	 * Using scatter-gather.  We have to go through the list one entry
> -	 * at a time.  Each s-g entry contains some number of pages, and
> -	 * each page has to be kmap()'ed separately.
> +	 * Using scatter-gather. We have to go through the list one entry
> +	 * at a time. Each s-g entry contains some number of pages which
> +	 * have to be copied one at a time.
>  	 */
>  	} else {
>  		struct scatterlist *sg =
> @@ -92,13 +92,11 @@ unsigned int rtsx_stor_access_xfer_buf(unsigned char *buffer,
>  			while (sglen > 0) {
>  				unsigned int plen = min(sglen, (unsigned int)
>  						PAGE_SIZE - poff);
> -				unsigned char *ptr = kmap(page);
>  
>  				if (dir == TO_XFER_BUF)
> -					memcpy(ptr + poff, buffer + cnt, plen);
> +					memcpy_to_page(page, poff, buffer + cnt, plen);
>  				else
> -					memcpy(buffer + cnt, ptr + poff, plen);
> -				kunmap(page);
> +					memcpy_from_page(buffer + cnt, page, poff, plen);
>  
>  				/* Start at the beginning of the next page */
>  				poff = 0;
> -- 
> 2.34.1
> 

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-03-30 21:11 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-03-30 14:33 [PATCH v4] staging: rts5208: Convert kmap() to kmap_local_page() Fabio M. De Francesco
2022-03-30 15:32 ` Dan Carpenter
2022-03-30 21:11 ` Ira Weiny

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox