Commit f00c3f9e authored by Johannes Berg's avatar Johannes Berg Committed by Luca Coelho
Browse files

iwlwifi: pcie: handle pcim_iomap_table() failures better



pcim_iomap_table() might return NULL, so we shouldn't unconditionally
dereference the return value by taking the [0] entry.

Handle this better by checking for NULL first, and then separately
checking if the [0] entry is NULL.

Signed-off-by: default avatarJohannes Berg <johannes.berg@intel.com>
Signed-off-by: default avatarLuca Coelho <luciano.coelho@intel.com>
Link: https://lore.kernel.org/r/iwlwifi.20210612142637.9aa4f0e3574a.I458b283f203d5f927f00be1bfbd4b8ebf11c5ae4@changeid


Signed-off-by: default avatarLuca Coelho <luciano.coelho@intel.com>
parent 8835a64f
Loading
Loading
Loading
Loading
+10 −2
Original line number Original line Diff line number Diff line
@@ -3413,6 +3413,7 @@ struct iwl_trans *iwl_trans_pcie_alloc(struct pci_dev *pdev,
	struct iwl_trans *trans;
	struct iwl_trans *trans;
	int ret, addr_size;
	int ret, addr_size;
	const struct iwl_trans_ops *ops = &trans_ops_pcie_gen2;
	const struct iwl_trans_ops *ops = &trans_ops_pcie_gen2;
	void __iomem * const *table;


	if (!cfg_trans->gen2)
	if (!cfg_trans->gen2)
		ops = &trans_ops_pcie;
		ops = &trans_ops_pcie;
@@ -3485,9 +3486,16 @@ struct iwl_trans *iwl_trans_pcie_alloc(struct pci_dev *pdev,
		goto out_no_pci;
		goto out_no_pci;
	}
	}


	trans_pcie->hw_base = pcim_iomap_table(pdev)[0];
	table = pcim_iomap_table(pdev);
	if (!trans_pcie->hw_base) {
	if (!table) {
		dev_err(&pdev->dev, "pcim_iomap_table failed\n");
		dev_err(&pdev->dev, "pcim_iomap_table failed\n");
		ret = -ENOMEM;
		goto out_no_pci;
	}

	trans_pcie->hw_base = table[0];
	if (!trans_pcie->hw_base) {
		dev_err(&pdev->dev, "couldn't find IO mem in first BAR\n");
		ret = -ENODEV;
		ret = -ENODEV;
		goto out_no_pci;
		goto out_no_pci;
	}
	}