scsi: target: pscsi: Clean up after failure in pscsi_map_sg()
authorMartin Wilck <mwilck@suse.com>
Tue, 23 Mar 2021 21:24:31 +0000 (22:24 +0100)
committerMartin K. Petersen <martin.petersen@oracle.com>
Thu, 25 Mar 2021 03:19:23 +0000 (23:19 -0400)
If pscsi_map_sg() fails, make sure to drop references to already allocated
bios.

Link: https://lore.kernel.org/r/20210323212431.15306-2-mwilck@suse.com
Reviewed-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Lee Duncan <lduncan@suse.com>
Signed-off-by: Martin Wilck <mwilck@suse.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
drivers/target/target_core_pscsi.c

index 6fa9fddc2e1e097f9a79333b3149ca79828dcb7b..9ee797b8cb7eae116922be7e6c5421cce4adea53 100644 (file)
@@ -938,6 +938,14 @@ new_bio:
 
        return 0;
 fail:
+       if (bio)
+               bio_put(bio);
+       while (req->bio) {
+               bio = req->bio;
+               req->bio = bio->bi_next;
+               bio_put(bio);
+       }
+       req->biotail = NULL;
        return TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE;
 }