From patchwork Tue Jan 31 15:09:00 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bjorn Helgaas X-Patchwork-Id: 9547469 X-Patchwork-Delegate: bhelgaas@google.com Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id C76EA60425 for ; Tue, 31 Jan 2017 15:19:59 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B8F6228179 for ; Tue, 31 Jan 2017 15:19:59 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id AB63528304; Tue, 31 Jan 2017 15:19:59 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D1EAE28179 for ; Tue, 31 Jan 2017 15:19:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751033AbdAaPT4 (ORCPT ); Tue, 31 Jan 2017 10:19:56 -0500 Received: from mail.kernel.org ([198.145.29.136]:52238 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750891AbdAaPTz (ORCPT ); Tue, 31 Jan 2017 10:19:55 -0500 Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id BB62B20145; Tue, 31 Jan 2017 15:09:04 +0000 (UTC) Received: from localhost (173-27-161-33.client.mchsi.com [173.27.161.33]) (using TLSv1.2 with cipher DHE-RSA-AES128-SHA (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 19761201EF; Tue, 31 Jan 2017 15:09:02 +0000 (UTC) Date: Tue, 31 Jan 2017 09:09:00 -0600 From: Bjorn Helgaas To: Shailendra Verma Cc: Zhou Wang , Gabriele Paoloni , Bjorn Helgaas , linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org, p.shailesh@samsung.com, ashish.kalra@samsung.com, Shailendra Verma Subject: Re: [PATCH] Pci: host - Fix possible NULL derefrence. Message-ID: <20170131150900.GB9942@bhelgaas-glaptop.roam.corp.google.com> References: <1485751775-29126-1-git-send-email-shailendra.v@samsung.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <1485751775-29126-1-git-send-email-shailendra.v@samsung.com> User-Agent: Mutt/1.5.21 (2010-09-15) X-Virus-Scanned: ClamAV using ClamSMTP Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Hi Shailendra, On Mon, Jan 30, 2017 at 10:19:35AM +0530, Shailendra Verma wrote: > of_match_device could return NULL, and so can cause a NULL > pointer dereference later. > > Signed-off-by: Shailendra Verma > --- > drivers/pci/host/pcie-hisi.c | 4 ++++ > 1 file changed, 4 insertions(+) > > diff --git a/drivers/pci/host/pcie-hisi.c b/drivers/pci/host/pcie-hisi.c > index 56154c2..3256f8f 100644 > --- a/drivers/pci/host/pcie-hisi.c > +++ b/drivers/pci/host/pcie-hisi.c > @@ -174,6 +174,10 @@ static int hisi_pcie_probe(struct platform_device *pdev) > driver = dev->driver; > > match = of_match_device(driver->of_match_table, dev); > + if (!match) { > + dev_err(dev, "Error: No device match found\n"); > + return -ENODEV; > + } > hisi_pcie->soc_ops = (struct pcie_soc_ops *) match->data; > > hisi_pcie->subctrl = I like this patch and I think it's correct. I'd like an ack from Zhou and/or Gabriele, and I'd propose the following tweak, which just moves the check earlier, before we start allocating this: commit 0bd4137b946cab412d612ae155f3b268f2f0a856 Author: Shailendra Verma Date: Mon Jan 30 10:19:35 2017 +0530 PCI: hisi: Check of_match_device() return value of_match_device() could return NULL, and so can cause a NULL pointer dereference later. Check the result first, before we start setting up things that need to be undone if it fails. [bhelgaas: check earlier, changelog] Signed-off-by: Shailendra Verma Signed-off-by: Bjorn Helgaas --- To unsubscribe from this list: send the line "unsubscribe linux-pci" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/drivers/pci/host/pcie-hisi.c b/drivers/pci/host/pcie-hisi.c index a301a7187b30..0f0521169a3c 100644 --- a/drivers/pci/host/pcie-hisi.c +++ b/drivers/pci/host/pcie-hisi.c @@ -264,6 +264,10 @@ static int hisi_pcie_probe(struct platform_device *pdev) struct device_driver *driver; int ret; + match = of_match_device(driver->of_match_table, dev); + if (!match) + return -ENODEV; + hisi_pcie = devm_kzalloc(dev, sizeof(*hisi_pcie), GFP_KERNEL); if (!hisi_pcie) return -ENOMEM; @@ -272,7 +276,6 @@ static int hisi_pcie_probe(struct platform_device *pdev) pp->dev = dev; driver = dev->driver; - match = of_match_device(driver->of_match_table, dev); hisi_pcie->soc_ops = (struct pcie_soc_ops *) match->data; hisi_pcie->subctrl =