Date: Sat, 31 Jul 2021 00:21:31 GMT From: Warner Losh <imp@FreeBSD.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org Subject: git: f5a43e10fe4d - stable/12 - fix big-endian platforms after 6733401935f8 Message-ID: <202107310021.16V0LVCt052090@gitrepo.freebsd.org>
next in thread | raw e-mail | index | archive | help
The branch stable/12 has been updated by imp: URL: https://cgit.FreeBSD.org/src/commit/?id=f5a43e10fe4d0fcc13f64d14e4c6c7ba285d8b3c commit f5a43e10fe4d0fcc13f64d14e4c6c7ba285d8b3c Author: Chuck Tuffli <chuck@FreeBSD.org> AuthorDate: 2021-01-08 22:36:37 +0000 Commit: Warner Losh <imp@FreeBSD.org> CommitDate: 2021-07-31 00:02:53 +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 (cherry picked from commit e83fdf8bb391579fa422d34663cd8c1f82a00dc0) --- 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 f42d1e9caa3b..2caf8171be5b 100644 --- a/sys/dev/nvme/nvme.h +++ b/sys/dev/nvme/nvme.h @@ -2053,16 +2053,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 }
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202107310021.16V0LVCt052090>