Subject: virtio-blk: fix NULL checking in virtblk_alloc_req()
From: Dan Carpenter <[email-masked]>
Date: Wed, 5 Sep 2012 15:32:53 +0300

Smatch complains about the inconsistent NULL checking here.  Fix it to
return NULL on failure.

Signed-off-by: Dan Carpenter <[email-masked]>
Signed-off-by: Rusty Russell <[email-masked]> (fixed accidental deletion)
---
 drivers/block/virtio_blk.c |    6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/block/virtio_blk.c b/drivers/block/virtio_blk.c
--- a/drivers/block/virtio_blk.c
+++ b/drivers/block/virtio_blk.c
@@ -90,10 +90,12 @@ static inline struct virtblk_req *virtbl
 	struct virtblk_req *vbr;
 
 	vbr = mempool_alloc(vblk->pool, gfp_mask);
-	if (vbr && use_bio)
-		sg_init_table(vbr->sg, vblk->sg_elems);
+	if (!vbr)
+		return NULL;
 
 	vbr->vblk = vblk;
+	if (use_bio)
+		sg_init_table(vbr->sg, vblk->sg_elems);
 
 	return vbr;
 }