Skip to content

Commit ce63c44

Browse files
windhlmpe
authored andcommitted
powerpc/pci-common: Fix refcount bug for 'phb->dn'
In pcibios_alloc_controller(), 'phb' is allocated and escaped into global 'hose_list'. So we should call of_node_get() when a new reference created into 'phb->dn'. And when phb is freed, we should call of_node_put() on it. NOTE: This function is called in the iteration of for_each_xx in chrp_find_bridges() and pSeries_discover_phbs(). If there is no of_node_get(), the object may be prematurely freed. Signed-off-by: Liang He <[email protected]> Signed-off-by: Michael Ellerman <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 605c27f commit ce63c44

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

arch/powerpc/kernel/pci-common.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ struct pci_controller *pcibios_alloc_controller(struct device_node *dev)
135135
list_add_tail(&phb->list_node, &hose_list);
136136
spin_unlock(&hose_spinlock);
137137

138-
phb->dn = dev;
138+
phb->dn = of_node_get(dev);
139139
phb->is_dynamic = slab_is_available();
140140
#ifdef CONFIG_PPC64
141141
if (dev) {
@@ -158,7 +158,7 @@ void pcibios_free_controller(struct pci_controller *phb)
158158
/* Clear bit of phb_bitmap to allow reuse of this PHB number. */
159159
if (phb->global_number < MAX_PHBS)
160160
clear_bit(phb->global_number, phb_bitmap);
161-
161+
of_node_put(phb->dn);
162162
list_del(&phb->list_node);
163163
spin_unlock(&hose_spinlock);
164164

0 commit comments

Comments
 (0)