diff --git a/nvme-print.c b/nvme-print.c index 404b470ef..a1dd797bd 100644 --- a/nvme-print.c +++ b/nvme-print.c @@ -962,13 +962,20 @@ const char *nvme_register_to_string(int reg) const char *nvme_select_to_string(int sel) { switch (sel) { - case 0: return "Current"; - case 1: return "Default"; - case 2: return "Saved"; - case 3: return "Supported capabilities"; - case 8: return "Changed"; - default: return "Reserved"; + case NVME_GET_FEATURES_SEL_CURRENT: + return "Current"; + case NVME_GET_FEATURES_SEL_DEFAULT: + return "Default"; + case NVME_GET_FEATURES_SEL_SAVED: + return "Saved"; + case NVME_GET_FEATURES_SEL_SUPPORTED: + return "Supported capabilities"; + case NVME_GET_FEATURES_SEL_CHANGED: + return "Changed"; + default: + break; } + return "Reserved"; } void nvme_show_select_result(enum nvme_features_id fid, __u32 result) diff --git a/nvme.c b/nvme.c index 40c6c5943..8e3a68017 100644 --- a/nvme.c +++ b/nvme.c @@ -4622,17 +4622,17 @@ static int get_feature_id_changed(struct nvme_dev *dev, struct feat_cfg cfg, _cleanup_free_ void *buf_def = NULL; if (changed) - cfg.sel = 0; + cfg.sel = NVME_GET_FEATURES_SEL_CURRENT; err = get_feature_id(dev, &cfg, &buf, &result); if (!err && changed) { - cfg.sel = 1; + cfg.sel = NVME_GET_FEATURES_SEL_DEFAULT; err_def = get_feature_id(dev, &cfg, &buf_def, &result_def); } if (changed) - cfg.sel = 8; + cfg.sel = NVME_GET_FEATURES_SEL_CHANGED; if (err || !changed || err_def || result != result_def || (buf && buf_def && !strcmp(buf, buf_def))) @@ -4651,7 +4651,7 @@ static int get_feature_ids(struct nvme_dev *dev, struct feat_cfg cfg) int status = 0; enum nvme_status_type type = NVME_STATUS_TYPE_NVME; - if (cfg.sel == 8) + if (cfg.sel == NVME_GET_FEATURES_SEL_CHANGED) changed = true; if (cfg.feature_id) @@ -4701,7 +4701,7 @@ static int get_feature(int argc, char **argv, struct command *cmd, struct feat_cfg cfg = { .feature_id = 0, .namespace_id = 0, - .sel = 0, + .sel = NVME_GET_FEATURES_SEL_CURRENT, .data_len = 0, .raw_binary = false, .cdw11 = 0, @@ -4734,7 +4734,7 @@ static int get_feature(int argc, char **argv, struct command *cmd, } } - if (cfg.sel > 8) { + if (cfg.sel > NVME_GET_FEATURES_SEL_CHANGED) { nvme_show_error("invalid 'select' param:%d", cfg.sel); return -EINVAL; } diff --git a/nvme.h b/nvme.h index cae434521..4cd72efd5 100644 --- a/nvme.h +++ b/nvme.h @@ -92,6 +92,8 @@ struct nvme_config { OPT_END() \ } +#define NVME_GET_FEATURES_SEL_CHANGED 8 + static inline int __dev_fd(struct nvme_dev *dev, const char *func, int line) { if (dev->type != NVME_DEV_DIRECT) {