]> www.infradead.org Git - users/sagi/nvme-cli.git/commitdiff
plugins/ocp: Align ocp_smart_extended_log struct.
authorMinsik Jeon <hmi.jeon@samsung.com>
Wed, 11 Dec 2024 05:39:37 +0000 (14:39 +0900)
committerDaniel Wagner <wagi@monom.org>
Wed, 8 Jan 2025 08:37:31 +0000 (09:37 +0100)
If the dssd point, minor version are declared as __le16, the alignment
will be broken. Remove __packed keyword.
Change parameter void to ocp_smart_extended_log.

Reported-by: Steven Seungcheol Lee <sc108.lee@samsung.com>
Signed-off-by: Minsik Jeon <hmi.jeon@samsung.com>
plugins/ocp/ocp-print-json.c
plugins/ocp/ocp-print-stdout.c
plugins/ocp/ocp-print.c
plugins/ocp/ocp-print.h
plugins/ocp/ocp-smart-extended-log.h

index 34cfb7f2ed8c98ef0eefa6525e82a143bc352e5e..844a9590425d40b200f33e8890fdffe0b992e7b1 100644 (file)
@@ -144,6 +144,7 @@ static void json_smart_extended_log_v1(struct ocp_smart_extended_log *log)
        struct json_object *pmuw;
        struct json_object *pmur;
        uint16_t smart_log_ver = 0;
+       uint16_t dssd_version = 0;
        char guid[40];
 
        root = json_create_object();
@@ -231,10 +232,12 @@ static void json_smart_extended_log_v1(struct ocp_smart_extended_log *log)
        case 2 ... 3:
                json_object_add_value_uint(root, "Errata Version Field",
                                                log->dssd_errata_version);
+               memcpy(&dssd_version, log->dssd_point_version, sizeof(dssd_version));
                json_object_add_value_uint(root, "Point Version Field",
-                                               le16_to_cpu(log->dssd_point_version));
+                                               le16_to_cpu(dssd_version));
+               memcpy(&dssd_version, log->dssd_minor_version, sizeof(dssd_version));
                json_object_add_value_uint(root, "Minor Version Field",
-                                               le16_to_cpu(log->dssd_minor_version));
+                                               le16_to_cpu(dssd_version));
                json_object_add_value_uint(root, "Major Version Field",
                                                log->dssd_major_version);
                json_object_add_value_uint(root, "NVMe Base Errata Version",
@@ -255,6 +258,7 @@ static void json_smart_extended_log_v2(struct ocp_smart_extended_log *log)
        struct json_object *pmuw;
        struct json_object *pmur;
        uint16_t smart_log_ver = 0;
+       uint16_t dssd_version = 0;
        char guid[40];
 
        root = json_create_object();
@@ -342,10 +346,12 @@ static void json_smart_extended_log_v2(struct ocp_smart_extended_log *log)
        case 2 ... 3:
                json_object_add_value_uint(root, "errata_version_field",
                                                log->dssd_errata_version);
+               memcpy(&dssd_version, log->dssd_point_version, sizeof(dssd_version));
                json_object_add_value_uint(root, "point_version_field",
-                                               le16_to_cpu(log->dssd_point_version));
+                                               le16_to_cpu(dssd_version));
+               memcpy(&dssd_version, log->dssd_minor_version, sizeof(dssd_version));
                json_object_add_value_uint(root, "minor_version_field",
-                                               le16_to_cpu(log->dssd_minor_version));
+                                               le16_to_cpu(dssd_version));
                json_object_add_value_uint(root, "major_version_field",
                                                log->dssd_major_version);
                json_object_add_value_uint(root, "nvme_base_errata_version",
index 51a8f60c08a5567161b3470b19a1d17c086c928b..dab9ecffeafe629aecfd39026a6d0512bad553d4 100644 (file)
@@ -100,6 +100,7 @@ static void stdout_fw_activation_history(const struct fw_activation_history *fw_
 static void stdout_smart_extended_log(struct ocp_smart_extended_log *log, unsigned int version)
 {
        uint16_t smart_log_ver = 0;
+       uint16_t dssd_version = 0;
 
        printf("SMART Cloud Attributes :-\n");
 
@@ -175,10 +176,12 @@ static void stdout_smart_extended_log(struct ocp_smart_extended_log *log, unsign
        case 2 ... 3:
                printf("  Errata Version Field                          %d\n",
                        log->dssd_errata_version);
+               memcpy(&dssd_version, log->dssd_point_version, sizeof(dssd_version));
                printf("  Point Version Field                           %"PRIu16"\n",
-                       le16_to_cpu(log->dssd_point_version));
+                       le16_to_cpu(dssd_version));
+               memcpy(&dssd_version, log->dssd_minor_version, sizeof(dssd_version));
                printf("  Minor Version Field                           %"PRIu16"\n",
-                       le16_to_cpu(log->dssd_minor_version));
+                       le16_to_cpu(dssd_version));
                printf("  Major Version Field                           %d\n",
                        log->dssd_major_version);
                printf("  NVMe Base Errata Version                      %d\n",
index eb6c4d137cb15d97e623acfaf5d8aad712298ef9..31037db946d14a44bd9f56dddaa0e4bdddd56da8 100644 (file)
@@ -36,9 +36,10 @@ void ocp_fw_act_history(const struct fw_activation_history *fw_history, nvme_pri
        ocp_print(fw_act_history, flags, fw_history);
 }
 
-void ocp_smart_extended_log(void *data, unsigned int version, nvme_print_flags_t flags)
+void ocp_smart_extended_log(struct ocp_smart_extended_log *log, unsigned int version,
+               nvme_print_flags_t flags)
 {
-       ocp_print(smart_extended_log, flags, data, version);
+       ocp_print(smart_extended_log, flags, log, version);
 }
 
 void ocp_show_telemetry_log(struct ocp_telemetry_parse_options *options, nvme_print_flags_t flags)
index 8836dd51c2cd24d0184b28ece11d5e476be77822..e9ede1c09ecd869dbe53b4689e92879cfafd5e1d 100644 (file)
@@ -37,7 +37,8 @@ static inline struct ocp_print_ops *ocp_get_json_print_ops(nvme_print_flags_t fl
 
 void ocp_show_hwcomp_log(struct hwcomp_log *log, __u32 id, bool list, nvme_print_flags_t flags);
 void ocp_fw_act_history(const struct fw_activation_history *fw_history, nvme_print_flags_t flags);
-void ocp_smart_extended_log(void *data, unsigned int version, nvme_print_flags_t flags);
+void ocp_smart_extended_log(struct ocp_smart_extended_log *log, unsigned int version,
+               nvme_print_flags_t flags);
 void ocp_show_telemetry_log(struct ocp_telemetry_parse_options *options, nvme_print_flags_t flags);
 void ocp_c3_log(struct nvme_dev *dev, struct ssd_latency_monitor_log *log_data,
                nvme_print_flags_t flags);
index 9b190d7ef2ab302f70f555b8a5e1dc2fd9324b03..8d1682abe1a3e428cfd5b3c7e9fb6cae544cff0d 100644 (file)
@@ -58,7 +58,7 @@ struct plugin;
  * @log_page_version:                  Log page version
  * @log_page_guid:                     Log page GUID
  */
-struct __packed ocp_smart_extended_log {
+struct ocp_smart_extended_log {
        __u8   physical_media_units_written[16];        /* [15:0] */
        __u8   physical_media_units_read[16];           /* [31:16] */
        __u8   bad_user_nand_blocks_raw[6];             /* [37:32] */
@@ -77,8 +77,8 @@ struct __packed ocp_smart_extended_log {
        __u8   thermal_throttling_event_count;          /* [96] */
        __u8   thermal_throttling_current_status;       /* [97] */
        __u8   dssd_errata_version;                     /* [98] */
-       __le16 dssd_point_version;                      /* [100:99] */
-       __le16 dssd_minor_version;                      /* [102:101] */
+       __u8   dssd_point_version[2];                   /* [100:99] */
+       __u8   dssd_minor_version[2];                   /* [102:101] */
        __u8   dssd_major_version;                      /* [103] */
        __le64 pcie_correctable_err_count;              /* [111:104] */
        __le32 incomplete_shoutdowns;                   /* [115:112] */