* [PATCH] PCI: mvebu: allocate ports with pcie struct
@ 2026-04-11 4:30 Rosen Penev
0 siblings, 0 replies; only message in thread
From: Rosen Penev @ 2026-04-11 4:30 UTC (permalink / raw)
To: linux-pci
Cc: Thomas Petazzoni, Pali Rohár, Lorenzo Pieralisi,
Krzysztof Wilczyński, Manivannan Sadhasivam, Rob Herring,
Bjorn Helgaas, Kees Cook, Gustavo A. R. Silva
Use a flexible array member to combine allocations and simplify
slightly.
Add __counted_by for extra runtime analysis.
Needed to move mvebu_pcie struct below others as flexible array members
require full definitions.
Signed-off-by: Rosen Penev <rosenp@gmail.com>
---
drivers/pci/controller/pci-mvebu.c | 33 ++++++++++++------------------
1 file changed, 13 insertions(+), 20 deletions(-)
diff --git a/drivers/pci/controller/pci-mvebu.c b/drivers/pci/controller/pci-mvebu.c
index a72aa57591c0..dea50f6e88be 100644
--- a/drivers/pci/controller/pci-mvebu.c
+++ b/drivers/pci/controller/pci-mvebu.c
@@ -78,18 +78,6 @@
#define PCIE_DEBUG_CTRL 0x1a60
#define PCIE_DEBUG_SOFT_RESET BIT(20)
-struct mvebu_pcie_port;
-
-/* Structure representing all PCIe interfaces */
-struct mvebu_pcie {
- struct platform_device *pdev;
- struct mvebu_pcie_port *ports;
- struct resource io;
- struct resource realio;
- struct resource mem;
- int nports;
-};
-
struct mvebu_pcie_window {
phys_addr_t base;
phys_addr_t remap;
@@ -125,6 +113,16 @@ struct mvebu_pcie_port {
int intx_irq;
};
+/* Structure representing all PCIe interfaces */
+struct mvebu_pcie {
+ struct platform_device *pdev;
+ struct resource io;
+ struct resource realio;
+ struct resource mem;
+ int nports;
+ struct mvebu_pcie_port ports[] __counted_by(nports);
+};
+
static inline void mvebu_writel(struct mvebu_pcie_port *port, u32 val, u32 reg)
{
writel(val, port->base + reg);
@@ -1455,11 +1453,13 @@ static int mvebu_pcie_probe(struct platform_device *pdev)
struct device_node *child;
int num, i, ret;
- bridge = devm_pci_alloc_host_bridge(dev, sizeof(struct mvebu_pcie));
+ num = of_get_available_child_count(np);
+ bridge = devm_pci_alloc_host_bridge(dev, struct_size(pcie, ports, num));
if (!bridge)
return -ENOMEM;
pcie = pci_host_bridge_priv(bridge);
+ pcie->nports = num;
pcie->pdev = pdev;
platform_set_drvdata(pdev, pcie);
@@ -1467,12 +1467,6 @@ static int mvebu_pcie_probe(struct platform_device *pdev)
if (ret)
return ret;
- num = of_get_available_child_count(np);
-
- pcie->ports = devm_kcalloc(dev, num, sizeof(*pcie->ports), GFP_KERNEL);
- if (!pcie->ports)
- return -ENOMEM;
-
i = 0;
for_each_available_child_of_node(np, child) {
struct mvebu_pcie_port *port = &pcie->ports[i];
@@ -1488,7 +1482,6 @@ static int mvebu_pcie_probe(struct platform_device *pdev)
port->dn = child;
i++;
}
- pcie->nports = i;
for (i = 0; i < pcie->nports; i++) {
struct mvebu_pcie_port *port = &pcie->ports[i];
--
2.53.0
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2026-04-11 4:31 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-04-11 4:30 [PATCH] PCI: mvebu: allocate ports with pcie struct Rosen Penev
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox