From patchwork Sun Feb 25 02:46:02 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shawn Lin X-Patchwork-Id: 10240651 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 DEDE6602A0 for ; Sun, 25 Feb 2018 02:51:46 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CAB9F29BC1 for ; Sun, 25 Feb 2018 02:51:46 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BDE2C29BC5; Sun, 25 Feb 2018 02:51:46 +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=-5.4 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_WEB 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 64C2D29BC1 for ; Sun, 25 Feb 2018 02:51:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751581AbeBYCvp (ORCPT ); Sat, 24 Feb 2018 21:51:45 -0500 Received: from lucky1.263xmail.com ([211.157.147.133]:51322 "EHLO lucky1.263xmail.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751481AbeBYCvp (ORCPT ); Sat, 24 Feb 2018 21:51:45 -0500 Received: from shawn.lin?rock-chips.com (unknown [192.168.167.152]) by lucky1.263xmail.com (Postfix) with ESMTP id ADA0794BB0; Sun, 25 Feb 2018 10:51:38 +0800 (CST) X-263anti-spam: KSV:0; X-MAIL-GRAY: 1 X-MAIL-DELIVERY: 0 X-KSVirus-check: 0 X-ABS-CHECKED: 4 Received: from localhost.localdomain (localhost [127.0.0.1]) by smtp.263.net (Postfix) with ESMTPA id 9BA0F381; Sun, 25 Feb 2018 10:51:37 +0800 (CST) X-RL-SENDER: shawn.lin@rock-chips.com X-FST-TO: bhelgaas@google.com X-SENDER-IP: 58.22.7.114 X-LOGIN-NAME: shawn.lin@rock-chips.com X-UNIQUE-TAG: X-ATTACHMENT-NUM: 0 X-SENDER: lintao@rock-chips.com X-DNS-TYPE: 0 Received: from localhost.localdomain (unknown [58.22.7.114]) by smtp.263.net (Postfix) whith ESMTP id 22701751JGL; Sun, 25 Feb 2018 10:51:37 +0800 (CST) From: Shawn Lin To: Bjorn Helgaas Cc: linux-pci@vger.kernel.org, Shawn Lin Subject: [PATCH] PCI: Fix possible NULL pointer dereference for of_pci_bus_find_domain_nr Date: Sun, 25 Feb 2018 10:46:02 +0800 Message-Id: <1519526762-136838-1-git-send-email-shawn.lin@rock-chips.com> X-Mailer: git-send-email 1.9.1 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 pci_register_host_bridge records bus->domain_nr from pci_bus_find_domain_nr but not guarantee not to pass a NULL struct device *parent to it which could be explained by the hint of checkcing for parent device before calling set_dev_node(), just lines after that. So of_pci_bus_find_domain_nr wisely check the parent pointer at the very beginning, but forgot to check it again when trying to get of_node from parent, which could causes a NULL pointer dereference. Fix it by dumping the NULL pointer address simply, if no parent available. Signed-off-by: Shawn Lin --- drivers/pci/pci.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c index f6a4dd1..ef18c48 100644 --- a/drivers/pci/pci.c +++ b/drivers/pci/pci.c @@ -5612,7 +5612,7 @@ static int of_pci_bus_find_domain_nr(struct device *parent) domain = pci_get_new_domain_nr(); } else { dev_err(parent, "Node %pOF has inconsistent \"linux,pci-domain\" property in DT\n", - parent->of_node); + parent ? parent->of_node : NULL); domain = -1; }