From patchwork Fri Jun 26 21:16:26 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Chiang X-Patchwork-Id: 32613 Received: from vger.kernel.org (vger.kernel.org [209.132.176.167]) by demeter.kernel.org (8.14.2/8.14.2) with ESMTP id n5QLGTRc029278 for ; Fri, 26 Jun 2009 21:16:29 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752116AbZFZVQY (ORCPT ); Fri, 26 Jun 2009 17:16:24 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1751618AbZFZVQY (ORCPT ); Fri, 26 Jun 2009 17:16:24 -0400 Received: from g5t0009.atlanta.hp.com ([15.192.0.46]:19376 "EHLO g5t0009.atlanta.hp.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751257AbZFZVQY (ORCPT ); Fri, 26 Jun 2009 17:16:24 -0400 Received: from g5t0029.atlanta.hp.com (g5t0029.atlanta.hp.com [16.228.8.141]) by g5t0009.atlanta.hp.com (Postfix) with ESMTP id 5494A30257; Fri, 26 Jun 2009 21:16:27 +0000 (UTC) Received: from ldl.fc.hp.com (ldl.fc.hp.com [15.11.146.30]) by g5t0029.atlanta.hp.com (Postfix) with ESMTP id 6BA69101CF; Fri, 26 Jun 2009 21:16:26 +0000 (UTC) Received: by ldl.fc.hp.com (Postfix, from userid 17609) id 2CEF939C009; Fri, 26 Jun 2009 15:16:26 -0600 (MDT) Date: Fri, 26 Jun 2009 15:16:26 -0600 From: Alex Chiang To: Len Brown Cc: Jesse Barnes , Troy Moure , linux-acpi@vger.kernel.org, linux-kernel Subject: [PATCH] ACPI: update acpi_get_pci_dev() comments Message-ID: <20090626211626.GB980@ldl.fc.hp.com> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.17+20080114 (2008-01-14) Sender: linux-acpi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org Recent commit 412af978 (ACPI: video: prevent NULL deref in acpi_get_pci_dev()) was added to prevent a boot oops. Update the implementation with some notes and analysis as to why the fix is correct. Cc: Jesse Barnes Cc: Troy Moure Signed-off-by: Alex Chiang --- -- To unsubscribe from this list: send the line "unsubscribe linux-acpi" 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/acpi/pci_root.c b/drivers/acpi/pci_root.c index 55b5b90..570f32e 100644 --- a/drivers/acpi/pci_root.c +++ b/drivers/acpi/pci_root.c @@ -344,6 +344,16 @@ struct acpi_handle_node { * function returns a pointer to its data structure. The caller must * decrement the reference count by calling pci_dev_put(). * If no device is found, %NULL is returned. + * + * XXX: You may be surprised at the results if you call this interface + * with a handle to a PCI root bridge and expect to get a pci_dev back. + * The PCI specification does not require a PCI root bridge to present + * configuration space, and thus may not have a valid associated pci_dev. + * + * [nb, all P2P bridges _are_ required to present configuration space] + * + * A PCI root bridge that presents config space is referred to as + * "materialized"; its converse is "non-materialized". */ struct pci_dev *acpi_get_pci_dev(acpi_handle handle) { @@ -385,6 +395,11 @@ struct pci_dev *acpi_get_pci_dev(acpi_handle handle) * Now, walk back down the PCI device tree until we return to our * original handle. Assumes that everything between the PCI root * bridge and the device we're looking for must be a P2P bridge. + * + * Note! It's possible for ACPI to describe a non-existent PCI device + * due to either hotplug or a namespace shared across different + * platforms with just enable or present bits to mask them out from + * the initial PCI scan. So take care to check for a NULL pdev. */ list_for_each_entry(node, &device_list, node) { acpi_handle hnd = node->handle;