summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAngel Pons <th3fanbus@gmail.com>2021-11-03 13:18:53 +0100
committerFelix Held <felix-coreboot@felixheld.de>2021-11-04 17:34:30 +0000
commitc1bfbe03a2d379d6859734da445a8ab3fd292305 (patch)
treec06cef86fb068c718e7a4b60ef5620e46a31fdd8 /src
parent536d36a7480c70acefb45c7f31db29489f4776e8 (diff)
soc/intel: Replace bad uses of `find_resource`
The `find_resource` function will never return null (will die instead). In cases where the existing code already accounts for null pointers, it is better to use `probe_resource` instead, which returns a null pointer instead of dying. Change-Id: I2a57ea1c2f5b156afd0724829e5b1880246f351f Signed-off-by: Angel Pons <th3fanbus@gmail.com> Reviewed-on: https://review.coreboot.org/c/coreboot/+/58907 Tested-by: build bot (Jenkins) <no-reply@coreboot.org> Reviewed-by: Werner Zeh <werner.zeh@siemens.com> Reviewed-by: Tim Wawrzynczak <twawrzynczak@chromium.org>
Diffstat (limited to 'src')
-rw-r--r--src/soc/intel/baytrail/gfx.c2
-rw-r--r--src/soc/intel/baytrail/hda.c2
-rw-r--r--src/soc/intel/baytrail/lpe.c4
-rw-r--r--src/soc/intel/baytrail/lpss.c4
-rw-r--r--src/soc/intel/baytrail/scc.c4
-rw-r--r--src/soc/intel/braswell/lpe.c6
-rw-r--r--src/soc/intel/braswell/lpss.c4
-rw-r--r--src/soc/intel/braswell/scc.c4
-rw-r--r--src/soc/intel/broadwell/gma.c2
-rw-r--r--src/soc/intel/broadwell/minihd.c2
-rw-r--r--src/soc/intel/broadwell/pch/adsp.c4
-rw-r--r--src/soc/intel/broadwell/pch/hda.c2
-rw-r--r--src/soc/intel/broadwell/pch/me.c2
-rw-r--r--src/soc/intel/broadwell/pch/serialio.c4
-rw-r--r--src/soc/intel/common/block/graphics/graphics.c2
-rw-r--r--src/soc/intel/common/block/i2c/i2c.c2
-rw-r--r--src/soc/intel/common/block/smbus/smbus.c2
-rw-r--r--src/soc/intel/common/block/thermal/thermal.c2
-rw-r--r--src/soc/intel/common/block/xhci/xhci.c2
-rw-r--r--src/soc/intel/denverton_ns/uart.c4
-rw-r--r--src/soc/intel/jasperlake/xhci.c2
-rw-r--r--src/soc/intel/skylake/graphics.c2
22 files changed, 32 insertions, 32 deletions
diff --git a/src/soc/intel/baytrail/gfx.c b/src/soc/intel/baytrail/gfx.c
index 0ee3cef591..2ee2375ef6 100644
--- a/src/soc/intel/baytrail/gfx.c
+++ b/src/soc/intel/baytrail/gfx.c
@@ -279,7 +279,7 @@ static void set_backlight_pwm(struct device *dev, uint32_t bklt_reg, int req_hz)
int divider;
struct resource *res;
- res = find_resource(dev, PCI_BASE_ADDRESS_0);
+ res = probe_resource(dev, PCI_BASE_ADDRESS_0);
if (res == NULL)
return;
diff --git a/src/soc/intel/baytrail/hda.c b/src/soc/intel/baytrail/hda.c
index db569ec63a..b582006d1c 100644
--- a/src/soc/intel/baytrail/hda.c
+++ b/src/soc/intel/baytrail/hda.c
@@ -64,7 +64,7 @@ static void hda_init(struct device *dev)
reg_script_run_on_dev(dev, init_ops);
- res = find_resource(dev, PCI_BASE_ADDRESS_0);
+ res = probe_resource(dev, PCI_BASE_ADDRESS_0);
if (res == NULL)
return;
diff --git a/src/soc/intel/baytrail/lpe.c b/src/soc/intel/baytrail/lpe.c
index a56ce5b6f0..719286541b 100644
--- a/src/soc/intel/baytrail/lpe.c
+++ b/src/soc/intel/baytrail/lpe.c
@@ -34,7 +34,7 @@ static void assign_device_nvs(struct device *dev, u32 *field, unsigned int index
{
struct resource *res;
- res = find_resource(dev, index);
+ res = probe_resource(dev, index);
if (res)
*field = res->base;
}
@@ -112,7 +112,7 @@ static void lpe_stash_firmware_info(struct device *dev)
struct resource *mmio;
const struct pattrs *pattrs = pattrs_get();
- res = find_resource(dev, FIRMWARE_PCI_REG_BASE);
+ res = probe_resource(dev, FIRMWARE_PCI_REG_BASE);
if (res == NULL) {
printk(BIOS_DEBUG, "LPE Firmware memory not found.\n");
return;
diff --git a/src/soc/intel/baytrail/lpss.c b/src/soc/intel/baytrail/lpss.c
index 9f309b4c15..b63576b784 100644
--- a/src/soc/intel/baytrail/lpss.c
+++ b/src/soc/intel/baytrail/lpss.c
@@ -32,11 +32,11 @@ static void dev_enable_acpi_mode(struct device *dev, int iosf_reg, int nvs_index
struct device_nvs *dev_nvs = acpi_get_device_nvs();
/* Save BAR0 and BAR1 to ACPI NVS */
- bar = find_resource(dev, PCI_BASE_ADDRESS_0);
+ bar = probe_resource(dev, PCI_BASE_ADDRESS_0);
if (bar)
dev_nvs->lpss_bar0[nvs_index] = (u32)bar->base;
- bar = find_resource(dev, PCI_BASE_ADDRESS_1);
+ bar = probe_resource(dev, PCI_BASE_ADDRESS_1);
if (bar)
dev_nvs->lpss_bar1[nvs_index] = (u32)bar->base;
diff --git a/src/soc/intel/baytrail/scc.c b/src/soc/intel/baytrail/scc.c
index a1e8eb7ca5..8892b531f9 100644
--- a/src/soc/intel/baytrail/scc.c
+++ b/src/soc/intel/baytrail/scc.c
@@ -83,11 +83,11 @@ void scc_enable_acpi_mode(struct device *dev, int iosf_reg, int nvs_index)
struct device_nvs *dev_nvs = acpi_get_device_nvs();
/* Save BAR0 and BAR1 to ACPI NVS */
- bar = find_resource(dev, PCI_BASE_ADDRESS_0);
+ bar = probe_resource(dev, PCI_BASE_ADDRESS_0);
if (bar)
dev_nvs->scc_bar0[nvs_index] = (u32)bar->base;
- bar = find_resource(dev, PCI_BASE_ADDRESS_1);
+ bar = probe_resource(dev, PCI_BASE_ADDRESS_1);
if (bar)
dev_nvs->scc_bar1[nvs_index] = (u32)bar->base;
diff --git a/src/soc/intel/braswell/lpe.c b/src/soc/intel/braswell/lpe.c
index 59cabee707..323c9fc175 100644
--- a/src/soc/intel/braswell/lpe.c
+++ b/src/soc/intel/braswell/lpe.c
@@ -35,7 +35,7 @@ static void assign_device_nvs(struct device *dev, u32 *field,
{
struct resource *res;
- res = find_resource(dev, index);
+ res = probe_resource(dev, index);
if (res)
*field = res->base;
}
@@ -109,7 +109,7 @@ static void lpe_stash_firmware_info(struct device *dev)
struct resource *res;
struct resource *mmio;
- res = find_resource(dev, FIRMWARE_PCI_REG_BASE);
+ res = probe_resource(dev, FIRMWARE_PCI_REG_BASE);
if (res == NULL) {
printk(BIOS_DEBUG, "LPE Firmware memory not found.\n");
return;
@@ -162,7 +162,7 @@ static void lpe_set_resources(struct device *dev)
{
struct resource *res;
- res = find_resource(dev, PCI_BASE_ADDRESS_2);
+ res = probe_resource(dev, PCI_BASE_ADDRESS_2);
if (res != NULL)
res->flags |= IORESOURCE_STORED;
diff --git a/src/soc/intel/braswell/lpss.c b/src/soc/intel/braswell/lpss.c
index 93ee3da273..5f93e17206 100644
--- a/src/soc/intel/braswell/lpss.c
+++ b/src/soc/intel/braswell/lpss.c
@@ -31,11 +31,11 @@ static void dev_enable_acpi_mode(struct device *dev, int iosf_reg, int nvs_index
struct device_nvs *dev_nvs = acpi_get_device_nvs();
/* Save BAR0 and BAR1 to ACPI NVS */
- bar = find_resource(dev, PCI_BASE_ADDRESS_0);
+ bar = probe_resource(dev, PCI_BASE_ADDRESS_0);
if (bar)
dev_nvs->lpss_bar0[nvs_index] = (u32)bar->base;
- bar = find_resource(dev, PCI_BASE_ADDRESS_1);
+ bar = probe_resource(dev, PCI_BASE_ADDRESS_1);
if (bar)
dev_nvs->lpss_bar1[nvs_index] = (u32)bar->base;
diff --git a/src/soc/intel/braswell/scc.c b/src/soc/intel/braswell/scc.c
index 902ee57a11..8894aa5c75 100644
--- a/src/soc/intel/braswell/scc.c
+++ b/src/soc/intel/braswell/scc.c
@@ -13,10 +13,10 @@ void scc_enable_acpi_mode(struct device *dev, int iosf_reg, int nvs_index)
struct device_nvs *dev_nvs = acpi_get_device_nvs();
/* Save BAR0 and BAR1 to ACPI NVS */
- bar = find_resource(dev, PCI_BASE_ADDRESS_0);
+ bar = probe_resource(dev, PCI_BASE_ADDRESS_0);
if (bar)
dev_nvs->scc_bar0[nvs_index] = bar->base;
- bar = find_resource(dev, PCI_BASE_ADDRESS_2);
+ bar = probe_resource(dev, PCI_BASE_ADDRESS_2);
if (bar)
dev_nvs->scc_bar1[nvs_index] = bar->base;
diff --git a/src/soc/intel/broadwell/gma.c b/src/soc/intel/broadwell/gma.c
index b3e010c65a..e84d075391 100644
--- a/src/soc/intel/broadwell/gma.c
+++ b/src/soc/intel/broadwell/gma.c
@@ -505,7 +505,7 @@ static void igd_init(struct device *dev)
intel_gma_init_igd_opregion();
- gtt_res = find_resource(dev, PCI_BASE_ADDRESS_0);
+ gtt_res = probe_resource(dev, PCI_BASE_ADDRESS_0);
if (!gtt_res || !gtt_res->base)
return;
diff --git a/src/soc/intel/broadwell/minihd.c b/src/soc/intel/broadwell/minihd.c
index e373878643..a07d9b1524 100644
--- a/src/soc/intel/broadwell/minihd.c
+++ b/src/soc/intel/broadwell/minihd.c
@@ -52,7 +52,7 @@ static void minihd_init(struct device *dev)
int codec_mask, i;
/* Find base address */
- res = find_resource(dev, PCI_BASE_ADDRESS_0);
+ res = probe_resource(dev, PCI_BASE_ADDRESS_0);
if (!res)
return;
diff --git a/src/soc/intel/broadwell/pch/adsp.c b/src/soc/intel/broadwell/pch/adsp.c
index 1ebf922aec..eaae08b881 100644
--- a/src/soc/intel/broadwell/pch/adsp.c
+++ b/src/soc/intel/broadwell/pch/adsp.c
@@ -25,10 +25,10 @@ static void adsp_init(struct device *dev)
pci_or_config16(dev, PCI_COMMAND, PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY);
/* Find BAR0 and BAR1 */
- bar0 = find_resource(dev, PCI_BASE_ADDRESS_0);
+ bar0 = probe_resource(dev, PCI_BASE_ADDRESS_0);
if (!bar0)
return;
- bar1 = find_resource(dev, PCI_BASE_ADDRESS_1);
+ bar1 = probe_resource(dev, PCI_BASE_ADDRESS_1);
if (!bar1)
return;
diff --git a/src/soc/intel/broadwell/pch/hda.c b/src/soc/intel/broadwell/pch/hda.c
index 2e00f79bb8..37f2d9f8e6 100644
--- a/src/soc/intel/broadwell/pch/hda.c
+++ b/src/soc/intel/broadwell/pch/hda.c
@@ -80,7 +80,7 @@ static void hda_init(struct device *dev)
u32 codec_mask;
/* Find base address */
- res = find_resource(dev, PCI_BASE_ADDRESS_0);
+ res = probe_resource(dev, PCI_BASE_ADDRESS_0);
if (!res)
return;
diff --git a/src/soc/intel/broadwell/pch/me.c b/src/soc/intel/broadwell/pch/me.c
index 22db6a72f9..95b6d889d2 100644
--- a/src/soc/intel/broadwell/pch/me.c
+++ b/src/soc/intel/broadwell/pch/me.c
@@ -709,7 +709,7 @@ static int intel_mei_setup(struct device *dev)
struct mei_csr host;
/* Find the MMIO base for the ME interface */
- res = find_resource(dev, PCI_BASE_ADDRESS_0);
+ res = probe_resource(dev, PCI_BASE_ADDRESS_0);
if (!res || res->base == 0 || res->size == 0) {
printk(BIOS_DEBUG, "ME: MEI resource not present!\n");
return -1;
diff --git a/src/soc/intel/broadwell/pch/serialio.c b/src/soc/intel/broadwell/pch/serialio.c
index e38de5eda1..f87217c070 100644
--- a/src/soc/intel/broadwell/pch/serialio.c
+++ b/src/soc/intel/broadwell/pch/serialio.c
@@ -166,10 +166,10 @@ static void serialio_init(struct device *dev)
pci_or_config16(dev, PCI_COMMAND, PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY);
/* Find BAR0 and BAR1 */
- bar0 = find_resource(dev, PCI_BASE_ADDRESS_0);
+ bar0 = probe_resource(dev, PCI_BASE_ADDRESS_0);
if (!bar0)
return;
- bar1 = find_resource(dev, PCI_BASE_ADDRESS_1);
+ bar1 = probe_resource(dev, PCI_BASE_ADDRESS_1);
if (!bar1)
return;
diff --git a/src/soc/intel/common/block/graphics/graphics.c b/src/soc/intel/common/block/graphics/graphics.c
index 8476b87b9e..e7e96ad934 100644
--- a/src/soc/intel/common/block/graphics/graphics.c
+++ b/src/soc/intel/common/block/graphics/graphics.c
@@ -100,7 +100,7 @@ static uintptr_t graphics_get_bar(struct device *dev, unsigned long index)
{
struct resource *gm_res;
- gm_res = find_resource(dev, index);
+ gm_res = probe_resource(dev, index);
if (!gm_res)
return 0;
diff --git a/src/soc/intel/common/block/i2c/i2c.c b/src/soc/intel/common/block/i2c/i2c.c
index 90670b6a4a..acc23abb0c 100644
--- a/src/soc/intel/common/block/i2c/i2c.c
+++ b/src/soc/intel/common/block/i2c/i2c.c
@@ -123,7 +123,7 @@ uintptr_t dw_i2c_base_address(unsigned int bus)
return (uintptr_t)NULL;
/* dev -> bar0 */
- res = find_resource(dev, PCI_BASE_ADDRESS_0);
+ res = probe_resource(dev, PCI_BASE_ADDRESS_0);
if (res)
return res->base;
diff --git a/src/soc/intel/common/block/smbus/smbus.c b/src/soc/intel/common/block/smbus/smbus.c
index d11abee6c6..4a46143558 100644
--- a/src/soc/intel/common/block/smbus/smbus.c
+++ b/src/soc/intel/common/block/smbus/smbus.c
@@ -46,7 +46,7 @@ static void pch_smbus_init(struct device *dev)
~((1 << 8) | (1 << 10) | (1 << 12) | (1 << 14)), 0);
/* Set Receive Slave Address */
- res = find_resource(dev, PCI_BASE_ADDRESS_4);
+ res = probe_resource(dev, PCI_BASE_ADDRESS_4);
if (res)
smbus_set_slave_addr(res->base, SMBUS_SLAVE_ADDR);
}
diff --git a/src/soc/intel/common/block/thermal/thermal.c b/src/soc/intel/common/block/thermal/thermal.c
index 13e5285abc..f88699531e 100644
--- a/src/soc/intel/common/block/thermal/thermal.c
+++ b/src/soc/intel/common/block/thermal/thermal.c
@@ -55,7 +55,7 @@ void pch_thermal_configuration(void)
return;
}
- res = find_resource(dev, PCI_BASE_ADDRESS_0);
+ res = probe_resource(dev, PCI_BASE_ADDRESS_0);
if (!res) {
printk(BIOS_ERR, "ERROR: PCH thermal device not found!\n");
return;
diff --git a/src/soc/intel/common/block/xhci/xhci.c b/src/soc/intel/common/block/xhci/xhci.c
index 9adcbfa57f..5b19fc9e36 100644
--- a/src/soc/intel/common/block/xhci/xhci.c
+++ b/src/soc/intel/common/block/xhci/xhci.c
@@ -33,7 +33,7 @@ static bool is_usb_port_connected(const struct xhci_usb_info *info,
return false;
/* Calculate port status register address and read the status */
- res = find_resource(PCH_DEV_XHCI, PCI_BASE_ADDRESS_0);
+ res = probe_resource(PCH_DEV_XHCI, PCI_BASE_ADDRESS_0);
/* If the memory BAR is not allocated for XHCI, leave the devices enabled */
if (!res)
return true;
diff --git a/src/soc/intel/denverton_ns/uart.c b/src/soc/intel/denverton_ns/uart.c
index 8084d26f6b..9d72642fb4 100644
--- a/src/soc/intel/denverton_ns/uart.c
+++ b/src/soc/intel/denverton_ns/uart.c
@@ -22,13 +22,13 @@ static void dnv_ns_uart_read_resources(struct device *dev)
pci_dev_read_resources(dev);
if (!CONFIG(LEGACY_UART_MODE))
return;
- struct resource *res = find_resource(dev, PCI_BASE_ADDRESS_0);
+ struct resource *res = probe_resource(dev, PCI_BASE_ADDRESS_0);
if (res == NULL)
return;
res->size = 0x8;
res->flags = IORESOURCE_IO | IORESOURCE_ASSIGNED | IORESOURCE_FIXED;
/* Do not configure membar */
- res = find_resource(dev, PCI_BASE_ADDRESS_1);
+ res = probe_resource(dev, PCI_BASE_ADDRESS_1);
if (res != NULL)
res->flags = 0;
compact_resources(dev);
diff --git a/src/soc/intel/jasperlake/xhci.c b/src/soc/intel/jasperlake/xhci.c
index 75663795d3..49f919d78f 100644
--- a/src/soc/intel/jasperlake/xhci.c
+++ b/src/soc/intel/jasperlake/xhci.c
@@ -31,7 +31,7 @@ const struct xhci_usb_info *soc_get_xhci_usb_info(pci_devfn_t xhci_dev)
static void set_xhci_lfps_sampling_offtime(struct device *dev, uint8_t time_ms)
{
void *addr;
- const struct resource *res = find_resource(dev, PCI_BASE_ADDRESS_0);
+ const struct resource *res = probe_resource(dev, PCI_BASE_ADDRESS_0);
if (!res)
return;
diff --git a/src/soc/intel/skylake/graphics.c b/src/soc/intel/skylake/graphics.c
index 786ba2de68..98b469c1c9 100644
--- a/src/soc/intel/skylake/graphics.c
+++ b/src/soc/intel/skylake/graphics.c
@@ -24,7 +24,7 @@ void graphics_soc_panel_init(struct device *dev)
panel_cfg = &conf->panel_cfg;
- mmio_res = find_resource(dev, PCI_BASE_ADDRESS_0);
+ mmio_res = probe_resource(dev, PCI_BASE_ADDRESS_0);
if (!mmio_res || !mmio_res->base)
return;
base = (void *)(uintptr_t)mmio_res->base;