From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 742F0C433B4 for ; Fri, 9 Apr 2021 09:58:16 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5351161206 for ; Fri, 9 Apr 2021 09:58:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233812AbhDIJ61 (ORCPT ); Fri, 9 Apr 2021 05:58:27 -0400 Received: from mail.kernel.org ([198.145.29.99]:45122 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233038AbhDIJ4v (ORCPT ); Fri, 9 Apr 2021 05:56:51 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id D612C611C1; Fri, 9 Apr 2021 09:56:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1617962197; bh=/VG/p+NAkMVBBjXx6LRY9rwJA+QB77JrDnWMbMJHDDk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=BqA/JTTqn2qFcH6ln5+4zxIIjHYRaGZkoQ4BkbYIVLk3aiZX8nkdzN8HlF/kUgz8Y EJdG/DjUzKJ4MkdWkNQIybQBtKDjghbSF+6M7LJxwr+C2VmWO7qyRNgRsOClVQK68y 6viqQvdCZ9DXfwYdFTfibXw1BXCbbDc+XuYI30U8= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Christoph Hellwig , Lee Duncan , Martin Wilck , "Martin K. Petersen" , Sasha Levin Subject: [PATCH 4.19 10/18] scsi: target: pscsi: Clean up after failure in pscsi_map_sg() Date: Fri, 9 Apr 2021 11:53:38 +0200 Message-Id: <20210409095301.864124749@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210409095301.525783608@linuxfoundation.org> References: <20210409095301.525783608@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Martin Wilck [ Upstream commit 36fa766faa0c822c860e636fe82b1affcd022974 ] 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 Reviewed-by: Lee Duncan Signed-off-by: Martin Wilck Signed-off-by: Martin K. Petersen Signed-off-by: Sasha Levin --- 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 47d76c862014..02c4e3beb264 100644 --- a/drivers/target/target_core_pscsi.c +++ b/drivers/target/target_core_pscsi.c @@ -970,6 +970,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; } -- 2.30.2