Patrick Georgi merged this change.

View Change

Approvals: build bot (Jenkins): Verified Kyösti Mälkki: Looks good to me, approved
nb/amd/pi, mb/amd/bettong: Fix null pointer checks

The dev pointers were being dereferenced before the null
check. Move the checks so they are done earlier.

Found-by: Coverity Scan, CID 1241851 (REVERSE_INULL)
Signed-off-by: Jacob Garber <jgarber1@ualberta.ca>
Change-Id: Ie578787c3c26a1f3acb4567c135486667e88a888
Reviewed-on: https://review.coreboot.org/c/coreboot/+/32022
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Kyösti Mälkki <kyosti.malkki@gmail.com>
---
M src/mainboard/amd/bettong/BiosCallOuts.c
M src/northbridge/amd/pi/00630F01/dimmSpd.c
M src/northbridge/amd/pi/00660F01/dimmSpd.c
M src/northbridge/amd/pi/00730F01/dimmSpd.c
4 files changed, 24 insertions(+), 5 deletions(-)

diff --git a/src/mainboard/amd/bettong/BiosCallOuts.c b/src/mainboard/amd/bettong/BiosCallOuts.c
index 040de9b..e4020b0 100644
--- a/src/mainboard/amd/bettong/BiosCallOuts.c
+++ b/src/mainboard/amd/bettong/BiosCallOuts.c
@@ -121,14 +121,20 @@
AGESA_READ_SPD_PARAMS *info = ConfigPtr;

DEVTREE_CONST struct device *dev = pcidev_on_root(0x18, 2);
+
+ if (dev == NULL)
+ return AGESA_ERROR;
+
DEVTREE_CONST struct northbridge_amd_pi_00660F01_config *config = dev->chip_info;
+
+ if (config == NULL)
+ return AGESA_ERROR;
+
UINT8 spdAddrLookup_rev_F [2][2][4]= {
{ {0xA0, 0xA2}, {0xA4, 0xAC}, }, /* socket 0 - Channel 0 & 1 - 8-bit SPD addresses */
{ {0x00, 0x00}, {0x00, 0x00}, }, /* socket 1 - Channel 0 & 1 - 8-bit SPD addresses */
};

- if ((dev == 0) || (config == 0))
- return AGESA_ERROR;
if (info->SocketId >= ARRAY_SIZE(config->spdAddrLookup))
return AGESA_ERROR;
if (info->MemChannelId >= ARRAY_SIZE(config->spdAddrLookup[0]))
diff --git a/src/northbridge/amd/pi/00630F01/dimmSpd.c b/src/northbridge/amd/pi/00630F01/dimmSpd.c
index f958b01..845dad1 100644
--- a/src/northbridge/amd/pi/00630F01/dimmSpd.c
+++ b/src/northbridge/amd/pi/00630F01/dimmSpd.c
@@ -28,9 +28,13 @@
{
int spdAddress;
DEVTREE_CONST struct device *dev = pcidev_on_root(0x18, 2);
+
+ if (dev == NULL)
+ return AGESA_ERROR;
+
DEVTREE_CONST struct northbridge_amd_pi_00630F01_config *config = dev->chip_info;

- if ((dev == 0) || (config == 0))
+ if (config == NULL)
return AGESA_ERROR;

if (info->SocketId >= ARRAY_SIZE(config->spdAddrLookup))
diff --git a/src/northbridge/amd/pi/00660F01/dimmSpd.c b/src/northbridge/amd/pi/00660F01/dimmSpd.c
index 0de7654..349dacf 100644
--- a/src/northbridge/amd/pi/00660F01/dimmSpd.c
+++ b/src/northbridge/amd/pi/00660F01/dimmSpd.c
@@ -27,10 +27,15 @@
{
int spdAddress;
DEVTREE_CONST struct device *dev = pcidev_on_root(0x18, 2);
+
+ if (dev == NULL)
+ return AGESA_ERROR;
+
DEVTREE_CONST struct northbridge_amd_pi_00660F01_config *config = dev->chip_info;

- if ((dev == 0) || (config == 0))
+ if (config == NULL)
return AGESA_ERROR;
+
if (info->SocketId >= ARRAY_SIZE(config->spdAddrLookup))
return AGESA_ERROR;
if (info->MemChannelId >= ARRAY_SIZE(config->spdAddrLookup[0]))
diff --git a/src/northbridge/amd/pi/00730F01/dimmSpd.c b/src/northbridge/amd/pi/00730F01/dimmSpd.c
index 79e046e..bbcac90 100644
--- a/src/northbridge/amd/pi/00730F01/dimmSpd.c
+++ b/src/northbridge/amd/pi/00730F01/dimmSpd.c
@@ -28,9 +28,13 @@
{
int spdAddress;
DEVTREE_CONST struct device *dev = pcidev_on_root(0x18, 2);
+
+ if (dev == NULL)
+ return AGESA_ERROR;
+
DEVTREE_CONST struct northbridge_amd_pi_00730F01_config *config = dev->chip_info;

- if ((dev == 0) || (config == 0))
+ if (config == NULL)
return AGESA_ERROR;

if (info->SocketId >= ARRAY_SIZE(config->spdAddrLookup))

To view, visit change 32022. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: coreboot
Gerrit-Branch: master
Gerrit-Change-Id: Ie578787c3c26a1f3acb4567c135486667e88a888
Gerrit-Change-Number: 32022
Gerrit-PatchSet: 6
Gerrit-Owner: Jacob Garber <jgarber1@ualberta.ca>
Gerrit-Reviewer: HAOUAS Elyes <ehaouas@noos.fr>
Gerrit-Reviewer: Jacob Garber <jgarber1@ualberta.ca>
Gerrit-Reviewer: Kyösti Mälkki <kyosti.malkki@gmail.com>
Gerrit-Reviewer: Patrick Georgi <pgeorgi@google.com>
Gerrit-Reviewer: Paul Menzel <paulepanter@users.sourceforge.net>
Gerrit-Reviewer: build bot (Jenkins) <no-reply@coreboot.org>
Gerrit-MessageType: merged