diff mbox series

[v2,2/2] target: pscsi: cleanup after failure in pscsi_map_sg()

Message ID 20210323212431.15306-2-mwilck@suse.com (mailing list archive)
State Accepted
Commit 36fa766faa0c822c860e636fe82b1affcd022974
Headers show
Series [v2,1/2] target: pscsi: avoid OOM in pscsi_map_sg() | expand

Commit Message

Martin Wilck March 23, 2021, 9:24 p.m. UTC
From: Martin Wilck <mwilck@suse.com>

If pscsi_map_sg() fails, make sure to drop references to already
allocated bios.

Signed-off-by: Martin Wilck <mwilck@suse.com>
---
 drivers/target/target_core_pscsi.c | 8 ++++++++
 1 file changed, 8 insertions(+)

Comments

Christoph Hellwig March 24, 2021, 7:14 a.m. UTC | #1
On Tue, Mar 23, 2021 at 10:24:31PM +0100, mwilck@suse.com wrote:
> From: Martin Wilck <mwilck@suse.com>
> 
> If pscsi_map_sg() fails, make sure to drop references to already
> allocated bios.
> 
> Signed-off-by: Martin Wilck <mwilck@suse.com>

Looks good,

Reviewed-by: Christoph Hellwig <hch@lst.de>
Lee Duncan March 24, 2021, 5:24 p.m. UTC | #2
On 3/23/21 2:24 PM, mwilck@suse.com wrote:
> From: Martin Wilck <mwilck@suse.com>
> 
> If pscsi_map_sg() fails, make sure to drop references to already
> allocated bios.
> 
> Signed-off-by: Martin Wilck <mwilck@suse.com>
> ---
>  drivers/target/target_core_pscsi.c | 8 ++++++++
>  1 file changed, 8 insertions(+)
> 
> diff --git a/drivers/target/target_core_pscsi.c b/drivers/target/target_core_pscsi.c
> index 977362d..1c9aeab 100644
> --- a/drivers/target/target_core_pscsi.c
> +++ b/drivers/target/target_core_pscsi.c
> @@ -937,6 +937,14 @@ pscsi_map_sg(struct se_cmd *cmd, struct scatterlist *sgl, u32 sgl_nents,
>  
>  	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;
>  }
>  
> 

Reviewed-by: Lee Duncan <lduncan@suse.com>
diff mbox series

Patch

diff --git a/drivers/target/target_core_pscsi.c b/drivers/target/target_core_pscsi.c
index 977362d..1c9aeab 100644
--- a/drivers/target/target_core_pscsi.c
+++ b/drivers/target/target_core_pscsi.c
@@ -937,6 +937,14 @@  pscsi_map_sg(struct se_cmd *cmd, struct scatterlist *sgl, u32 sgl_nents,
 
 	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;
 }