Received: by 2002:ac0:bc90:0:0:0:0:0 with SMTP id a16csp4177402img; Tue, 26 Mar 2019 04:41:48 -0700 (PDT) X-Google-Smtp-Source: APXvYqwH5Nxb1rYndTI6z/wqbfX9srE0YSzjH0wNs8OcBsl8W3471DXj7SS+QQgEiTRL6mQIFdYk X-Received: by 2002:a17:902:988e:: with SMTP id s14mr18286926plp.167.1553600508500; Tue, 26 Mar 2019 04:41:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1553600508; cv=none; d=google.com; s=arc-20160816; b=i6CfrB1pZTrWfvLriSbhBASdeDYVKjjw1PTXk7BOhvh9L7+lJiJata2fQEtvAjtIrJ 6+0p8Q0c552uFD6bg1J39B0uf4GErRIR9pmVbKgIULwmQ0ePfTWkkVNjk4qDwVV8SkqH 74n6KMkrvzURNNaAZsJ+eMLO4cdok3YSLNDmQ/xjWSy9W/Yt0WUaFs3o6f2mRaqtpCBd w11qSATVBzkdTHtZ6icZXVemxw8jN8mPmFhBA2v5XdqhdGU5+WcvRysD+XOVOaZCjz/H x7rYFIL2yQozOIME+dWoyajvXI7lZdNrpzNMlnDx9jqarosKQYIdhkK4WFIx5gNebO5U LGOw== 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 :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject; bh=auaZC99/PaIuWBOZiHnhtbgLx/yik8Ko6nmu5aXXuuU=; b=hAwHk4vWa2wzGeJqKhzi0hpN9B2JE254PeWfhO6wMBTCLTaKz4Qn3yR2z+nU+voEM5 B/90pelkiNX8rFsqCzwi3wmpm327mQhZiaBAq+lQSWBDQdd45UoUSAW5fHAX67qwUnjA lWnbzdxOrPL8Z9yRCICopnipMXfC/annjI0MjLbvax+D3WdUeCMkPM/9GywAMqvLrAkm Jnq+38KK9zFfD/wPhsaA5OS9HcFJDz/RN6ZJiuTm6Tv4ZSoxAGzBo7kaYDNac7bbegR9 chFzTpCWKSlpmLTLupKbrLx+FYw9UQyQZ1Ge42J9R/BCWcovV05KdV+4OvjGomda/l3H htVQ== ARC-Authentication-Results: i=1; mx.google.com; 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 r18si16944625pgd.585.2019.03.26.04.41.33; Tue, 26 Mar 2019 04:41:48 -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; 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 S1730377AbfCZLkz (ORCPT + 99 others); Tue, 26 Mar 2019 07:40:55 -0400 Received: from foss.arm.com ([217.140.101.70]:34926 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725948AbfCZLkz (ORCPT ); Tue, 26 Mar 2019 07:40:55 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id B2FCD1596; Tue, 26 Mar 2019 04:40:54 -0700 (PDT) Received: from [10.1.196.69] (e112269-lin.cambridge.arm.com [10.1.196.69]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 43E933F59C; Tue, 26 Mar 2019 04:40:53 -0700 (PDT) Subject: Re: [PATCH v3] PCI: xilinx: Check for __get_free_pages() failure To: Kangjie Lu Cc: Lorenzo Pieralisi , linux-pci@vger.kernel.org, Michal Simek , linux-kernel@vger.kernel.org, pakki001@umn.edu, Bjorn Helgaas , linux-arm-kernel@lists.infradead.org References: <20190325215105.GB24180@google.com> <20190325221909.26315-1-kjlu@umn.edu> From: Steven Price Message-ID: <377aa504-7bfa-4e8d-5db7-fce01c931e28@arm.com> Date: Tue, 26 Mar 2019 11:40:51 +0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.5.1 MIME-Version: 1.0 In-Reply-To: <20190325221909.26315-1-kjlu@umn.edu> Content-Type: text/plain; charset=utf-8 Content-Language: en-GB Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 25/03/2019 22:19, Kangjie Lu wrote: > If __get_free_pages() fails, the patch returns -ENOMEM to avoid As Bjorn suggested s/the patch returns/return/ would suffice and is slightly easier to read. But I'm happy either way. > NULL pointer dereference. > > Signed-off-by: Kangjie Lu Reviewed-by: Steven Price > --- > v3: remove "unlikely", as suggested by Bjorn Helgaas. > v2: caller is redefined to accept the error code, as suggested by > Steven Price > --- > drivers/pci/controller/pcie-xilinx.c | 12 ++++++++++-- > 1 file changed, 10 insertions(+), 2 deletions(-) > > diff --git a/drivers/pci/controller/pcie-xilinx.c b/drivers/pci/controller/pcie-xilinx.c > index 9bd1a35cd5d8..abc214e94f7c 100644 > --- a/drivers/pci/controller/pcie-xilinx.c > +++ b/drivers/pci/controller/pcie-xilinx.c > @@ -336,14 +336,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 */ > @@ -498,6 +503,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); > @@ -526,7 +532,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; >