From 5ea714accea63ba3ff13411b813fb3cfa9caf932 Mon Sep 17 00:00:00 2001 From: Werner Zeh Date: Mon, 19 Feb 2018 09:49:52 +0100 Subject: mb/siemens/mc_bdx1: Avoid dereferencing a NULL pointer Coverity scan has found an error where a NULL pointer is dereferenced. The bug would happen if the devicetree does not contain a valid entry for PCA9538. In this case the code * if (dev->path.i2c.device == PCA9538_SLAVE_ADR) would dereference to a NULL pointer. This patch fixes this issue. Thanks coverity! Found-by: Coverity (CID 1386126: Null pointer dereferences (REVERSE_INULL)) Change-Id: I75e271d86c16fa3938420c43575ebba910f6a2fd Signed-off-by: Werner Zeh Reviewed-on: https://review.coreboot.org/23808 Tested-by: build bot (Jenkins) Reviewed-by: Martin Roth --- src/mainboard/siemens/mc_bdx1/mainboard.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/mainboard') diff --git a/src/mainboard/siemens/mc_bdx1/mainboard.c b/src/mainboard/siemens/mc_bdx1/mainboard.c index ebc6d40fdc..66edcb7a66 100644 --- a/src/mainboard/siemens/mc_bdx1/mainboard.c +++ b/src/mainboard/siemens/mc_bdx1/mainboard.c @@ -259,11 +259,11 @@ static void wait_for_legacy_dev(void *unused) struct device *pca9538_get_dev(void) { struct device *dev = NULL; - do { - dev = dev_find_path(dev, DEVICE_PATH_I2C); + + while ((dev = dev_find_path(dev, DEVICE_PATH_I2C))) { if (dev->path.i2c.device == PCA9538_SLAVE_ADR) break; - } while (dev); + } return dev; } -- cgit v1.2.3