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: 877495 X-Patchwork-Delegate: bhelgaas@google.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-pci-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=rock-chips.com Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3zpqH70kqpz9s0y for ; Sun, 25 Feb 2018 13:51:47 +1100 (AEDT) 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 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; }