Skip to contentSkip to conversation

pflash: Fix blk_pread_nonzeroes()

PATCH In review Kevin Wolf 3 participants 3 messages Mar 7, 2023

lore
Share & tools
lore

Kevin Wolf

author
#0 lore raw

PATCH 1/1 pflash: Fix blk_pread_nonzeroes()

Commit a4b15a8b introduced a new function blk_pread_nonzeroes(). Instead of reading directly from the root node of the BlockBackend, it reads from its 'file' child node. This can happen to mostly work for raw images (as long as the 'raw' format driver is in use, but not actually doing anything), but it breaks everything else.

Fix it to read from the root node instead.

Fixes a4b15a8b9ef25b44fa92a4825312622600c1f37c
---
 hw/block/block.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
hw/block/block.c +1 -2
index af0710e477..9f52ee6e72 100644
@@ -39,8 +39,7 @@ static int blk_pread_nonzeroes(BlockBackend *blk, hwaddr size, void *buf)
             return ret;
         }
         if (!(ret & BDRV_BLOCK_ZERO)) {
-            ret = bdrv_pread(bs->file, offset, bytes,
-                             (uint8_t *) buf + offset, 0);
+            ret = blk_pread(blk, offset, bytes, (uint8_t *) buf + offset, 0);
             if (ret < 0) {
                 return ret;
             }
Signature · 1 line
2.39.2
#1 lore raw
Quoted 11 lines · Kevin Wolf

Commit a4b15a8b introduced a new function blk_pread_nonzeroes(). Instead of reading directly from the root node of the BlockBackend, it reads from its 'file' child node. This can happen to mostly work for raw images (as long as the 'raw' format driver is in use, but not actually doing anything), but it breaks everything else.

Fix it to read from the root node instead.

Fixes a4b15a8b9ef25b44fa92a4825312622600c1f37c

I have a couple of extra patches for 8.0. I can include this fix if no one does.

Thanks,

C.

Quoted 18 lines
---
  hw/block/block.c | 3 +--
  1 file changed, 1 insertion(+), 2 deletions(-)
hw/block/block.c +1 -2
index af0710e477..9f52ee6e72 100644
@@ -39,8 +39,7 @@ static int blk_pread_nonzeroes(BlockBackend *blk, hwaddr size, void *buf)
              return ret;
          }
          if (!(ret & BDRV_BLOCK_ZERO)) {
-            ret = bdrv_pread(bs->file, offset, bytes,
-                             (uint8_t *) buf + offset, 0);
+            ret = blk_pread(blk, offset, bytes, (uint8_t *) buf + offset, 0);
              if (ret < 0) {
                  return ret;
              }
Tested-by on v1 1/1
#2 lore raw
In reply to Kevin Wolf
Quoted 7 lines · Kevin Wolf

Commit a4b15a8b introduced a new function blk_pread_nonzeroes(). Instead of reading directly from the root node of the BlockBackend, it reads from its 'file' child node. This can happen to mostly work for raw images (as long as the 'raw' format driver is in use, but not actually doing anything), but it breaks everything else.

Fix it to read from the root node instead.

Thanks for preparing the patch.

It seems to work fine, so:

Quoted 1 line
Fixes a4b15a8b9ef25b44fa92a4825312622600c1f37c

I think this should be:

Fixes a4b15a8b9e ("pflash: Only read non-zero parts of backend image")
Quoted 3 lines

---

Thanks,
Maciej