Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp3801319ybi; Mon, 29 Jul 2019 12:54:27 -0700 (PDT) X-Google-Smtp-Source: APXvYqyPEhaGhfNjWErOAtbH3ngz/P/AceF9+2CIpQSp62/tc3mf3+RFakek25PEzDUfv7oWldGa X-Received: by 2002:aa7:9254:: with SMTP id 20mr39570589pfp.212.1564430067801; Mon, 29 Jul 2019 12:54:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564430067; cv=none; d=google.com; s=arc-20160816; b=AshoS0JxoTBTl67ahvo8g9ORtE1q8/TtRwWs65f8L1FhMsrJijMUvSjt2O1OZDrF5P /aI4tmQTtgReqlabBazmD1+lYfborJt9UyfOiKv5IeR87sMD/2gayfu2EdHPYuB1gEUh 5wnptdSVqkcaDdk+OCCdzNkdZD9iIMBoB+tQbMeRoUjB75i8p5KHxDoyVxC8rAmdy4w1 reBdj064UR3VqObCfxsyl4hf7NpAKPECEpAhm7LwJzjED+KsInmOWcoyv/DJ7V4kUW90 ABKmM5WQ3aKUFkPj/wwmr/nBx3EWait6WxOun0lBEa9ke1AhoM7cK8HzAXtRjPuTX74h J9IQ== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=UYmHdIRqrfOOMf3tKwgAfvCtLvSqwD0Id7/VYi2rvsM=; b=MmoQmesXnbVD1OVoaD7nb29hfbIi3hk3Vnh0dAGMTrT1R2MA3oyvCJPmI3hPLXSnfr 6D7246hPJ1Bltq3KDr+R2EyeD28qEEvTK1kD3o7ewn6LX1OyftiAOcUhGN3xQbIqd4Iv 3kobBCSxyUsOC3y0M03gyz07xt2SDPaaxR158r0+HMzGwnPugR34iOuw/O/AjEWAYtV9 wiWUKkkas0ekMfcJnpYW8QIdb4aP2lRvmVmOxLKnB0HGaNK9HAz++gjFZluP7QdYdKGz evJuC1f1Mo/wJDvlrFJDr+E4VkuScFIP2/JLM7kkjOwu2n40uS77GJbOaIJQop0u2Y5m Kxag== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="RGHn6vC/"; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 21si25130511pgh.148.2019.07.29.12.54.12; Mon, 29 Jul 2019 12:54:27 -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="RGHn6vC/"; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390826AbfG2Tvl (ORCPT + 99 others); Mon, 29 Jul 2019 15:51:41 -0400 Received: from mail.kernel.org ([198.145.29.99]:43162 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2403873AbfG2Tvj (ORCPT ); Mon, 29 Jul 2019 15:51:39 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 50E56204EC; Mon, 29 Jul 2019 19:51:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1564429898; bh=IdEMgGy0pL2VQ26yIXXQLlHAcV2TSQxywE3X7xeZwE8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=RGHn6vC/WtuCioAzjjinAmfdPfq9yVj+67xoAkK50/y57NZkaE5G65xnU3lzyrT02 wlXS+j7bVafDP8UsFTaUhDrnTxQwKprwKOyLaR8V1ttsHO6jH8SqBwqZafLS/F6WGS LE1EGlU5w63kLOfh4jA+YHTxh0M7/2GECpt7wPxQ= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Alan Mikhak , Christoph Hellwig , Sasha Levin Subject: [PATCH 5.2 132/215] nvme-pci: check for NULL return from pci_alloc_p2pmem() Date: Mon, 29 Jul 2019 21:22:08 +0200 Message-Id: <20190729190802.348929092@linuxfoundation.org> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190729190739.971253303@linuxfoundation.org> References: <20190729190739.971253303@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org [ Upstream commit bfac8e9f55cf62a000b643a0081488badbe92d96 ] Modify nvme_alloc_sq_cmds() to call pci_free_p2pmem() to free the memory it allocated using pci_alloc_p2pmem() in case pci_p2pmem_virt_to_bus() returns null. Makes sure not to call pci_free_p2pmem() if pci_alloc_p2pmem() returned NULL, which can happen if CONFIG_PCI_P2PDMA is not configured. The current implementation is not expected to leak since pci_p2pmem_virt_to_bus() is expected to fail only if pci_alloc_p2pmem() returns null. However, checking the return value of pci_alloc_p2pmem() is more explicit. Signed-off-by: Alan Mikhak Signed-off-by: Christoph Hellwig Signed-off-by: Sasha Levin --- drivers/nvme/host/pci.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/drivers/nvme/host/pci.c b/drivers/nvme/host/pci.c index f5bc1c30cef5..245b6e2151c1 100644 --- a/drivers/nvme/host/pci.c +++ b/drivers/nvme/host/pci.c @@ -1456,11 +1456,15 @@ static int nvme_alloc_sq_cmds(struct nvme_dev *dev, struct nvme_queue *nvmeq, if (qid && dev->cmb_use_sqes && (dev->cmbsz & NVME_CMBSZ_SQS)) { nvmeq->sq_cmds = pci_alloc_p2pmem(pdev, SQ_SIZE(depth)); - nvmeq->sq_dma_addr = pci_p2pmem_virt_to_bus(pdev, - nvmeq->sq_cmds); - if (nvmeq->sq_dma_addr) { - set_bit(NVMEQ_SQ_CMB, &nvmeq->flags); - return 0; + if (nvmeq->sq_cmds) { + nvmeq->sq_dma_addr = pci_p2pmem_virt_to_bus(pdev, + nvmeq->sq_cmds); + if (nvmeq->sq_dma_addr) { + set_bit(NVMEQ_SQ_CMB, &nvmeq->flags); + return 0; + } + + pci_free_p2pmem(pdev, nvmeq->sq_cmds, SQ_SIZE(depth)); } } -- 2.20.1