Skip to content

Commit 468e60f

Browse files
maurizio-lombardiigaw
authored andcommitted
nvme: Fix get-feature on big-endian systems
The `parse_and_open()` function uses `OPT_BYTE` to parse the feature_id and sel options. This means it writes a single byte to the memory locations for `feature_id` and `sel` in the `feat_cfg` struct. However, these fields were declared as `enum`, which typically has the size of an `int`. On big-endian architectures, writing a single byte to the address of an `int` modifies the most significant byte, resulting in an incorrect value being read. This caused the `get-feature` command to fail. The command only worked on little-endian systems. Fix the issue by changing the type for `feature_id` and `sel` to `__u8`. This ensures the fields are treated as single bytes, guaranteeing correct behavior on all architectures. Signed-off-by: Maurizio Lombardi <[email protected]>
1 parent 0d4aaa3 commit 468e60f

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

nvme.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,9 @@
7272
#include "malloc.h"
7373

7474
struct feat_cfg {
75-
enum nvme_features_id feature_id;
75+
__u8 feature_id; /* enum nvme_features_id */
76+
__u8 sel; /* enum nvme_get_features_sel */
7677
__u32 namespace_id;
77-
enum nvme_get_features_sel sel;
7878
__u32 cdw11;
7979
__u32 cdw12;
8080
__u8 uuid_index;

0 commit comments

Comments
 (0)