Attention is currently required from: Nico Huber, Arthur Heymans, Patrick Rudolph. Hello Nico Huber, Arthur Heymans, Patrick Rudolph,
I'd like you to do a code review. Please visit
https://review.coreboot.org/c/coreboot/+/55690
to review the following change.
Change subject: nb/intel/haswell/pcie.c: Avoid needless death ......................................................................
nb/intel/haswell/pcie.c: Avoid needless death
Using `config_of(dev)` to access `dev->chip_info` will make coreboot die if the latter is NULL, which is the case for devices detected at runtime (i.e. not statically declared in the devicetree). Given that the code is designed to work when the PEG config is all-zeroes (devicetree default), dying because `dev->chip_info` is NULL is foolish and unwarranted.
Introduce a helper function that returns a pointer to devicetree config when available, and otherwise returns a pointer to a zero-filled static struct. In addition, avoid an out-of-bounds access in the very unlikely case where the device's function is too large.
Tested on Asrock B85M Pro4, can now boot when `device pci 01.0 on end` is commented out in its devicetree. Without this commit, it could not.
Change-Id: Ia2d3a03da9eab601fb834b0c51a8a51c9ae14c33 Signed-off-by: Angel Pons th3fanbus@gmail.com --- M src/northbridge/intel/haswell/pcie.c 1 file changed, 15 insertions(+), 5 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/90/55690/1
diff --git a/src/northbridge/intel/haswell/pcie.c b/src/northbridge/intel/haswell/pcie.c index 4806f77..16ea28d 100644 --- a/src/northbridge/intel/haswell/pcie.c +++ b/src/northbridge/intel/haswell/pcie.c @@ -46,15 +46,25 @@ } #endif
+static const struct peg_config *get_peg_config(struct device *dev, const uint8_t func) +{ + static const struct peg_config default_config = { 0 }; + + if (!dev || !dev->chip_info) + return &default_config; + + const struct northbridge_intel_haswell_config *config = dev->chip_info; + + const bool in_range = func < ARRAY_SIZE(config->peg_cfg); + assert(in_range); + return in_range ? &config->peg_cfg[func] : &default_config; +} + static void peg_enable(struct device *dev) { - const struct northbridge_intel_haswell_config *config = config_of(dev); - const uint8_t func = PCI_FUNC(PCI_DEV2DEVFN(PCI_BDF(dev)));
- assert(func < ARRAY_SIZE(config->peg_cfg)); - - const struct peg_config *peg_cfg = &config->peg_cfg[func]; + const struct peg_config *peg_cfg = get_peg_config(dev, func);
const bool slot_implemented = !peg_cfg->is_onboard;