From: Keith Busch Date: Tue, 3 Aug 2021 14:41:58 +0000 (-0700) Subject: remove string representation timestamp set_feature X-Git-Tag: v2.0-rc0~53^2~37 X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=ebc960ae74bc2ebbbfae6eae51de41a879706906;p=users%2Fsagi%2Fnvme-cli.git remove string representation timestamp set_feature Require the integer representation be provided for this to avoid any mismatched sizing problems. Signed-off-by: Keith Busch --- diff --git a/nvme.c b/nvme.c index 2d89c7d6..3815ef86 100644 --- a/nvme.c +++ b/nvme.c @@ -3827,8 +3827,6 @@ static int set_feature(int argc, char **argv, struct command *cmd, struct plugin __u32 result; void *buf = NULL; int fd, ffd = STDIN_FILENO; - char *endptr = NULL; - uint64_t number = 0; struct config { char *file; @@ -3906,7 +3904,12 @@ static int set_feature(int argc, char **argv, struct command *cmd, struct plugin } if (buf) { - /* if feature ID is 0x0E, get timestamp value by -v option */ + /* + * Use the '-v' value for the timestamp feature if provided as + * a convenience since it can often fit in 4-bytes. The user + * should use the buffer method if the value exceeds this + * length. + */ if (NVME_FEAT_FID_TIMESTAMP == cfg.feature_id && cfg.value) { memcpy(buf, &cfg.value, NVME_FEAT_TIMESTAMP_DATA_SIZE); } else { @@ -3919,6 +3922,7 @@ static int set_feature(int argc, char **argv, struct command *cmd, struct plugin goto free; } } + err = read(ffd, (void *)buf, cfg.data_len); if (err < 0) { err = -errno; @@ -3926,12 +3930,6 @@ static int set_feature(int argc, char **argv, struct command *cmd, struct plugin " file: %s\n", strerror(errno)); goto close_ffd; } - /* if feature ID is 0x0E, then change string from file to integer */ - if (NVME_FEAT_FID_TIMESTAMP == cfg.feature_id) { - number = strtoul(buf, &endptr, STRTOUL_AUTO_BASE); - memset(buf, 0, cfg.data_len); - memcpy(buf, &number, NVME_FEAT_TIMESTAMP_DATA_SIZE); - } } }