Skip to contentSkip to conversation

dm-log-writes: Use pointers from memcpy() calls for assignments in two functions

PATCH In review Markus Elfring 2 participants 2 messages Oct 31, 2025 – Nov 3, 2025

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 dm-log-writes: Use pointers from memcpy() calls for assignments in two functions

From: Markus Elfring <[email protected]>
Date: Fri, 31 Oct 2025 20:20:56 +0100

A pointer was assigned to a variable in two function implementations. The same pointer was used for the destination parameter of a memcpy() call. This function is documented in the way that the same value is returned. Thus convert separate statements into a direct variable assignment for the return value from a memory copy action.

The source code was transformed by using the Coccinelle software.

---
 drivers/md/dm-log-writes.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
drivers/md/dm-log-writes.c +2 -4
index 7bb7174f8f4f..b450bdadfaf2 100644
@@ -232,8 +232,7 @@ static int write_metadata(struct log_writes_c *lc, void *entry,
 		goto error;
 	}
 
-	ptr = kmap_local_page(page);
-	memcpy(ptr, entry, entrylen);
+	ptr = memcpy(kmap_local_page(page), entry, entrylen);
 	if (datalen)
 		memcpy(ptr + entrylen, data, datalen);
 	memset(ptr + entrylen + datalen, 0,
@@ -287,8 +286,7 @@ static int write_inline_data(struct log_writes_c *lc, void *entry,
 				goto error_bio;
 			}
 
-			ptr = kmap_local_page(page);
-			memcpy(ptr, data, pg_datalen);
+			ptr = memcpy(kmap_local_page(page), data, pg_datalen);
 			if (pg_sectorlen > pg_datalen)
 				memset(ptr + pg_datalen, 0, pg_sectorlen - pg_datalen);
 			kunmap_local(ptr);
Signature · 1 line
2.51.1
maintainer
#1 lore raw

Hi

I think that the code is more readable as it is.

Putting two function calls on one line doesn't make it easier to read.

Mikulas

Quoted 43 lines · Markus Elfring

From: Markus Elfring <[email protected]>
Date: Fri, 31 Oct 2025 20:20:56 +0100

A pointer was assigned to a variable in two function implementations. The same pointer was used for the destination parameter of a memcpy() call. This function is documented in the way that the same value is returned. Thus convert separate statements into a direct variable assignment for the return value from a memory copy action.

The source code was transformed by using the Coccinelle software.

---
 drivers/md/dm-log-writes.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
drivers/md/dm-log-writes.c +2 -4
index 7bb7174f8f4f..b450bdadfaf2 100644
@@ -232,8 +232,7 @@ static int write_metadata(struct log_writes_c *lc, void *entry,
 		goto error;
 	}
 
-	ptr = kmap_local_page(page);
-	memcpy(ptr, entry, entrylen);
+	ptr = memcpy(kmap_local_page(page), entry, entrylen);
 	if (datalen)
 		memcpy(ptr + entrylen, data, datalen);
 	memset(ptr + entrylen + datalen, 0,
@@ -287,8 +286,7 @@ static int write_inline_data(struct log_writes_c *lc, void *entry,
 				goto error_bio;
 			}
 
-			ptr = kmap_local_page(page);
-			memcpy(ptr, data, pg_datalen);
+			ptr = memcpy(kmap_local_page(page), data, pg_datalen);
 			if (pg_sectorlen > pg_datalen)
 				memset(ptr + pg_datalen, 0, pg_sectorlen - pg_datalen);
 			kunmap_local(ptr);
Signature · 1 line
2.51.1