Skip to content

Commit

Permalink
scsi: fnic: Fix memleak in vnic_dev_init_devcmd2
Browse files Browse the repository at this point in the history
When ioread32() returns 0xFFFFFFFF, we should execute cleanup functions
like other error handling paths before returning.

Link: https://lore.kernel.org/r/[email protected]
Acked-by: Karan Tilak Kumar <[email protected]>
Signed-off-by: Dinghao Liu <[email protected]>
Signed-off-by: Martin K. Petersen <[email protected]>
  • Loading branch information
dinghaoliu authored and martinkpetersen committed Jan 13, 2021
1 parent b2b0f16 commit d6e3ae7
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions drivers/scsi/fnic/vnic_dev.c
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,8 @@ static int vnic_dev_init_devcmd2(struct vnic_dev *vdev)
fetch_index = ioread32(&vdev->devcmd2->wq.ctrl->fetch_index);
if (fetch_index == 0xFFFFFFFF) { /* check for hardware gone */
pr_err("error in devcmd2 init");
return -ENODEV;
err = -ENODEV;
goto err_free_wq;
}

/*
Expand All @@ -460,7 +461,7 @@ static int vnic_dev_init_devcmd2(struct vnic_dev *vdev)
err = vnic_dev_alloc_desc_ring(vdev, &vdev->devcmd2->results_ring,
DEVCMD2_RING_SIZE, DEVCMD2_DESC_SIZE);
if (err)
goto err_free_wq;
goto err_disable_wq;

vdev->devcmd2->result =
(struct devcmd2_result *) vdev->devcmd2->results_ring.descs;
Expand All @@ -481,8 +482,9 @@ static int vnic_dev_init_devcmd2(struct vnic_dev *vdev)

err_free_desc_ring:
vnic_dev_free_desc_ring(vdev, &vdev->devcmd2->results_ring);
err_free_wq:
err_disable_wq:
vnic_wq_disable(&vdev->devcmd2->wq);
err_free_wq:
vnic_wq_free(&vdev->devcmd2->wq);
err_free_devcmd2:
kfree(vdev->devcmd2);
Expand Down

0 comments on commit d6e3ae7

Please sign in to comment.