diff mbox

pci/of: Don't crash when bridge parent is NULL.

Message ID 1313519077-18457-1-git-send-email-david.daney@cavium.com (mailing list archive)
State New, archived
Headers show

Commit Message

David Daney Aug. 16, 2011, 6:24 p.m. UTC
In pcibios_get_phb_of_node(), we will crash while booting if
bus->bridge->parent is NULL.

Check for this case and avoid dereferencing the NULL pointer.

Signed-off-by: David Daney <david.daney@cavium.com>
Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Cc: Jesse Barnes <jbarnes@virtuousgeek.org>
Cc: linux-pci@vger.kernel.org
Cc: Grant Likely <grant.likely@secretlab.ca>
---
 drivers/pci/of.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

Comments

Benjamin Herrenschmidt Aug. 16, 2011, 7:16 p.m. UTC | #1
On Tue, 2011-08-16 at 11:24 -0700, David Daney wrote:
> In pcibios_get_phb_of_node(), we will crash while booting if
> bus->bridge->parent is NULL.
> 
> Check for this case and avoid dereferencing the NULL pointer.
> 
> Signed-off-by: David Daney <david.daney@cavium.com>

Acked-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>

Jesse or Grant, I'm travelling, can any of you send that to Linus asap ?

Cheers,
Ben.

> Cc: Jesse Barnes <jbarnes@virtuousgeek.org>
> Cc: linux-pci@vger.kernel.org
> Cc: Grant Likely <grant.likely@secretlab.ca>
> ---
>  drivers/pci/of.c |    2 +-
>  1 files changed, 1 insertions(+), 1 deletions(-)
> 
> diff --git a/drivers/pci/of.c b/drivers/pci/of.c
> index c94d37e..f092993 100644
> --- a/drivers/pci/of.c
> +++ b/drivers/pci/of.c
> @@ -55,7 +55,7 @@ struct device_node * __weak pcibios_get_phb_of_node(struct pci_bus *bus)
>  	 */
>  	if (bus->bridge->of_node)
>  		return of_node_get(bus->bridge->of_node);
> -	if (bus->bridge->parent->of_node)
> +	if (bus->bridge->parent && bus->bridge->parent->of_node)
>  		return of_node_get(bus->bridge->parent->of_node);
>  	return NULL;
>  }


--
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
Jesse Barnes Aug. 17, 2011, 4:11 a.m. UTC | #2
On Tue, 16 Aug 2011 14:16:18 -0500
Benjamin Herrenschmidt <benh@kernel.crashing.org> wrote:

> On Tue, 2011-08-16 at 11:24 -0700, David Daney wrote:
> > In pcibios_get_phb_of_node(), we will crash while booting if
> > bus->bridge->parent is NULL.
> > 
> > Check for this case and avoid dereferencing the NULL pointer.
> > 
> > Signed-off-by: David Daney <david.daney@cavium.com>
> 
> Acked-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
> 
> Jesse or Grant, I'm travelling, can any of you send that to Linus
> asap ?

Sure looks fine.  I'll send it off tomorrow (now that I'm back :).

Thanks,
Jesse
--
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
Grant Likely Aug. 17, 2011, 11:29 a.m. UTC | #3
On 11-08-16 10:11 PM, Jesse Barnes wrote:
> On Tue, 16 Aug 2011 14:16:18 -0500
> Benjamin Herrenschmidt<benh@kernel.crashing.org>  wrote:
>
>> On Tue, 2011-08-16 at 11:24 -0700, David Daney wrote:
>>> In pcibios_get_phb_of_node(), we will crash while booting if
>>> bus->bridge->parent is NULL.
>>>
>>> Check for this case and avoid dereferencing the NULL pointer.
>>>
>>> Signed-off-by: David Daney<david.daney@cavium.com>
>>
>> Acked-by: Benjamin Herrenschmidt<benh@kernel.crashing.org>
>>
>> Jesse or Grant, I'm travelling, can any of you send that to Linus
>> asap ?
>
> Sure looks fine.  I'll send it off tomorrow (now that I'm back :).
>
> Thanks,
> Jesse

thanks Jesse.

Acked-by: Grant Likely <grant.likely@secretlab.ca>
--
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/drivers/pci/of.c b/drivers/pci/of.c
index c94d37e..f092993 100644
--- a/drivers/pci/of.c
+++ b/drivers/pci/of.c
@@ -55,7 +55,7 @@  struct device_node * __weak pcibios_get_phb_of_node(struct pci_bus *bus)
 	 */
 	if (bus->bridge->of_node)
 		return of_node_get(bus->bridge->of_node);
-	if (bus->bridge->parent->of_node)
+	if (bus->bridge->parent && bus->bridge->parent->of_node)
 		return of_node_get(bus->bridge->parent->of_node);
 	return NULL;
 }