Skip to contentSkip to conversation

staging: rts5208: Convert kmap() to kmap_local_page()

PATCH Superseded Fabio M. De Francesco 2 participants 3 messages Mar 29, 2022 Staging

v2 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 staging: rts5208: Convert kmap() to kmap_local_page()

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().

---

v1 -> v2: Rework the commit message and use the appropriate helpers instead of open coding the use of kmap_local_page()/kunmap_local_page(). (Many thanks to Ira Weiny <[email protected]>).

 drivers/staging/rts5208/rtsx_transport.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
drivers/staging/rts5208/rtsx_transport.c +2 -4
index 805dc18fac0a..56b6cc845619 100644
@@ -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, 0, buffer + cnt, plen);
 				else
-					memcpy(buffer + cnt, ptr + poff, plen);
-				kunmap(page);
+					memcpy_from_page(buffer + cnt, page + poff, 0, plen);
 
 				/* Start at the beginning of the next page */
 				poff = 0;
Signature · 1 line
2.34.1
#1 lore raw

drivers/staging/rts5208/rtsx_transport.c unsigned int rtsx_stor_access_xfer_buf(unsigned char *buffer, · line 97

Quoted 13 lines · Fabio M. De Francesco
drivers/staging/rts5208/rtsx_transport.c +1 -2
index 805dc18fac0a..56b6cc845619 100644
@@ -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, 0, buffer + cnt, plen);

You meant:

	memcpy_to_page(page, poff, buffer + cnt, plen);

drivers/staging/rts5208/rtsx_transport.c unsigned int rtsx_stor_access_xfer_buf(unsigned char *buffer, · line 99

Quoted 4 lines
drivers/staging/rts5208/rtsx_transport.c +1 -2
 				else
-					memcpy(buffer + cnt, ptr + poff, plen);
-				kunmap(page);
+					memcpy_from_page(buffer + cnt, page + poff, 0, plen);

Same.

regards,
dan carpenter

#2 lore raw
Quoted 11 lines · On marted? 29 marzo 2022 11:18:27 CEST Dan Carpenter wrote:
Quoted 10 lines · Fabio M. De Francesco
drivers/staging/rts5208/rtsx_transport.c +0 -1
index 805dc18fac0a..56b6cc845619 100644
@@ -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);
 
Quoted 8 lines

drivers/staging/rts5208/rtsx_transport.c unsigned int rtsx_stor_access_xfer_buf(unsigned char *buffer, · line 97

Quoted 3 lines
drivers/staging/rts5208/rtsx_transport.c +1 -1
 				if (dir == TO_XFER_BUF)
-					memcpy(ptr + poff, buffer + cnt, plen);
+					memcpy_to_page(page + poff, 0, buffer + cnt, plen);

You meant:

	memcpy_to_page(page, poff, buffer + cnt, plen);

Yes, correct. I meant exactly what you wrote.

It's the first time that I use these API and, after 30 seconds look at their prototypes, I thought that either have the same semantics.

I don't yet know if I'm wrong. However, even if either were correct, yours would be more consistent and elegant. Therefore, I am going to change these calls and submit a v3.

Thanks for your review,

Fabio M. De Francesco

Quoted 11 lines

drivers/staging/rts5208/rtsx_transport.c unsigned int rtsx_stor_access_xfer_buf(unsigned char *buffer, · line 99

Quoted 4 lines
drivers/staging/rts5208/rtsx_transport.c +1 -2
 				else
-					memcpy(buffer + cnt, ptr + poff, plen);
-				kunmap(page);
+					memcpy_from_page(buffer + cnt, page + poff, 0, plen);

Same.

regards,
dan carpenter