From: Jeremy Kerr Date: Sat, 23 Sep 2023 18:06:40 +0000 (-0700) Subject: nvme: fw-download offset only describes FW offset, not file offset X-Git-Tag: v2.6~7 X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=3348f1772e57685a72d689998b93d50ad1621074;p=users%2Fsagi%2Fnvme-cli.git nvme: fw-download offset only describes FW offset, not file offset In e7ca3bcbdba, we (unintentionally) changed the semantics of the fw-download's --offset argument to also apply an offset to the source file. According to https://github.com/linux-nvme/nvme-cli/issues/2013, the old behaviour is useful when the source firmware image was provided in separate chunks. This change restored to the old hehaviour, where --offset only applies to the destination firmware buffer on the device. This means that the start of the source file will end up at the destination offset. Fixes: https://github.com/linux-nvme/nvme-cli/issues/2013 Signed-off-by: Jeremy Kerr --- diff --git a/nvme.c b/nvme.c index 150555f8..f2b3ef47 100644 --- a/nvme.c +++ b/nvme.c @@ -5001,7 +5001,7 @@ static int fw_download(int argc, char **argv, struct command *cmd, struct plugin _cleanup_nvme_dev_ struct nvme_dev *dev = NULL; _cleanup_file_ int fw_fd = -1; - unsigned int fw_size; + unsigned int fw_size, pos; int err; struct stat sb; void *fw_buf; @@ -5077,16 +5077,14 @@ static int fw_download(int argc, char **argv, struct command *cmd, struct plugin goto free; } - while (cfg.offset < fw_size) { - cfg.xfer = min(cfg.xfer, fw_size); + for (pos = 0; pos < fw_size; pos += cfg.xfer) { + cfg.xfer = min(cfg.xfer, fw_size - pos); - err = fw_download_single(dev, fw_buf + cfg.offset, fw_size, - cfg.offset, cfg.xfer, cfg.progress, - cfg.ignore_ovr); + err = fw_download_single(dev, fw_buf + pos, fw_size, + cfg.offset + pos, cfg.xfer, + cfg.progress, cfg.ignore_ovr); if (err) break; - - cfg.offset += cfg.xfer; } if (!err) {