Skip to content

Commit d8650c0

Browse files
svenpeter42kwilczynski
authored andcommitted
PCI: apple: Initialize pcie->nvecs before use
The apple_pcie_setup_port() function computes ilog2(pcie->nvecs) to set up the number of MSIs available for each port. However, it's called before apple_msi_init(), which initializes pcie->nvecs. Luckily, pcie->nvecs is part of kzalloc()-ed structure and, as such, initialized as zero. ilog2(0) happens to be 0xffffffff which then simply configures more MSIs in hardware than we have. This doesn't break anything because we never hand out those vectors. Thus, swap the order of the two calls so that the correctly initialized value is then used. [kwilczynski: commit log] Link: https://lore.kernel.org/linux-pci/20230311133453.63246-1-sven@svenpeter.dev Fixes: 476c41e ("PCI: apple: Implement MSI support") Signed-off-by: Sven Peter <sven@svenpeter.dev> Signed-off-by: Krzysztof Wilczyński <kwilczynski@kernel.org> Reviewed-by: Marc Zyngier <maz@kernel.org> Reviewed-by: Alyssa Rosenzweig <alyssa@rosenzweig.io> Reviewed-by: Eric Curtin <ecurtin@redhat.com>
1 parent 06c2afb commit d8650c0

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

drivers/pci/controller/pcie-apple.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -783,6 +783,10 @@ static int apple_pcie_init(struct pci_config_window *cfg)
783783
cfg->priv = pcie;
784784
INIT_LIST_HEAD(&pcie->ports);
785785

786+
ret = apple_msi_init(pcie);
787+
if (ret)
788+
return ret;
789+
786790
for_each_child_of_node(dev->of_node, of_port) {
787791
ret = apple_pcie_setup_port(pcie, of_port);
788792
if (ret) {
@@ -792,7 +796,7 @@ static int apple_pcie_init(struct pci_config_window *cfg)
792796
}
793797
}
794798

795-
return apple_msi_init(pcie);
799+
return 0;
796800
}
797801

798802
static int apple_pcie_probe(struct platform_device *pdev)

0 commit comments

Comments
 (0)