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>
This commit is contained in:
parent
536d36a748
commit
c1bfbe03a2
|
@ -279,7 +279,7 @@ static void set_backlight_pwm(struct device *dev, uint32_t bklt_reg, int req_hz)
|
||||||
int divider;
|
int divider;
|
||||||
struct resource *res;
|
struct resource *res;
|
||||||
|
|
||||||
res = find_resource(dev, PCI_BASE_ADDRESS_0);
|
res = probe_resource(dev, PCI_BASE_ADDRESS_0);
|
||||||
|
|
||||||
if (res == NULL)
|
if (res == NULL)
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -64,7 +64,7 @@ static void hda_init(struct device *dev)
|
||||||
|
|
||||||
reg_script_run_on_dev(dev, init_ops);
|
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)
|
if (res == NULL)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
|
|
@ -34,7 +34,7 @@ static void assign_device_nvs(struct device *dev, u32 *field, unsigned int index
|
||||||
{
|
{
|
||||||
struct resource *res;
|
struct resource *res;
|
||||||
|
|
||||||
res = find_resource(dev, index);
|
res = probe_resource(dev, index);
|
||||||
if (res)
|
if (res)
|
||||||
*field = res->base;
|
*field = res->base;
|
||||||
}
|
}
|
||||||
|
@ -112,7 +112,7 @@ static void lpe_stash_firmware_info(struct device *dev)
|
||||||
struct resource *mmio;
|
struct resource *mmio;
|
||||||
const struct pattrs *pattrs = pattrs_get();
|
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) {
|
if (res == NULL) {
|
||||||
printk(BIOS_DEBUG, "LPE Firmware memory not found.\n");
|
printk(BIOS_DEBUG, "LPE Firmware memory not found.\n");
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -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();
|
struct device_nvs *dev_nvs = acpi_get_device_nvs();
|
||||||
|
|
||||||
/* Save BAR0 and BAR1 to ACPI 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)
|
if (bar)
|
||||||
dev_nvs->lpss_bar0[nvs_index] = (u32)bar->base;
|
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)
|
if (bar)
|
||||||
dev_nvs->lpss_bar1[nvs_index] = (u32)bar->base;
|
dev_nvs->lpss_bar1[nvs_index] = (u32)bar->base;
|
||||||
|
|
||||||
|
|
|
@ -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();
|
struct device_nvs *dev_nvs = acpi_get_device_nvs();
|
||||||
|
|
||||||
/* Save BAR0 and BAR1 to ACPI 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)
|
if (bar)
|
||||||
dev_nvs->scc_bar0[nvs_index] = (u32)bar->base;
|
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)
|
if (bar)
|
||||||
dev_nvs->scc_bar1[nvs_index] = (u32)bar->base;
|
dev_nvs->scc_bar1[nvs_index] = (u32)bar->base;
|
||||||
|
|
||||||
|
|
|
@ -35,7 +35,7 @@ static void assign_device_nvs(struct device *dev, u32 *field,
|
||||||
{
|
{
|
||||||
struct resource *res;
|
struct resource *res;
|
||||||
|
|
||||||
res = find_resource(dev, index);
|
res = probe_resource(dev, index);
|
||||||
if (res)
|
if (res)
|
||||||
*field = res->base;
|
*field = res->base;
|
||||||
}
|
}
|
||||||
|
@ -109,7 +109,7 @@ static void lpe_stash_firmware_info(struct device *dev)
|
||||||
struct resource *res;
|
struct resource *res;
|
||||||
struct resource *mmio;
|
struct resource *mmio;
|
||||||
|
|
||||||
res = find_resource(dev, FIRMWARE_PCI_REG_BASE);
|
res = probe_resource(dev, FIRMWARE_PCI_REG_BASE);
|
||||||
if (res == NULL) {
|
if (res == NULL) {
|
||||||
printk(BIOS_DEBUG, "LPE Firmware memory not found.\n");
|
printk(BIOS_DEBUG, "LPE Firmware memory not found.\n");
|
||||||
return;
|
return;
|
||||||
|
@ -162,7 +162,7 @@ static void lpe_set_resources(struct device *dev)
|
||||||
{
|
{
|
||||||
struct resource *res;
|
struct resource *res;
|
||||||
|
|
||||||
res = find_resource(dev, PCI_BASE_ADDRESS_2);
|
res = probe_resource(dev, PCI_BASE_ADDRESS_2);
|
||||||
if (res != NULL)
|
if (res != NULL)
|
||||||
res->flags |= IORESOURCE_STORED;
|
res->flags |= IORESOURCE_STORED;
|
||||||
|
|
||||||
|
|
|
@ -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();
|
struct device_nvs *dev_nvs = acpi_get_device_nvs();
|
||||||
|
|
||||||
/* Save BAR0 and BAR1 to ACPI 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)
|
if (bar)
|
||||||
dev_nvs->lpss_bar0[nvs_index] = (u32)bar->base;
|
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)
|
if (bar)
|
||||||
dev_nvs->lpss_bar1[nvs_index] = (u32)bar->base;
|
dev_nvs->lpss_bar1[nvs_index] = (u32)bar->base;
|
||||||
|
|
||||||
|
|
|
@ -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();
|
struct device_nvs *dev_nvs = acpi_get_device_nvs();
|
||||||
|
|
||||||
/* Save BAR0 and BAR1 to ACPI 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)
|
if (bar)
|
||||||
dev_nvs->scc_bar0[nvs_index] = bar->base;
|
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)
|
if (bar)
|
||||||
dev_nvs->scc_bar1[nvs_index] = bar->base;
|
dev_nvs->scc_bar1[nvs_index] = bar->base;
|
||||||
|
|
||||||
|
|
|
@ -505,7 +505,7 @@ static void igd_init(struct device *dev)
|
||||||
|
|
||||||
intel_gma_init_igd_opregion();
|
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)
|
if (!gtt_res || !gtt_res->base)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
|
|
@ -52,7 +52,7 @@ static void minihd_init(struct device *dev)
|
||||||
int codec_mask, i;
|
int codec_mask, i;
|
||||||
|
|
||||||
/* Find base address */
|
/* Find base address */
|
||||||
res = find_resource(dev, PCI_BASE_ADDRESS_0);
|
res = probe_resource(dev, PCI_BASE_ADDRESS_0);
|
||||||
if (!res)
|
if (!res)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
|
|
@ -25,10 +25,10 @@ static void adsp_init(struct device *dev)
|
||||||
pci_or_config16(dev, PCI_COMMAND, PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY);
|
pci_or_config16(dev, PCI_COMMAND, PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY);
|
||||||
|
|
||||||
/* Find BAR0 and BAR1 */
|
/* Find BAR0 and BAR1 */
|
||||||
bar0 = find_resource(dev, PCI_BASE_ADDRESS_0);
|
bar0 = probe_resource(dev, PCI_BASE_ADDRESS_0);
|
||||||
if (!bar0)
|
if (!bar0)
|
||||||
return;
|
return;
|
||||||
bar1 = find_resource(dev, PCI_BASE_ADDRESS_1);
|
bar1 = probe_resource(dev, PCI_BASE_ADDRESS_1);
|
||||||
if (!bar1)
|
if (!bar1)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
|
|
@ -80,7 +80,7 @@ static void hda_init(struct device *dev)
|
||||||
u32 codec_mask;
|
u32 codec_mask;
|
||||||
|
|
||||||
/* Find base address */
|
/* Find base address */
|
||||||
res = find_resource(dev, PCI_BASE_ADDRESS_0);
|
res = probe_resource(dev, PCI_BASE_ADDRESS_0);
|
||||||
if (!res)
|
if (!res)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
|
|
@ -709,7 +709,7 @@ static int intel_mei_setup(struct device *dev)
|
||||||
struct mei_csr host;
|
struct mei_csr host;
|
||||||
|
|
||||||
/* Find the MMIO base for the ME interface */
|
/* 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) {
|
if (!res || res->base == 0 || res->size == 0) {
|
||||||
printk(BIOS_DEBUG, "ME: MEI resource not present!\n");
|
printk(BIOS_DEBUG, "ME: MEI resource not present!\n");
|
||||||
return -1;
|
return -1;
|
||||||
|
|
|
@ -166,10 +166,10 @@ static void serialio_init(struct device *dev)
|
||||||
pci_or_config16(dev, PCI_COMMAND, PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY);
|
pci_or_config16(dev, PCI_COMMAND, PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY);
|
||||||
|
|
||||||
/* Find BAR0 and BAR1 */
|
/* Find BAR0 and BAR1 */
|
||||||
bar0 = find_resource(dev, PCI_BASE_ADDRESS_0);
|
bar0 = probe_resource(dev, PCI_BASE_ADDRESS_0);
|
||||||
if (!bar0)
|
if (!bar0)
|
||||||
return;
|
return;
|
||||||
bar1 = find_resource(dev, PCI_BASE_ADDRESS_1);
|
bar1 = probe_resource(dev, PCI_BASE_ADDRESS_1);
|
||||||
if (!bar1)
|
if (!bar1)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
|
|
@ -100,7 +100,7 @@ static uintptr_t graphics_get_bar(struct device *dev, unsigned long index)
|
||||||
{
|
{
|
||||||
struct resource *gm_res;
|
struct resource *gm_res;
|
||||||
|
|
||||||
gm_res = find_resource(dev, index);
|
gm_res = probe_resource(dev, index);
|
||||||
if (!gm_res)
|
if (!gm_res)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
|
|
@ -123,7 +123,7 @@ uintptr_t dw_i2c_base_address(unsigned int bus)
|
||||||
return (uintptr_t)NULL;
|
return (uintptr_t)NULL;
|
||||||
|
|
||||||
/* dev -> bar0 */
|
/* dev -> bar0 */
|
||||||
res = find_resource(dev, PCI_BASE_ADDRESS_0);
|
res = probe_resource(dev, PCI_BASE_ADDRESS_0);
|
||||||
if (res)
|
if (res)
|
||||||
return res->base;
|
return res->base;
|
||||||
|
|
||||||
|
|
|
@ -46,7 +46,7 @@ static void pch_smbus_init(struct device *dev)
|
||||||
~((1 << 8) | (1 << 10) | (1 << 12) | (1 << 14)), 0);
|
~((1 << 8) | (1 << 10) | (1 << 12) | (1 << 14)), 0);
|
||||||
|
|
||||||
/* Set Receive Slave Address */
|
/* Set Receive Slave Address */
|
||||||
res = find_resource(dev, PCI_BASE_ADDRESS_4);
|
res = probe_resource(dev, PCI_BASE_ADDRESS_4);
|
||||||
if (res)
|
if (res)
|
||||||
smbus_set_slave_addr(res->base, SMBUS_SLAVE_ADDR);
|
smbus_set_slave_addr(res->base, SMBUS_SLAVE_ADDR);
|
||||||
}
|
}
|
||||||
|
|
|
@ -55,7 +55,7 @@ void pch_thermal_configuration(void)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
res = find_resource(dev, PCI_BASE_ADDRESS_0);
|
res = probe_resource(dev, PCI_BASE_ADDRESS_0);
|
||||||
if (!res) {
|
if (!res) {
|
||||||
printk(BIOS_ERR, "ERROR: PCH thermal device not found!\n");
|
printk(BIOS_ERR, "ERROR: PCH thermal device not found!\n");
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -33,7 +33,7 @@ static bool is_usb_port_connected(const struct xhci_usb_info *info,
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
/* Calculate port status register address and read the status */
|
/* 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 the memory BAR is not allocated for XHCI, leave the devices enabled */
|
||||||
if (!res)
|
if (!res)
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -22,13 +22,13 @@ static void dnv_ns_uart_read_resources(struct device *dev)
|
||||||
pci_dev_read_resources(dev);
|
pci_dev_read_resources(dev);
|
||||||
if (!CONFIG(LEGACY_UART_MODE))
|
if (!CONFIG(LEGACY_UART_MODE))
|
||||||
return;
|
return;
|
||||||
struct resource *res = find_resource(dev, PCI_BASE_ADDRESS_0);
|
struct resource *res = probe_resource(dev, PCI_BASE_ADDRESS_0);
|
||||||
if (res == NULL)
|
if (res == NULL)
|
||||||
return;
|
return;
|
||||||
res->size = 0x8;
|
res->size = 0x8;
|
||||||
res->flags = IORESOURCE_IO | IORESOURCE_ASSIGNED | IORESOURCE_FIXED;
|
res->flags = IORESOURCE_IO | IORESOURCE_ASSIGNED | IORESOURCE_FIXED;
|
||||||
/* Do not configure membar */
|
/* Do not configure membar */
|
||||||
res = find_resource(dev, PCI_BASE_ADDRESS_1);
|
res = probe_resource(dev, PCI_BASE_ADDRESS_1);
|
||||||
if (res != NULL)
|
if (res != NULL)
|
||||||
res->flags = 0;
|
res->flags = 0;
|
||||||
compact_resources(dev);
|
compact_resources(dev);
|
||||||
|
|
|
@ -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)
|
static void set_xhci_lfps_sampling_offtime(struct device *dev, uint8_t time_ms)
|
||||||
{
|
{
|
||||||
void *addr;
|
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)
|
if (!res)
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -24,7 +24,7 @@ void graphics_soc_panel_init(struct device *dev)
|
||||||
|
|
||||||
panel_cfg = &conf->panel_cfg;
|
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)
|
if (!mmio_res || !mmio_res->base)
|
||||||
return;
|
return;
|
||||||
base = (void *)(uintptr_t)mmio_res->base;
|
base = (void *)(uintptr_t)mmio_res->base;
|
||||||
|
|
Loading…
Reference in New Issue