]> www.infradead.org Git - users/sagi/nvme-cli.git/commitdiff
nvme: fw-download offset only describes FW offset, not file offset
authorJeremy Kerr <jk@codeconstruct.com.au>
Sat, 23 Sep 2023 18:06:40 +0000 (11:06 -0700)
committerDaniel Wagner <wagi@monom.org>
Wed, 27 Sep 2023 06:11:42 +0000 (08:11 +0200)
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 <jk@codeconstruct.com.au>
nvme.c

diff --git a/nvme.c b/nvme.c
index 150555f80a68eae4851a5a06605bdb3118d55e72..f2b3ef4728f8188ef56f96961cc6207153a170d0 100644 (file)
--- 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) {