]> www.infradead.org Git - users/sagi/nvme-cli.git/commitdiff
nvme: use NVME_GET_FEATURES_SEL definitions
authorTokunori Ikegami <ikegami.t@gmail.com>
Sun, 15 Sep 2024 06:07:58 +0000 (15:07 +0900)
committerDaniel Wagner <wagi@monom.org>
Mon, 23 Sep 2024 09:18:42 +0000 (11:18 +0200)
These changes are to replace the hardcoded SEL values.

Signed-off-by: Tokunori Ikegami <ikegami.t@gmail.com>
nvme-print.c
nvme.c
nvme.h

index 404b470ef35b5459e5f00b7b7d6fec89155004b1..a1dd797bd8ad7d091c234ab86292eb7712f30787 100644 (file)
@@ -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 ab5602d01563fa2485bee857851355b1c574623c..baeccb1835bb266f1994d33741eac14aa9e23ea6 100644 (file)
--- 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 cae43452145e6f673964dc064c1fb719cf5b8d50..4cd72efd504c22d1b7543ea78d98c9796378e324 100644 (file)
--- 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) {