intelblocks/gpio.c: Handle NULL return values from child functions

gpio_configure_pad function gets called for most of the GPIO
configuration for all the boards. This function is not handling NULL
pointers properly which can cause exception in CPU.

This patch fixes the handling and function is able to return early
in case the NULL pointer is passed or any subsequent child function
calls return NULL.

BUG=None
BRANCH=None
TEST=Compilation works fine for all Alder Lake boards.

Change-Id: I97fad72cdd92f70c7c5e6fdd23fbecf535a6e388
Signed-off-by: Maulik V Vaghela <maulik.v.vaghela@intel.com>
Reviewed-on: https://review.coreboot.org/c/coreboot/+/64857
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Eric Lai <eric_lai@quanta.corp-partner.google.com>
This commit is contained in:
Maulik V Vaghela 2022-05-31 20:24:42 +05:30 committed by Paul Fagerburg
parent 295a7508b8
commit cdc1de7e92
1 changed files with 13 additions and 1 deletions

View File

@ -331,11 +331,23 @@ static const int mask[4] = {
static void gpio_configure_pad(const struct pad_config *cfg) static void gpio_configure_pad(const struct pad_config *cfg)
{ {
const struct pad_community *comm = gpio_get_community(cfg->pad); const struct pad_community *comm;
uint16_t config_offset; uint16_t config_offset;
uint32_t pad_conf, soc_pad_conf; uint32_t pad_conf, soc_pad_conf;
int i, pin, group; int i, pin, group;
if (!cfg) {
printk(BIOS_ERR, "%s: cfg value is NULL\n", __func__);
return;
}
comm = gpio_get_community(cfg->pad);
if (!comm) {
printk(BIOS_ERR, "%s: Could not find community for pad: 0x%x\n",
__func__, cfg->pad);
return;
}
config_offset = pad_config_offset(comm, cfg->pad); config_offset = pad_config_offset(comm, cfg->pad);
pin = relative_pad_in_comm(comm, cfg->pad); pin = relative_pad_in_comm(comm, cfg->pad);
group = gpio_group_index(comm, pin); group = gpio_group_index(comm, pin);