]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/commit
pci: Don't try to read cfg registers of non-existing devices
authorKornel Duleba <mindal@semihalf.com>
Tue, 23 Nov 2021 08:13:56 +0000 (09:13 +0100)
committerWojciech Macek <wma@FreeBSD.org>
Wed, 15 Dec 2021 10:46:46 +0000 (11:46 +0100)
commit77b3cf989fc11bcae263c8601e73daf90987ea97
tree4a4d4f26cd6107509c41463ac956cf8f5a49b5df
parent98a6200ee2482f2f3c73d6d8b8814db2447f7e33
pci: Don't try to read cfg registers of non-existing devices

Instead of returning 0xffs some controllers, such as Layerscape generate
an external exception when someone attempts to read any register
of config space of a non-existing device other than PCIR_VENDOR.
This causes a kernel panic.
Fix it by bailing during device enumeration if a device vendor register
returns invalid value. (0xffff)
Use this opportunity to replace some hardcoded values with a macro.

I believe that this change won't have any unintended side-effects since
it is safe to assume that vendor == 0xffff -> hdr_type == 0xffff.

Sponsored by: Alstom
Obtained from: Semihalf
Reviewed by: jhb
MFC after: 2 weeks
Differential revision: https://reviews.freebsd.org/D33059

(cherry picked from commit 68cbe189fdd3c572476f8af9219a5d335f05b51a)
sys/dev/pci/pci.c