Re: [PATCH v2 19/37] PCI: Add pci_stop_and_remove_bus()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 03/10/2012 03:00 PM, Yinghai Lu wrote:
> It supports both pci root bus and pci bus under pci bridge.
> 
> -v2: clear pci_bridge's subordinate.
> 
> Signed-off-by: Yinghai Lu <yinghai@xxxxxxxxxx>
> ---
>  drivers/pci/remove.c |   32 ++++++++++++++++++++++++++++++++
>  include/linux/pci.h  |    1 +
>  2 files changed, 33 insertions(+), 0 deletions(-)
> 
> diff --git a/drivers/pci/remove.c b/drivers/pci/remove.c
> index d4fdf7b..9ffc071 100644
> --- a/drivers/pci/remove.c
> +++ b/drivers/pci/remove.c
> @@ -170,6 +170,38 @@ void pci_stop_bus_device(struct pci_dev *dev)
>  	pci_stop_dev(dev);
>  }
>  
> +static void pci_stop_host_bridge(struct pci_host_bridge *bridge)
> +{
> +	device_unregister(&bridge->dev);
> +}
> +/*
> + * it will support pci root bus too, in that case we need
> + *  stop and remove host bridge
> + */
> +void pci_stop_and_remove_bus(struct pci_bus *bus)
> +{
> +	struct pci_host_bridge *host_bridge = NULL;
> +	struct pci_dev *pci_bridge = NULL;
> +
> +	pci_stop_bus_devices(bus);
> +
> +	if (pci_is_root_bus(bus)) {
> +		host_bridge = to_pci_host_bridge(bus->bridge);
> +		pci_stop_host_bridge(host_bridge);
> +	} else
> +		pci_bridge = bus->self;
> +
> +	__pci_remove_bus_devices(bus);
> +
> +	pci_remove_bus(bus);
> +
It seems that the bus and host_bridge structures may have already been freed here,
so should not access host_bridge structure any more.
> +	if (host_bridge)
> +		host_bridge->bus = NULL;
> +
> +	if (pci_bridge)
> +		pci_bridge->subordinate = NULL;
> +}
> +
>  EXPORT_SYMBOL(pci_stop_and_remove_bus_device);
>  EXPORT_SYMBOL(pci_stop_and_remove_behind_bridge);
>  EXPORT_SYMBOL_GPL(pci_stop_bus_device);
> diff --git a/include/linux/pci.h b/include/linux/pci.h
> index 860091f..8874b90 100644
> --- a/include/linux/pci.h
> +++ b/include/linux/pci.h
> @@ -702,6 +702,7 @@ extern void pci_dev_put(struct pci_dev *dev);
>  extern void pci_remove_bus(struct pci_bus *b);
>  extern void __pci_remove_bus_device(struct pci_dev *dev);
>  extern void pci_stop_and_remove_bus_device(struct pci_dev *dev);
> +void pci_stop_and_remove_bus(struct pci_bus *bus);
>  extern void pci_stop_bus_device(struct pci_dev *dev);
>  void pci_setup_cardbus(struct pci_bus *bus);
>  extern void pci_sort_breadthfirst(void);

--
To unsubscribe from this list: send the line "unsubscribe linux-pci" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [DMA Engine]     [Linux Coverity]     [Linux USB]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Greybus]

  Powered by Linux