From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 64190C433EF for ; Thu, 7 Oct 2021 12:51:25 +0000 (UTC) Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 968746109F for ; Thu, 7 Oct 2021 12:51:24 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 968746109F Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=lists.denx.de Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id D7352834B9; Thu, 7 Oct 2021 14:51:21 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=kernel.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=kernel.org header.i=@kernel.org header.b="ojwFsEGe"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id C646F834FB; Thu, 7 Oct 2021 14:51:18 +0200 (CEST) Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 5B471834B9 for ; Thu, 7 Oct 2021 14:51:15 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=kernel.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=pali@kernel.org Received: by mail.kernel.org (Postfix) with ESMTPSA id 4E28A610E6; Thu, 7 Oct 2021 12:51:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1633611073; bh=LyECC7ISwo0t8xt3PGXbyaWXJ0SM4iDy0ScBwpqUM74=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ojwFsEGeadqUKBSqcH4ymE4Jx12IGevyldqQPOyTRU36xAT4rVSGo9W3BKEHvg3jB f68KJO2QDVPcdXESJbYmJKrcqJGA+kfD/3Uq6lv7VFGjO3GcDjaNz0edpwxcYeUDv/ E09D3c95QUN6ihOPgVqhBiU9CZLO0jQmCr2k4+ukvI4rDAwucOoV4N3WBXTdSNxt5d RliwXh/4OfptcS3r/B2ty5pUH609YuCGCIbHeCBufHe+lxXcLGo8bMAfxj/PJW0/s7 f5dOJYPXQIDQVV1PeARV9NTp+sFcNkNznDBax0V6q5T/IeMJsoLfEkAR4pxsakaXR5 33kcCnifUYv2g== Received: by pali.im (Postfix) id 4834D2666; Thu, 7 Oct 2021 14:51:11 +0200 (CEST) From: =?UTF-8?q?Pali=20Roh=C3=A1r?= To: Simon Glass , Vladimir Oltean , Bin Meng , Stefan Roese Cc: u-boot@lists.denx.de Subject: [PATCH 2/5] pci: Skip configuring invalid P2P bridge devices Date: Thu, 7 Oct 2021 14:50:58 +0200 Message-Id: <20211007125101.21811-2-pali@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20211007125101.21811-1-pali@kernel.org> References: <20211007125101.21811-1-pali@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.2 at phobos.denx.de X-Virus-Status: Clean Function dm_pci_hose_probe_bus() expects that bus is valid PCI device with Bridge header type (0x01). So add check before touching PCI config space to prevent misconfiguring some non-standard device. Signed-off-by: Pali Rohár --- drivers/pci/pci-uclass.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/drivers/pci/pci-uclass.c b/drivers/pci/pci-uclass.c index 044babee164f..5da3515f5f25 100644 --- a/drivers/pci/pci-uclass.c +++ b/drivers/pci/pci-uclass.c @@ -627,6 +627,7 @@ int pci_generic_mmap_read_config( int dm_pci_hose_probe_bus(struct udevice *bus) { + u8 header_type; int sub_bus; int ret; int ea_pos; @@ -634,6 +635,14 @@ int dm_pci_hose_probe_bus(struct udevice *bus) debug("%s\n", __func__); + dm_pci_read_config8(bus, PCI_HEADER_TYPE, &header_type); + header_type &= 0x7f; + if (header_type != PCI_HEADER_TYPE_BRIDGE) { + debug("%s: Skipping PCI device %d with Non-Bridge Header Type 0x%x\n", + __func__, PCI_DEV(dm_pci_get_bdf(bus)), header_type); + return log_msg_ret("probe", -EINVAL); + } + ea_pos = dm_pci_find_capability(bus, PCI_CAP_ID_EA); if (ea_pos) { dm_pci_read_config8(bus, ea_pos + sizeof(u32) + sizeof(u8), -- 2.20.1