virtio-blk: fix NULL checking in virtblk_alloc_req()
Subsystems (4)
PATCH 1/1 virtio-blk: fix NULL checking in virtblk_alloc_req()
Smatch complains about the inconsistent NULL checking here. Fix it to return NULL on failure.
---
This is only needed in linux-next.
drivers/block/virtio_blk.c +4 -3
@@ -90,10 +90,11 @@ static inline struct virtblk_req *virtblk_alloc_req(struct virtio_blk *vblk,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; }
Michael S. Tsirkin
maintainerQuoted 4 lines · Dan Carpenter
Smatch complains about the inconsistent NULL checking here. Fix it to return NULL on failure.
Signed-off-by Dan Carpenter <[email protected]>
ACK
Quoted 2 lines
---
This is only needed in linux-next.
Yes upstream is OK.
linux-next picks up stuff from rusty's patch queue so presumably this can be folded into patch that triggered this.
Quoted 6 lines
drivers/block/virtio_blk.c +0
-0
drivers/block/virtio_blk.c static inline struct virtblk_req *virtblk_alloc_req(struct virtio_blk *vblk, · line 96
Quoted 9 lines
drivers/block/virtio_blk.c +2
-3@@ -90,10 +90,11 @@ static inline struct virtblk_req *virtblk_alloc_req(struct virtio_blk *vblk,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;
Smatch is right to complain: on memory allocation
failure this will dereference NULL.
Quoted 5 lines
drivers/block/virtio_blk.c +2
-0+if (use_bio) +sg_init_table (vbr->sg, vblk->sg_elems);return vbr; }
Quoted 6 lines · Dan Carpenter
Smatch complains about the inconsistent NULL checking here. Fix it to return NULL on failure.
Signed-off-by Dan Carpenter <[email protected]>---
This is only needed in linux-next.
Nice!
Quoted 9 lines
drivers/block/virtio_blk.c +0
-1@@ -90,10 +90,11 @@ static inline struct virtblk_req *virtblk_alloc_req(struct virtio_blk *vblk,struct virtblk_req *vbr; vbr =mempool_alloc (vblk->pool, gfp_mask); -if (vbr && use_bio)
drivers/block/virtio_blk.c static inline struct virtblk_req *virtblk_alloc_req(struct virtio_blk *vblk, · line 100
Quoted 10 lines
drivers/block/virtio_blk.c +4
-2-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; }
But it turns out that "vbr->vblk = vblk;" assignment is important :)
Fixed and applied,
Rusty.
Quoted 24 lines · Rusty Russell
Quoted 6 lines · Dan Carpenter
Smatch complains about the inconsistent NULL checking here. Fix it to return NULL on failure.
Signed-off-by Dan Carpenter <[email protected]>---
This is only needed in linux-next.Nice!
Quoted 13 lines
drivers/block/virtio_blk.c +2
-2@@ -90,10 +90,11 @@ static inline struct virtblk_req *virtblk_alloc_req(struct virtio_blk *vblk,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 ;
Quoted 8 lines
drivers/block/virtio_blk.c static inline struct virtblk_req *virtblk_alloc_req(struct virtio_blk *vblk, · line 100
Quoted 6 lines
drivers/block/virtio_blk.c +2
-1- vbr->vblk = vblk; +if (use_bio) +sg_init_table (vbr->sg, vblk->sg_elems);return vbr; }But it turns out that "
vbr->vblk= vblk;" assignment is important :)
I was just replying ;-)
Quoted 1 line
Fixed and applied,
Thanks Rusty!
Signature · 1 line
Asias
Hello Dan,
Quoted 4 lines · Dan Carpenter
Smatch complains about the inconsistent NULL checking here. Fix it to return NULL on failure.
Signed-off-by Dan Carpenter <[email protected]>
Thanks for catching this.
Quoted 8 lines
---
This is only needed in linux-next.drivers/block/virtio_blk.c +0
-0
drivers/block/virtio_blk.c static inline struct virtblk_req *virtblk_alloc_req(struct virtio_blk *vblk, · line 96
Quoted 9 lines
drivers/block/virtio_blk.c +2
-3@@ -90,10 +90,11 @@ static inline struct virtblk_req *virtblk_alloc_req(struct virtio_blk *vblk,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;
The assignment of vbr->vblk is needed.
Quoted 5 lines
drivers/block/virtio_blk.c +2
-0+if (use_bio) +sg_init_table (vbr->sg, vblk->sg_elems);return vbr; }
Signature · 1 line
Asias