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.
Sponsored by: Netflix
Differential D41310
nvme: Eliminate redundant code imp on Aug 3 2023, 10:40 PM. Authored by Tags None Referenced Files
Subscribers
Details
get_admin_opcode_string and get_io_opcode_string are identical, but Sponsored by: Netflix
Diff Detail
Event TimelineComment Actions Aren't opcodes just 8 bits anyway? Seems like you could make these tables be indexed by the opcode and always have 256 entries with a fallback if the entry is NULL and avoid the loop. Granted, it's likely not a critical path anyway, but still: #define OPC_ENTRY(opc) \ [(opc)] = __STRING(opc) static const char *admin_opcodes[256] = { OPC_ENTRY(NVME_OPC_ABORT), .... }; static const char * get_opcode_string(const char **table, const char *default, uint8_t opc) { const char *s; s = table[opc]; return (s == NULL ? default : s); } static const char * get_admin_opcode_string(uint8_t opc) { return (get_opcode_string(admin_opcode, "ADMIN COMMAND", opc)); } Comment Actions I like @jhb 's table approach but would prefer the shorter string (i.e., RESERVATION REGISTER vs NVME_OPC_RESERVATION_REGISTER Comment Actions ok. trying jhb's suggstion on this commit breaks future commits, so that's a non-starter (at least more work than I think is worth) |