Skip to contentSkip to conversation

block: Assert that drv->bdrv_child_perm is set in bdrv_child_perm()

PATCH Applied Alberto Garcia 2 participants 3 messages Apr 4, 2019 – Apr 26, 2019

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 block: Assert that drv->bdrv_child_perm is set in bdrv_child_perm()

There is no need to check for this because all block drivers that have children implement bdrv_child_perm and all callers already ensure that bs->drv is set.

Furthermore, if this check would fail then the callers would end up with uninitialized values for nperm and nshared.

This patch replaces the check with an assertion.

---
 block.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)
block.c +4 -5
index 3050854528..5f92565692 100644
@@ -1742,11 +1742,10 @@ static void bdrv_child_perm(BlockDriverState *bs, BlockDriverState *child_bs,
                             uint64_t parent_perm, uint64_t parent_shared,
                             uint64_t *nperm, uint64_t *nshared)
 {
-    if (bs->drv && bs->drv->bdrv_child_perm) {
-        bs->drv->bdrv_child_perm(bs, c, role, reopen_queue,
-                                 parent_perm, parent_shared,
-                                 nperm, nshared);
-    }
+    assert(bs->drv && bs->drv->bdrv_child_perm);
+    bs->drv->bdrv_child_perm(bs, c, role, reopen_queue,
+                             parent_perm, parent_shared,
+                             nperm, nshared);
     /* TODO Take force_share from reopen_queue */
     if (child_bs && child_bs->force_share) {
         *nshared = BLK_PERM_ALL;
Signature · 1 line
2.11.0
#1 lore raw

ping

Quoted 36 lines · Alberto Garcia

There is no need to check for this because all block drivers that have children implement bdrv_child_perm and all callers already ensure that bs->drv is set.

Furthermore, if this check would fail then the callers would end up with uninitialized values for nperm and nshared.

This patch replaces the check with an assertion.

---
 block.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)
block.c +4 -5
index 3050854528..5f92565692 100644
@@ -1742,11 +1742,10 @@ static void bdrv_child_perm(BlockDriverState *bs, BlockDriverState *child_bs,
                             uint64_t parent_perm, uint64_t parent_shared,
                             uint64_t *nperm, uint64_t *nshared)
 {
-    if (bs->drv && bs->drv->bdrv_child_perm) {
-        bs->drv->bdrv_child_perm(bs, c, role, reopen_queue,
-                                 parent_perm, parent_shared,
-                                 nperm, nshared);
-    }
+    assert(bs->drv && bs->drv->bdrv_child_perm);
+    bs->drv->bdrv_child_perm(bs, c, role, reopen_queue,
+                             parent_perm, parent_shared,
+                             nperm, nshared);
     /* TODO Take force_share from reopen_queue */
     if (child_bs && child_bs->force_share) {
         *nshared = BLK_PERM_ALL;
Signature · 1 line
2.11.0
Applied
#2 lore raw
In reply to Alberto Garcia
Quoted 7 lines · Alberto Garcia

There is no need to check for this because all block drivers that have children implement bdrv_child_perm and all callers already ensure that bs->drv is set.

Furthermore, if this check would fail then the callers would end up with uninitialized values for nperm and nshared.

Quoted 6 lines

This patch replaces the check with an assertion.

---
 block.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)

Thanks, applied to my block branch:

https://git.xanclic.moe/XanClic/qemu/commits/branch/block

Max