Skip to content

Commit 0cca961

Browse files
Mani-Sadhasivamkwilczynski
authored andcommitted
PCI: Pass domain number to pci_bus_release_domain_nr() explicitly
The pci_bus_release_domain_nr() API is supposed to free the domain number allocated by pci_bus_find_domain_nr(). Most of the callers of pci_bus_find_domain_nr(), store the domain number in pci_bus::domain_nr. As such, the pci_bus_release_domain_nr() implicitly frees the domain number by dereferencing 'struct pci_bus'. However, one of the callers of this API, the PCI endpoint subsystem, doesn't have 'struct pci_bus', so it only passes NULL. Due to this, the API will end up dereferencing the NULL pointer. To fix this issue, pass the domain number to this API explicitly. Since 'struct pci_bus' is not used for anything else other than extracting the domain number, it makes sense to pass the domain number directly. Fixes: 0328947 ("PCI: endpoint: Assign PCI domain number for endpoint controllers") Closes: https://lore.kernel.org/linux-pci/[email protected] Link: https://lore.kernel.org/linux-pci/[email protected] Reported-by: Dan Carpenter <[email protected]> Signed-off-by: Manivannan Sadhasivam <[email protected]> [kwilczynski: commit log] Signed-off-by: Krzysztof Wilczyński <[email protected]>
1 parent d14bc28 commit 0cca961

File tree

5 files changed

+11
-11
lines changed

5 files changed

+11
-11
lines changed

drivers/pci/endpoint/pci-epc-core.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -840,7 +840,7 @@ void pci_epc_destroy(struct pci_epc *epc)
840840
device_unregister(&epc->dev);
841841

842842
#ifdef CONFIG_PCI_DOMAINS_GENERIC
843-
pci_bus_release_domain_nr(NULL, &epc->dev);
843+
pci_bus_release_domain_nr(&epc->dev, epc->domain_nr);
844844
#endif
845845
}
846846
EXPORT_SYMBOL_GPL(pci_epc_destroy);

drivers/pci/pci.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6801,16 +6801,16 @@ static int of_pci_bus_find_domain_nr(struct device *parent)
68016801
return ida_alloc(&pci_domain_nr_dynamic_ida, GFP_KERNEL);
68026802
}
68036803

6804-
static void of_pci_bus_release_domain_nr(struct pci_bus *bus, struct device *parent)
6804+
static void of_pci_bus_release_domain_nr(struct device *parent, int domain_nr)
68056805
{
6806-
if (bus->domain_nr < 0)
6806+
if (domain_nr < 0)
68076807
return;
68086808

68096809
/* Release domain from IDA where it was allocated. */
6810-
if (of_get_pci_domain_nr(parent->of_node) == bus->domain_nr)
6811-
ida_free(&pci_domain_nr_static_ida, bus->domain_nr);
6810+
if (of_get_pci_domain_nr(parent->of_node) == domain_nr)
6811+
ida_free(&pci_domain_nr_static_ida, domain_nr);
68126812
else
6813-
ida_free(&pci_domain_nr_dynamic_ida, bus->domain_nr);
6813+
ida_free(&pci_domain_nr_dynamic_ida, domain_nr);
68146814
}
68156815

68166816
int pci_bus_find_domain_nr(struct pci_bus *bus, struct device *parent)
@@ -6819,11 +6819,11 @@ int pci_bus_find_domain_nr(struct pci_bus *bus, struct device *parent)
68196819
acpi_pci_bus_find_domain_nr(bus);
68206820
}
68216821

6822-
void pci_bus_release_domain_nr(struct pci_bus *bus, struct device *parent)
6822+
void pci_bus_release_domain_nr(struct device *parent, int domain_nr)
68236823
{
68246824
if (!acpi_disabled)
68256825
return;
6826-
of_pci_bus_release_domain_nr(bus, parent);
6826+
of_pci_bus_release_domain_nr(parent, domain_nr);
68276827
}
68286828
#endif
68296829

drivers/pci/probe.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1061,7 +1061,7 @@ static int pci_register_host_bridge(struct pci_host_bridge *bridge)
10611061

10621062
free:
10631063
#ifdef CONFIG_PCI_DOMAINS_GENERIC
1064-
pci_bus_release_domain_nr(bus, parent);
1064+
pci_bus_release_domain_nr(parent, bus->domain_nr);
10651065
#endif
10661066
kfree(bus);
10671067
return err;

drivers/pci/remove.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ void pci_remove_root_bus(struct pci_bus *bus)
163163
#ifdef CONFIG_PCI_DOMAINS_GENERIC
164164
/* Release domain_nr if it was dynamically allocated */
165165
if (host_bridge->domain_nr == PCI_DOMAIN_NR_NOT_SET)
166-
pci_bus_release_domain_nr(bus, host_bridge->dev.parent);
166+
pci_bus_release_domain_nr(host_bridge->dev.parent, bus->domain_nr);
167167
#endif
168168

169169
pci_remove_bus(bus);

include/linux/pci.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1884,7 +1884,7 @@ static inline int acpi_pci_bus_find_domain_nr(struct pci_bus *bus)
18841884
{ return 0; }
18851885
#endif
18861886
int pci_bus_find_domain_nr(struct pci_bus *bus, struct device *parent);
1887-
void pci_bus_release_domain_nr(struct pci_bus *bus, struct device *parent);
1887+
void pci_bus_release_domain_nr(struct device *parent, int domain_nr);
18881888
#endif
18891889

18901890
/* Some architectures require additional setup to direct VGA traffic */

0 commit comments

Comments
 (0)