Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp3100744ybi; Thu, 18 Jul 2019 21:02:52 -0700 (PDT) X-Google-Smtp-Source: APXvYqw44DeZkM0BN74CdoIGaYev7gTQAalWVgkSIK3U5NoOutMDNIoHRj++I4z4pnAvACQsabkc X-Received: by 2002:a17:90a:8a17:: with SMTP id w23mr53874571pjn.139.1563508972247; Thu, 18 Jul 2019 21:02:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1563508972; cv=none; d=google.com; s=arc-20160816; b=Ltlg8pG9HEJeKQQC0hVf+Z27LamruLJI3sxT8/+WV/JuxlQ377wAgpK4TxHmI1M71J IvEie1y7xjFdGEmLTq9bR5ld42dh8aQQwLZvMpH5TVRN7JoEwRPIvRIUlA43f1qA56ul XRBNMLKLZ5E8BnWPSvy3pdmu13jBeQcUZXZPM0qfd5ZtOCtRAv0GFSVu7yi7d8VgAVGf PnmMHRaUWz7CodNVAE1kbzA4vHExdLfJFZ6ZBJ3HbNYrJfWFMZAIFwm6XyYVuDaghymO xQt+U6olRW51vKM0daQqUZ/vR2eLRVJxb8AIYLTCDThvSyRmaQ+hROBYphb8JMPItRq7 GIjw== 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=L37ZCTVgGMTDmsZpBaomEgGuc1Gbw+tvBKWs2PuzXzk=; b=d5oA4f40FWzvKoxRG8viGQhiqgQ9h+CMwVFKC5VJ+M8UBlXY6rFMrWHcP0fu7n/Aag 2+r71CM9m5ACIusYb1wCw2v1ye9R0p5p5vvQL1E6+htULSPzqPyQDrm13z7nO3iWt+5d 95oitHaNg7CW6oqURMkWPKoWBgQ9wHadfvhEq4L+j+U2XH81zCn+Zh++gmzBer8F/Z49 ezMc8UI5uSs5GwTQMgQdQewWSzUrw1fl/AFQRKfAgA8HfZ9BwbNRCMzPALxwmWMiiX7a oRaaokMJ/dQyGnz7l2I3LUd9pW5FCLTuPP303F+ORu6V4YXxRncfB9acxwVrhahbKX74 6BPA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=tI87Xu24; 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 r6si3409789pls.145.2019.07.18.21.02.36; Thu, 18 Jul 2019 21:02:52 -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=tI87Xu24; 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 S1728717AbfGSEBc (ORCPT + 99 others); Fri, 19 Jul 2019 00:01:32 -0400 Received: from mail.kernel.org ([198.145.29.99]:33142 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729409AbfGSEBZ (ORCPT ); Fri, 19 Jul 2019 00:01:25 -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 579B921873; Fri, 19 Jul 2019 04:01:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1563508884; bh=I17DrcFi7+urAICnpGho+Udc/SRWzTgx9Ys7b2roMz8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=tI87Xu24wtfN0JlayL0WoI+Ox7SvC9i+8npqGZ47T9MHdRQTf9+UJSQZZr7WUwP76 7sSGMN5WQYwOtLym0WtD7GKZAeujPFvHpbk9oGnHrGwfSFJ3tREMmWrVmaUsoSjSuP WONVyeY94r9yPT20eV9yGEgj+6jdVMY8WbkjL4o4= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Alan Mikhak , Christoph Hellwig , Sasha Levin , linux-nvme@lists.infradead.org, linux-riscv@lists.infradead.org Subject: [PATCH AUTOSEL 5.2 135/171] nvme-pci: check for NULL return from pci_alloc_p2pmem() Date: Thu, 18 Jul 2019 23:56:06 -0400 Message-Id: <20190719035643.14300-135-sashal@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190719035643.14300-1-sashal@kernel.org> References: <20190719035643.14300-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: Alan Mikhak [ 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 524d6bd6d095..5dfa067f6506 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