diff --git a/drivers/pcie/host/pcie.c b/drivers/pcie/host/pcie.c index 52c7053e5b7..d8e04a9ed73 100644 --- a/drivers/pcie/host/pcie.c +++ b/drivers/pcie/host/pcie.c @@ -126,7 +126,7 @@ static bool pcie_get_bar(pcie_bdf_t bdf, bool io) { uint32_t reg = bar_index + PCIE_CONF_BAR0; - uint32_t cmd_reg = pcie_conf_read(bdf, PCIE_CONF_CMDSTAT); + uint32_t cmd_reg; bool ret = false; #ifdef CONFIG_PCIE_CONTROLLER const struct device *dev; @@ -158,6 +158,8 @@ static bool pcie_get_bar(pcie_bdf_t bdf, return false; } + cmd_reg = pcie_conf_read(bdf, PCIE_CONF_CMDSTAT); + /* IO/memory decode should be disabled before sizing/update BAR. */ pcie_conf_write(bdf, PCIE_CONF_CMDSTAT, cmd_reg & (~(PCIE_CONF_CMDSTAT_IO | PCIE_CONF_CMDSTAT_MEM)));