Skip to contentSkip to conversation

commit: Add NULL check for overlay_bs

PATCH In review Kevin Wolf 3 participants 4 messages Jul 10, 2017 – Jul 11, 2017 Block layer

lore
Share & tools
lore

Kevin Wolf

author
#0 lore raw

PATCH 1/1 commit: Add NULL check for overlay_bs

I can't see how overlay_bs could become NULL with the current code, but other code in this function already checks it and we can make Coverity happy with this check, so let's add it.

---
 block/commit.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
block/commit.c +3 -1
index 774a8a5..50e7950 100644
@@ -90,7 +90,9 @@ static void commit_complete(BlockJob *job, void *opaque)
 
     /* Make sure overlay_bs and top stay around until bdrv_set_backing_hd() */
     bdrv_ref(top);
-    bdrv_ref(overlay_bs);
+    if (overlay_bs) {
+        bdrv_ref(overlay_bs);
+    }
 
     /* Remove base node parent that still uses BLK_PERM_WRITE/RESIZE before
      * the normal backing chain can be restored. */
Signature · 1 line
1.8.3.1
#1 lore raw
Quoted 25 lines · Kevin Wolf

I can't see how overlay_bs could become NULL with the current code, but other code in this function already checks it and we can make Coverity happy with this check, so let's add it.

---
 block/commit.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
block/commit.c +3 -2
index 774a8a5..50e7950 100644
@@ -90,7 +90,9 @@ static void commit_complete(BlockJob *job, void *opaque)
 
     /* Make sure overlay_bs and top stay around until bdrv_set_backing_hd() */
     bdrv_ref(top);
-    bdrv_ref(overlay_bs);
+    if (overlay_bs) {
+        bdrv_ref(overlay_bs);
+    }
 
     /* Remove base node parent that still uses BLK_PERM_WRITE/RESIZE before
      * the normal backing chain can be restored. */
--
Quoted 1 line

1.8.3.1

Commit 19ebd13ed45ad5d5f2 which added the bdrv_ref() call was cc qemu-stable; should we cc this fix too, or are you happy that it's definitely not actually triggerable in stable?

thanks
-- PMM

author
#2 lore raw
In reply to Peter Maydell

Am 10.07.2017 um 14:09 hat Peter Maydell geschrieben:

Quoted 23 lines · Kevin Wolf
Quoted 22 lines

I can't see how overlay_bs could become NULL with the current code, but other code in this function already checks it and we can make Coverity happy with this check, so let's add it.

---
 block/commit.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
block/commit.c +3 -1
index 774a8a5..50e7950 100644
@@ -90,7 +90,9 @@ static void commit_complete(BlockJob *job, void *opaque)
 
     /* Make sure overlay_bs and top stay around until bdrv_set_backing_hd() */
     bdrv_ref(top);
-    bdrv_ref(overlay_bs);
+    if (overlay_bs) {
+        bdrv_ref(overlay_bs);
+    }
 
Quoted 6 lines

block/commit.c static void commit_complete(BlockJob *job, void *opaque) · line 98

Quoted 2 lines
block/commit.c +0 -0
     /* Remove base node parent that still uses BLK_PERM_WRITE/RESIZE before
      * the normal backing chain can be restored. */

Commit 19ebd13ed45ad5d5f2 which added the bdrv_ref() call was cc qemu-stable; should we cc this fix too, or are you happy that it's definitely not actually triggerable in stable?

Okay, I'll add the CC, better safe than sorry.

Kevin