From patchwork Fri Nov 9 10:13:36 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maurizio Lombardi X-Patchwork-Id: 10675677 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 3F3DD13AD for ; Fri, 9 Nov 2018 10:13:40 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2FE2D2BC88 for ; Fri, 9 Nov 2018 10:13:40 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 24AAF2DC35; Fri, 9 Nov 2018 10:13:40 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.2 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI,SUBJ_OBFU_PUNCT_FEW autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D5DAB2E8F4 for ; Fri, 9 Nov 2018 10:13:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727653AbeKITxd (ORCPT ); Fri, 9 Nov 2018 14:53:33 -0500 Received: from mx1.redhat.com ([209.132.183.28]:47008 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727532AbeKITxd (ORCPT ); Fri, 9 Nov 2018 14:53:33 -0500 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 5BA6E307DACB; Fri, 9 Nov 2018 10:13:39 +0000 (UTC) Received: from manaslu.redhat.com (unknown [10.33.36.19]) by smtp.corp.redhat.com (Postfix) with ESMTP id DD24C6015E; Fri, 9 Nov 2018 10:13:37 +0000 (UTC) From: Maurizio Lombardi To: target-devel@vger.kernel.org Cc: mchristi@redhat.com, martin.petersen@oracle.com Subject: [PATCH] target: fix a memory leak in pscsi_map_sg() Date: Fri, 9 Nov 2018 11:13:36 +0100 Message-Id: <1541758416-30607-1-git-send-email-mlombard@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.42]); Fri, 09 Nov 2018 10:13:39 +0000 (UTC) Sender: target-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: target-devel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP If blk_rq_append_bio() fails, the bio should be released before returning. This patch also removes a "bio = NULL" assignment which is not needed because the bio pointer will be immediatly reassigned after the jump. Signed-off-by: Maurizio Lombardi --- drivers/target/target_core_pscsi.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/drivers/target/target_core_pscsi.c b/drivers/target/target_core_pscsi.c index 47d76c8..432361e 100644 --- a/drivers/target/target_core_pscsi.c +++ b/drivers/target/target_core_pscsi.c @@ -948,11 +948,6 @@ static inline struct bio *pscsi_get_bio(int nr_vecs) goto fail; } - /* - * Clear the pointer so that another bio will - * be allocated with pscsi_get_bio() above. - */ - bio = NULL; goto new_bio; } @@ -970,6 +965,8 @@ static inline struct bio *pscsi_get_bio(int nr_vecs) return 0; fail: + if (bio) + bio_put(bio); return TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE; }