git: edd23e4dc013 - main - nvme: Eliminate redundant code
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Mon, 07 Aug 2023 22:45:40 UTC
The branch main has been updated by imp:
URL: https://cgit.FreeBSD.org/src/commit/?id=edd23e4dc013fe9603138271a2cfaa68732055ba
commit edd23e4dc013fe9603138271a2cfaa68732055ba
Author: Warner Losh <imp@FreeBSD.org>
AuthorDate: 2023-08-07 22:35:15 +0000
Commit: Warner Losh <imp@FreeBSD.org>
CommitDate: 2023-08-07 22:44:31 +0000
nvme: Eliminate redundant code
get_admin_opcode_string and get_io_opcode_string are identical, but
start with different tables. Use a helper routine that takes an argument
to implement these instead. A future commit will refine this further.
Sponsored by: Netflix
Reviewed by: chuck, mav, jhb
Differential Revision: https://reviews.freebsd.org/D41310
---
sys/dev/nvme/nvme_qpair.c | 23 ++++++++---------------
1 file changed, 8 insertions(+), 15 deletions(-)
diff --git a/sys/dev/nvme/nvme_qpair.c b/sys/dev/nvme/nvme_qpair.c
index 40c9f6053b95..988c82741592 100644
--- a/sys/dev/nvme/nvme_qpair.c
+++ b/sys/dev/nvme/nvme_qpair.c
@@ -99,12 +99,8 @@ static struct nvme_opcode_string io_opcode[] = {
};
static const char *
-get_admin_opcode_string(uint16_t opc)
+get_opcode_string(struct nvme_opcode_string *entry, uint16_t opc)
{
- struct nvme_opcode_string *entry;
-
- entry = admin_opcode;
-
while (entry->opc != 0xFFFF) {
if (entry->opc == opc)
return (entry->str);
@@ -114,18 +110,15 @@ get_admin_opcode_string(uint16_t opc)
}
static const char *
-get_io_opcode_string(uint16_t opc)
+get_admin_opcode_string(uint16_t opc)
{
- struct nvme_opcode_string *entry;
-
- entry = io_opcode;
+ return (get_opcode_string(admin_opcode, opc));
+}
- while (entry->opc != 0xFFFF) {
- if (entry->opc == opc)
- return (entry->str);
- entry++;
- }
- return (entry->str);
+static const char *
+get_io_opcode_string(uint16_t opc)
+{
+ return (get_opcode_string(io_opcode, opc));
}
static void