git: e83fdf8bb391 - main - fix big-endian platforms after 6733401935f8

Chuck Tuffli chuck at FreeBSD.org
Fri Jan 8 22:44:48 UTC 2021


The branch main has been updated by chuck:

URL: https://cgit.FreeBSD.org/src/commit/?id=e83fdf8bb391579fa422d34663cd8c1f82a00dc0

commit e83fdf8bb391579fa422d34663cd8c1f82a00dc0
Author:     Chuck Tuffli <chuck at FreeBSD.org>
AuthorDate: 2021-01-08 22:36:37 +0000
Commit:     Chuck Tuffli <chuck at FreeBSD.org>
CommitDate: 2021-01-08 22:41:45 +0000

    fix big-endian platforms after 6733401935f8
    
    The NVMe byte-swap routines for big-endian platforms used memcpy() to
    move the unaligned 64-bit value into a temp register to byte swap it.
    Instead of introducing a dependency, manually byte-swap the values in
    place.
    
    Point hat:      me
---
 sys/dev/nvme/nvme.h | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)

diff --git a/sys/dev/nvme/nvme.h b/sys/dev/nvme/nvme.h
index 67d02ba73fd8..b28a8d4348db 100644
--- a/sys/dev/nvme/nvme.h
+++ b/sys/dev/nvme/nvme.h
@@ -2042,16 +2042,20 @@ static inline void
 nvme_device_self_test_swapbytes(struct nvme_device_self_test_page *s __unused)
 {
 #if _BYTE_ORDER != _LITTLE_ENDIAN
-	uint64_t failing_lba;
-	uint32_t r;
+	uint8_t *tmp;
+	uint32_t r, i;
+	uint8_t b;
 
 	for (r = 0; r < 20; r++) {
 		s->result[r].poh = le64toh(s->result[r].poh);
 		s->result[r].nsid = le32toh(s->result[r].nsid);
 		/* Unaligned 64-bit loads fail on some architectures */
-		memcpy(&failing_lba, s->result[r].failing_lba, sizeof(failing_lba));
-		failing_lba = le64toh(failing_lba);
-		memcpy(s->result[r].failing_lba, &failing_lba, sizeof(failing_lba));
+		tmp = s->result[r].failing_lba;
+		for (i = 0; i < 4; i++) {
+			b = tmp[i];
+			tmp[i] = tmp[7-i];
+			tmp[7-i] = b;
+		}
 	}
 #endif
 }


More information about the dev-commits-src-all mailing list