Skip to contentSkip to conversation

bdrv_inc_in_flight and bdrv_dec_in_flight:

PATCH In review Zhengui Li 3 participants 3 messages Jun 10, 2017 – Jun 11, 2017 Block layer

lore
Share & tools
lore

Zhengui Li

author
#0 lore raw

PATCH 1/1 bdrv_inc_in_flight and bdrv_dec_in_flight:

Avoid empty pointer access if the bs is NULL.

---
 block/io.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)
block/io.c +7 -3
index ed31810..b12d7cf 100644
@@ -492,7 +492,9 @@ static bool tracked_request_overlaps(BdrvTrackedRequest *req,
 
 void bdrv_inc_in_flight(BlockDriverState *bs)
 {
-    atomic_inc(&bs->in_flight);
+    if (bs) {
+        atomic_inc(&bs->in_flight);
+    }
 }
 
 static void dummy_bh_cb(void *opaque)
@@ -508,8 +510,10 @@ void bdrv_wakeup(BlockDriverState *bs)
 
 void bdrv_dec_in_flight(BlockDriverState *bs)
 {
-    atomic_dec(&bs->in_flight);
-    bdrv_wakeup(bs);
+    if (bs) {
+        atomic_dec(&bs->in_flight);
+        bdrv_wakeup(bs);
+    }
 }
 
 static bool coroutine_fn wait_serialising_requests(BdrvTrackedRequest *self)
Signature · 1 line
1.8.3.1
#1 lore raw
Quoted 1 line · Zhengui Li

Avoid empty pointer access if the bs is NULL.

Looks like most (if not all) of the places these are called dereference bs anyway. Can it ever be NULL? Perhaps a check for each of those case (if any) would be a better idea.

Quoted 38 lines

---
block/io.c | 10 +++++++---

1 file changed, 7 insertions(+), 3 deletions(-)
block/io.c +7 -3
index ed31810..b12d7cf 100644
@@ -492,7 +492,9 @@ static bool tracked_request_overlaps(BdrvTrackedRequest *req,
 
 void bdrv_inc_in_flight(BlockDriverState *bs)
 {
-    atomic_inc(&bs->in_flight);
+    if (bs) {
+        atomic_inc(&bs->in_flight);
+    }
 }
 
 static void dummy_bh_cb(void *opaque)
@@ -508,8 +510,10 @@ void bdrv_wakeup(BlockDriverState *bs)
 
 void bdrv_dec_in_flight(BlockDriverState *bs)
 {
-    atomic_dec(&bs->in_flight);
-    bdrv_wakeup(bs);
+    if (bs) {
+        atomic_dec(&bs->in_flight);
+        bdrv_wakeup(bs);
+    }
 }
 
 static bool coroutine_fn wait_serialising_requests(BdrvTrackedRequest *self)
Signature · 1 line
1.8.3.1
#2 lore raw
In reply to Zhengui Li
Quoted 6 lines · Zhengui Li

Avoid empty pointer access if the bs is NULL.

---
 block/io.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

NACK; this is fixing a symptom, not the problem. If you have a coredump due to a bad caller passing in NULL, then post the backtrace and let's fix the broken caller instead.

Signature · 3 lines
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3266
Virtualization:  qemu.org | libvirt.org