Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp2692961ybl; Thu, 29 Aug 2019 11:33:28 -0700 (PDT) X-Google-Smtp-Source: APXvYqzby4deBkOG44Got9I0SiZnOfcQkP9imbpc2u6faIm1qqk0orDmazB5t8SwQylJawEf5sUK X-Received: by 2002:a62:28c:: with SMTP id 134mr13528397pfc.194.1567103608602; Thu, 29 Aug 2019 11:33:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1567103608; cv=none; d=google.com; s=arc-20160816; b=oCuEH8oWlXmIKMedqI4pXzHuPgqUCyn7WkVeeSaJN7aDbT1BFVd0OsGQFq5qee5lxx glHS8MQ8diVbfeY6a5MbzfeGEjY7oEtkQmISgO4SzXtBzfuT7uEDyLTNSOkgwYJtshy1 yNO+aIk9qH9Vkadp98TdX6bZY3XO40NTXVQhzRyVl7EWD7vgC7Gyza46ymzID2wSGM1i PlxxKeaoRPomOUEII0exqfLKibfv+CvuH8hincrar6/qIplbkxoCV6ozUX2OWuPBIqEs fUWx6FIKRwE8f+Rnucf2JzhxP5JmTPzOwOdWnWqx62+cnQj/AM94o9JS+l24+ZsSa7Cr maTw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=CN/8+KWuxzpSA6l+NBBEScJJ1BhozRGceeIyH2qJ8Ts=; b=pbpy8afx7HKHOe/TVLfXs3GLlBDuO0Ot2JsqFQqvQ8vYaDVKdmBSMZzO2IktR0w1bB 4jGyXzbEBoxbDcw7stPUFS76y7jtsHoScRhMKrfB+hIZd2/lqNdoxtzxQ/B67k/YnJo2 /FRU/ZM+nTrpYWXzvEiWoNyN5XGccRqQNtBgjaaW98aVnWNS2QjZOjqgNDHHrCy0nNEn 9LQs3Prk00VVC6XvjZN5asfiKFpqlK4wdu9SogpXvk2tFU5zm1PcWXnQGF8pHMvQDBFY LHn7d7nLkZyghLYVXN1fTO9foP7rqb8btt938eLMJdRcMgapOdLpb/VB65S9VIw4NVwm G5cA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="cqWA/JAi"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d4si2759484pjj.28.2019.08.29.11.33.12; Thu, 29 Aug 2019 11:33:28 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="cqWA/JAi"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729048AbfH2Sc1 (ORCPT + 99 others); Thu, 29 Aug 2019 14:32:27 -0400 Received: from mail.kernel.org ([198.145.29.99]:55744 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728697AbfH2SOC (ORCPT ); Thu, 29 Aug 2019 14:14:02 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 5E89121874; Thu, 29 Aug 2019 18:14:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1567102441; bh=Jh3vaT2aKc/EF6gk4cCrzt8r2KBPKvpZzdfcK2NepqQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=cqWA/JAiUBQtJmMjH36Ipsivdj1V4qWnS4rulFY+F139JHkLkG5lFyLtjVRxQXgU/ clUuCIi7hk9oT4b2k8WubvczpKHVo3ORBpo/JlQRc3+FcR/LK/lPGGIcocVxyUPQSU DYidsrQzHq4nYwj1AMDEK94sfenKQyKNbn+3Qm7k= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Bill Kuzeja , Bill Kuzeja , Himanshu Madhani , "Martin K . Petersen" , Sasha Levin , linux-scsi@vger.kernel.org Subject: [PATCH AUTOSEL 5.2 29/76] scsi: qla2xxx: Fix gnl.l memory leak on adapter init failure Date: Thu, 29 Aug 2019 14:12:24 -0400 Message-Id: <20190829181311.7562-29-sashal@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190829181311.7562-1-sashal@kernel.org> References: <20190829181311.7562-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Bill Kuzeja [ Upstream commit 26fa656e9a0cbccddf7db132ea020d2169dbe46e ] If HBA initialization fails unexpectedly (exiting via probe_failed:), we may fail to free vha->gnl.l. So that we don't attempt to double free, set this pointer to NULL after a free and check for NULL at probe_failed: so we know whether or not to call dma_free_coherent. Signed-off-by: Bill Kuzeja Acked-by: Himanshu Madhani Signed-off-by: Martin K. Petersen Signed-off-by: Sasha Levin --- drivers/scsi/qla2xxx/qla_attr.c | 2 ++ drivers/scsi/qla2xxx/qla_os.c | 11 ++++++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/drivers/scsi/qla2xxx/qla_attr.c b/drivers/scsi/qla2xxx/qla_attr.c index 8d560c562e9c0..6b7b390b2e522 100644 --- a/drivers/scsi/qla2xxx/qla_attr.c +++ b/drivers/scsi/qla2xxx/qla_attr.c @@ -2956,6 +2956,8 @@ qla24xx_vport_delete(struct fc_vport *fc_vport) dma_free_coherent(&ha->pdev->dev, vha->gnl.size, vha->gnl.l, vha->gnl.ldma); + vha->gnl.l = NULL; + vfree(vha->scan.l); if (vha->qpair && vha->qpair->vp_idx == vha->vp_idx) { diff --git a/drivers/scsi/qla2xxx/qla_os.c b/drivers/scsi/qla2xxx/qla_os.c index d056f5e7cf930..794478e5f7ec8 100644 --- a/drivers/scsi/qla2xxx/qla_os.c +++ b/drivers/scsi/qla2xxx/qla_os.c @@ -3440,6 +3440,12 @@ qla2x00_probe_one(struct pci_dev *pdev, const struct pci_device_id *id) return 0; probe_failed: + if (base_vha->gnl.l) { + dma_free_coherent(&ha->pdev->dev, base_vha->gnl.size, + base_vha->gnl.l, base_vha->gnl.ldma); + base_vha->gnl.l = NULL; + } + if (base_vha->timer_active) qla2x00_stop_timer(base_vha); base_vha->flags.online = 0; @@ -3673,7 +3679,7 @@ qla2x00_remove_one(struct pci_dev *pdev) if (!atomic_read(&pdev->enable_cnt)) { dma_free_coherent(&ha->pdev->dev, base_vha->gnl.size, base_vha->gnl.l, base_vha->gnl.ldma); - + base_vha->gnl.l = NULL; scsi_host_put(base_vha->host); kfree(ha); pci_set_drvdata(pdev, NULL); @@ -3713,6 +3719,8 @@ qla2x00_remove_one(struct pci_dev *pdev) dma_free_coherent(&ha->pdev->dev, base_vha->gnl.size, base_vha->gnl.l, base_vha->gnl.ldma); + base_vha->gnl.l = NULL; + vfree(base_vha->scan.l); if (IS_QLAFX00(ha)) @@ -4817,6 +4825,7 @@ struct scsi_qla_host *qla2x00_create_host(struct scsi_host_template *sht, "Alloc failed for scan database.\n"); dma_free_coherent(&ha->pdev->dev, vha->gnl.size, vha->gnl.l, vha->gnl.ldma); + vha->gnl.l = NULL; scsi_remove_host(vha->host); return NULL; } -- 2.20.1