PCI: apple: Initialize pcie->nvecs before using it
PATCH 1/1 PCI: apple: Initialize pcie->nvecs before using it
apple_pcie_setup_port computes ilog2(pcie->nvecs) to setup the number of MSIs available for each port. It is however called before apple_msi_init which actually initializes pcie->nvecs.
Luckily, pcie->nvecs is part of kzalloc-ed structure and thus initialized as zero. ilog2(0) happens to be 0xffffffff which then just configures more MSIs in hardware than we actually have. This doesn't break anything because we never hand out those vectors. Let's swap the order of the two calls so that we use the correctly initialized value.
--- drivers/pci/controller/pcie-apple.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/pci/controller/pcie-apple.c +5 -1
@@ -783,6 +783,10 @@ static int apple_pcie_init(struct pci_config_window *cfg) cfg->priv = pcie;INIT_LIST_HEAD (&pcie->ports); + ret =apple_msi_init (pcie); +if (ret) +return ret; +for_each_child_of_node (dev->of_node, of_port) { ret =apple_pcie_setup_port (pcie, of_port);if (ret) {
@@ -792,7 +796,7 @@ static int apple_pcie_init(struct pci_config_window *cfg) } } -return apple_msi_init (pcie); +return 0 ; }static int apple_pcie_probe (struct platform_device *pdev)
Signature · 1 line
2.25.1
Quoted 11 lines · Sven Peter
apple_pcie_setup_portcomputesilog2(pcie->nvecs)to setup the number of MSIs available for each port. It is however called beforeapple_msi_initwhich actually initializespcie->nvecs.
Luckily,pcie->nvecsis part of kzalloc-ed structure and thus initialized as zero. ilog2(0) happens to be0xffffffffwhich then just configures more MSIs in hardware than we actually have. This doesn't break anything because we never hand out those vectors. Let's swap the order of the two calls so that we use the correctly initialized value.
Quoted 2 lines
Fixes 476c41ed4597 ("PCI: apple: Implement MSI support")Signed-off-by Sven Peter <[email protected]>
Is mise le meas/Regards,
Eric Curtin
Quoted 32 lines
--- drivers/pci/controller/pcie-apple.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)drivers/pci/controller/pcie-apple.c +5
-2@@ -783,6 +783,10 @@ static int apple_pcie_init(struct pci_config_window *cfg) cfg->priv = pcie;INIT_LIST_HEAD (&pcie->ports); + ret =apple_msi_init (pcie); +if (ret) +return ret; +for_each_child_of_node (dev->of_node, of_port) { ret =apple_pcie_setup_port (pcie, of_port);if (ret) {@@ -792,7 +796,7 @@ static int apple_pcie_init(struct pci_config_window *cfg) } } -return apple_msi_init (pcie); +return 0 ; }static int apple_pcie_probe (struct platform_device *pdev) --2.25.1
Whoops!
Quoted 42 lines · Sven Peter
apple_pcie_setup_portcomputesilog2(pcie->nvecs)to setup the number of MSIs available for each port. It is however called beforeapple_msi_initwhich actually initializespcie->nvecs.
Luckily,pcie->nvecsis part of kzalloc-ed structure and thus initialized as zero. ilog2(0) happens to be0xffffffffwhich then just configures more MSIs in hardware than we actually have. This doesn't break anything because we never hand out those vectors. Let's swap the order of the two calls so that we use the correctly initialized value.Fixes 476c41ed4597 ("PCI: apple: Implement MSI support")Signed-off-by Sven Peter <[email protected]>---
drivers/pci/controller/pcie-apple.c| 6 +++++-1 file changed, 5 insertions(+), 1 deletion(-)drivers/pci/controller/pcie-apple.c +5
-1@@ -783,6 +783,10 @@ static int apple_pcie_init(struct pci_config_window *cfg) cfg->priv = pcie;INIT_LIST_HEAD (&pcie->ports); + ret =apple_msi_init (pcie); +if (ret) +return ret; + for_each_child_of_node(dev->of_node, of_port) { ret =apple_pcie_setup_port (pcie, of_port);if (ret) {@@ -792,7 +796,7 @@ static int apple_pcie_init(struct pci_config_window *cfg) } } -return apple_msi_init (pcie); +return 0 ; }static int apple_pcie_probe (struct platform_device *pdev)Signature · 1 line
2.25.1
Quoted 11 lines · Sven Peter
apple_pcie_setup_portcomputesilog2(pcie->nvecs)to setup the number of MSIs available for each port. It is however called beforeapple_msi_initwhich actually initializespcie->nvecs.
Luckily,pcie->nvecsis part of kzalloc-ed structure and thus initialized as zero. ilog2(0) happens to be0xffffffffwhich then just configures more MSIs in hardware than we actually have. This doesn't break anything because we never hand out those vectors. Let's swap the order of the two calls so that we use the correctly initialized value.
Quoted 2 lines
Fixes 476c41ed4597 ("PCI: apple: Implement MSI support")Signed-off-by Sven Peter <[email protected]>
Huh, how embarrassing... :-/
M.
Signature · 1 line
Without deviation from the norm, progress is not possible.
Krzysztof Wilczyński
AppliedHello,
Quoted 9 lines
apple_pcie_setup_portcomputesilog2(pcie->nvecs)to setup the number of MSIs available for each port. It is however called beforeapple_msi_initwhich actually initializespcie->nvecs.
Luckily,pcie->nvecsis part of kzalloc-ed structure and thus initialized as zero. ilog2(0) happens to be0xffffffffwhich then just configures more MSIs in hardware than we actually have. This doesn't break anything because we never hand out those vectors. Let's swap the order of the two calls so that we use the correctly initialized value.
Applied to controller/apple, thank you!
[1/1] PCI: apple: Initialize pcie->nvecs before use
https://git.kernel.org/pci/pci/c/328a16477027 Krzysztof