diff mbox

[RFC,v2,part,2,09/18] PCI, PPC: use hotplug-safe iterators to walk PCI buses

Message ID 1368550322-1045-9-git-send-email-jiang.liu@huawei.com (mailing list archive)
State New, archived
Delegated to: Bjorn Helgaas
Headers show

Commit Message

Jiang Liu May 14, 2013, 4:51 p.m. UTC
Enhance PPC architecture specific code to use hotplug-safe iterators
to walk PCI buses.

Signed-off-by: Jiang Liu <jiang.liu@huawei.com>
Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Cc: Paul Mackerras <paulus@samba.org>
Bjorn Helgaas <bhelgaas@google.com>
Cc: Gavin Shan <shangw@linux.vnet.ibm.com>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Grant Likely <grant.likely@secretlab.ca>
Cc: Bill Pemberton <wfp5p@virginia.edu>
Cc: Yinghai Lu <yinghai@kernel.org>
Cc: linuxppc-dev@lists.ozlabs.org
Cc: linux-kernel@vger.kernel.org
---
 arch/powerpc/kernel/pci-common.c |  4 ++--
 arch/powerpc/kernel/pci_64.c     | 13 +++++--------
 2 files changed, 7 insertions(+), 10 deletions(-)

Comments

Benjamin Herrenschmidt May 14, 2013, 11:30 p.m. UTC | #1
On Wed, 2013-05-15 at 00:51 +0800, Jiang Liu wrote:
> Enhance PPC architecture specific code to use hotplug-safe iterators
> to walk PCI buses.

I was about to ack it but then I saw:

> diff --git a/arch/powerpc/kernel/pci_64.c b/arch/powerpc/kernel/pci_64.c
> index 51a133a..a41c6dd 100644
> --- a/arch/powerpc/kernel/pci_64.c
> +++ b/arch/powerpc/kernel/pci_64.c
> @@ -208,7 +208,6 @@ long sys_pciconfig_iobase(long which, unsigned long in_bus,
>  			  unsigned long in_devfn)
>  {
>  	struct pci_controller* hose;
> -	struct list_head *ln;
>  	struct pci_bus *bus = NULL;
>  	struct device_node *hose_node;
>  
> @@ -229,18 +228,16 @@ long sys_pciconfig_iobase(long which, unsigned long in_bus,
>  	/* That syscall isn't quite compatible with PCI domains, but it's
>  	 * used on pre-domains setup. We return the first match
>  	 */
> -
> -	for (ln = pci_root_buses.next; ln != &pci_root_buses; ln = ln->next) {
> -		bus = pci_bus_b(ln);
> -		if (in_bus >= bus->number && in_bus <= bus->busn_res.end)
> +	for_each_pci_root_bus(bus)
> +		if (in_bus >= bus->number && in_bus <= bus->busn_res.end &&
> +		    bus->dev.of_node)
>  			break;
> -		bus = NULL;
> -	}
> -	if (bus == NULL || bus->dev.of_node == NULL)
> +	if (bus == NULL)
>  		return -ENODEV;

You just removed the NULL check for the of_node field...
 
>  	hose_node = bus->dev.of_node;
>  	hose = PCI_DN(hose_node)->phb;

Which is dereferrenced here.	

> +	pci_bus_put(bus);

On the other hand, the whole thing can probably be using
pci_bus_to_host() instead.... the above code is bitrotted.

>  	switch (which) {
>  	case IOBASE_BRIDGE_NUMBER:
 
Cheeers,
Ben.


--
To unsubscribe from this list: send the line "unsubscribe linux-pci" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Jiang Liu May 15, 2013, 3:07 p.m. UTC | #2
On 05/15/2013 07:30 AM, Benjamin Herrenschmidt wrote:
> On Wed, 2013-05-15 at 00:51 +0800, Jiang Liu wrote:
>> Enhance PPC architecture specific code to use hotplug-safe iterators
>> to walk PCI buses.
> I was about to ack it but then I saw:
>
>> diff --git a/arch/powerpc/kernel/pci_64.c b/arch/powerpc/kernel/pci_64.c
>> index 51a133a..a41c6dd 100644
>> --- a/arch/powerpc/kernel/pci_64.c
>> +++ b/arch/powerpc/kernel/pci_64.c
>> @@ -208,7 +208,6 @@ long sys_pciconfig_iobase(long which, unsigned long in_bus,
>>   			  unsigned long in_devfn)
>>   {
>>   	struct pci_controller* hose;
>> -	struct list_head *ln;
>>   	struct pci_bus *bus = NULL;
>>   	struct device_node *hose_node;
>>   
>> @@ -229,18 +228,16 @@ long sys_pciconfig_iobase(long which, unsigned long in_bus,
>>   	/* That syscall isn't quite compatible with PCI domains, but it's
>>   	 * used on pre-domains setup. We return the first match
>>   	 */
>> -
>> -	for (ln = pci_root_buses.next; ln != &pci_root_buses; ln = ln->next) {
>> -		bus = pci_bus_b(ln);
>> -		if (in_bus >= bus->number && in_bus <= bus->busn_res.end)
>> +	for_each_pci_root_bus(bus)
>> +		if (in_bus >= bus->number && in_bus <= bus->busn_res.end &&
>> +		    bus->dev.of_node)
>>   			break;
>> -		bus = NULL;
>> -	}
>> -	if (bus == NULL || bus->dev.of_node == NULL)
>> +	if (bus == NULL)
>>   		return -ENODEV;
> You just removed the NULL check for the of_node field...
Hi Benjamin,
     Thanks for review.
     I just moved the "bus->dev.of_node == NULL" into the above 
for_each_pci_root_bus()
loop:)
     Will send you another version according to your suggestion to use 
pci_bus_to_host()
to simplify the code.
Regards!
Gerry

>   
>>   	hose_node = bus->dev.of_node;
>>   	hose = PCI_DN(hose_node)->phb;
> Which is dereferrenced here.	
>
>> +	pci_bus_put(bus);
> On the other hand, the whole thing can probably be using
> pci_bus_to_host() instead.... the above code is bitrotted.
>
>>   	switch (which) {
>>   	case IOBASE_BRIDGE_NUMBER:
>   
> Cheeers,
> Ben.
>
>

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

Patch

diff --git a/arch/powerpc/kernel/pci-common.c b/arch/powerpc/kernel/pci-common.c
index fa12ae4..26fca09 100644
--- a/arch/powerpc/kernel/pci-common.c
+++ b/arch/powerpc/kernel/pci-common.c
@@ -1400,7 +1400,7 @@  void __init pcibios_resource_survey(void)
 	struct pci_bus *b;
 
 	/* Allocate and assign resources */
-	list_for_each_entry(b, &pci_root_buses, node)
+	for_each_pci_root_bus(b)
 		pcibios_allocate_bus_resources(b);
 	pcibios_allocate_resources(0);
 	pcibios_allocate_resources(1);
@@ -1410,7 +1410,7 @@  void __init pcibios_resource_survey(void)
 	 * bus available resources to avoid allocating things on top of them
 	 */
 	if (!pci_has_flag(PCI_PROBE_ONLY)) {
-		list_for_each_entry(b, &pci_root_buses, node)
+		for_each_pci_root_bus(b)
 			pcibios_reserve_legacy_regions(b);
 	}
 
diff --git a/arch/powerpc/kernel/pci_64.c b/arch/powerpc/kernel/pci_64.c
index 51a133a..a41c6dd 100644
--- a/arch/powerpc/kernel/pci_64.c
+++ b/arch/powerpc/kernel/pci_64.c
@@ -208,7 +208,6 @@  long sys_pciconfig_iobase(long which, unsigned long in_bus,
 			  unsigned long in_devfn)
 {
 	struct pci_controller* hose;
-	struct list_head *ln;
 	struct pci_bus *bus = NULL;
 	struct device_node *hose_node;
 
@@ -229,18 +228,16 @@  long sys_pciconfig_iobase(long which, unsigned long in_bus,
 	/* That syscall isn't quite compatible with PCI domains, but it's
 	 * used on pre-domains setup. We return the first match
 	 */
-
-	for (ln = pci_root_buses.next; ln != &pci_root_buses; ln = ln->next) {
-		bus = pci_bus_b(ln);
-		if (in_bus >= bus->number && in_bus <= bus->busn_res.end)
+	for_each_pci_root_bus(bus)
+		if (in_bus >= bus->number && in_bus <= bus->busn_res.end &&
+		    bus->dev.of_node)
 			break;
-		bus = NULL;
-	}
-	if (bus == NULL || bus->dev.of_node == NULL)
+	if (bus == NULL)
 		return -ENODEV;
 
 	hose_node = bus->dev.of_node;
 	hose = PCI_DN(hose_node)->phb;
+	pci_bus_put(bus);
 
 	switch (which) {
 	case IOBASE_BRIDGE_NUMBER: