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=-8.7 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham 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 E3479C31E45 for ; Thu, 13 Jun 2019 16:22:29 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id B93DB2147A for ; Thu, 13 Jun 2019 16:22:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1560442949; bh=kUI4Ey98f9c4Iojg9qzUYMcrgvXf+9czDL3HOV3FGKQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=NrNCcCcopTkvyDGZPeidkTpSZ2w4PDcYhXAd+YzU5zxJlio2Sbj8gY1O/DZVEMR1i j4DgWxBNOelQCx9oAhTesdK17nMAttN3jVzlG+enLM5jbYn7nnzvwLU6slGPFqmlbJ izuwRRLxhxRly+uPpEHIWONA6Vwq6HcPyy3mFMmA= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2392216AbfFMQW2 (ORCPT ); Thu, 13 Jun 2019 12:22:28 -0400 Received: from mail.kernel.org ([198.145.29.99]:55730 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731043AbfFMIiR (ORCPT ); Thu, 13 Jun 2019 04:38:17 -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 BA1D421473; Thu, 13 Jun 2019 08:38:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1560415097; bh=kUI4Ey98f9c4Iojg9qzUYMcrgvXf+9czDL3HOV3FGKQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=OUs73mncoQyV7kJx3tswNRZVJWvQQSe7SD4jAr+Jc2yvWNLC0Cpy28udhWmuA6q+N 8iiqU6ayy4s+PDQNm49QzwaAp3vnI1v8ObTFS1yOF/JMe3WUS1aPYM0wZ9HH67iRQf IiazGqx7ws/3bp7kaTiAx35Qof3er07xjPhgrz+8= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Kangjie Lu , Lorenzo Pieralisi , Steven Price , Mukesh Ojha , Sasha Levin Subject: [PATCH 4.14 69/81] PCI: xilinx: Check for __get_free_pages() failure Date: Thu, 13 Jun 2019 10:33:52 +0200 Message-Id: <20190613075654.047460645@linuxfoundation.org> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190613075649.074682929@linuxfoundation.org> References: <20190613075649.074682929@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 699ca30162686bf305cdf94861be02eb0cf9bda2 ] If __get_free_pages() fails, return -ENOMEM to avoid a NULL pointer dereference. Signed-off-by: Kangjie Lu Signed-off-by: Lorenzo Pieralisi Reviewed-by: Steven Price Reviewed-by: Mukesh Ojha Signed-off-by: Sasha Levin --- drivers/pci/host/pcie-xilinx.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/drivers/pci/host/pcie-xilinx.c b/drivers/pci/host/pcie-xilinx.c index 29f024f0ed7f..a8a44afa81ec 100644 --- a/drivers/pci/host/pcie-xilinx.c +++ b/drivers/pci/host/pcie-xilinx.c @@ -338,14 +338,19 @@ static const struct irq_domain_ops msi_domain_ops = { * xilinx_pcie_enable_msi - Enable MSI support * @port: PCIe port information */ -static void xilinx_pcie_enable_msi(struct xilinx_pcie_port *port) +static int xilinx_pcie_enable_msi(struct xilinx_pcie_port *port) { phys_addr_t msg_addr; port->msi_pages = __get_free_pages(GFP_KERNEL, 0); + if (!port->msi_pages) + return -ENOMEM; + msg_addr = virt_to_phys((void *)port->msi_pages); pcie_write(port, 0x0, XILINX_PCIE_REG_MSIBASE1); pcie_write(port, msg_addr, XILINX_PCIE_REG_MSIBASE2); + + return 0; } /* INTx Functions */ @@ -500,6 +505,7 @@ static int xilinx_pcie_init_irq_domain(struct xilinx_pcie_port *port) struct device *dev = port->dev; struct device_node *node = dev->of_node; struct device_node *pcie_intc_node; + int ret; /* Setup INTx */ pcie_intc_node = of_get_next_child(node, NULL); @@ -528,7 +534,9 @@ static int xilinx_pcie_init_irq_domain(struct xilinx_pcie_port *port) return -ENODEV; } - xilinx_pcie_enable_msi(port); + ret = xilinx_pcie_enable_msi(port); + if (ret) + return ret; } return 0; -- 2.20.1