diff mbox

[kernel,v2] powerpc/powernv: Check kzalloc() return value in pnv_pci_table_alloc

Message ID 20170327082737.14448-1-aik@ozlabs.ru (mailing list archive)
State Accepted
Commit 82eae1afbbdcaf2d716f88025736dc2d6f7afbf0
Headers show

Commit Message

Alexey Kardashevskiy March 27, 2017, 8:27 a.m. UTC
pnv_pci_table_alloc() ignores possible failure from kzalloc_node(),
this adds a check. There are 2 callers of pnv_pci_table_alloc(),
one already checks for tbl!=NULL, this adds WARN_ON() to the other path
which only happens during boot time in IODA1 and not expected to fail.

Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
---
Changes:
v2:
* s/BUG_ON/WARN_ON/
---
 arch/powerpc/platforms/powernv/pci-ioda.c | 3 +++
 arch/powerpc/platforms/powernv/pci.c      | 3 +++
 2 files changed, 6 insertions(+)

Comments

Alexey Kardashevskiy April 11, 2017, 8:28 a.m. UTC | #1
On 27/03/17 19:27, Alexey Kardashevskiy wrote:
> pnv_pci_table_alloc() ignores possible failure from kzalloc_node(),
> this adds a check. There are 2 callers of pnv_pci_table_alloc(),
> one already checks for tbl!=NULL, this adds WARN_ON() to the other path
> which only happens during boot time in IODA1 and not expected to fail.
> 
> Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
> ---
> Changes:
> v2:
> * s/BUG_ON/WARN_ON/

Bad/good?


> ---
>  arch/powerpc/platforms/powernv/pci-ioda.c | 3 +++
>  arch/powerpc/platforms/powernv/pci.c      | 3 +++
>  2 files changed, 6 insertions(+)
> 
> diff --git a/arch/powerpc/platforms/powernv/pci-ioda.c b/arch/powerpc/platforms/powernv/pci-ioda.c
> index e36738291c32..04ef03a5201b 100644
> --- a/arch/powerpc/platforms/powernv/pci-ioda.c
> +++ b/arch/powerpc/platforms/powernv/pci-ioda.c
> @@ -2128,6 +2128,9 @@ static void pnv_pci_ioda1_setup_dma_pe(struct pnv_phb *phb,
>  
>  found:
>  	tbl = pnv_pci_table_alloc(phb->hose->node);
> +	if (WARN_ON(!tbl))
> +		return;
> +
>  	iommu_register_group(&pe->table_group, phb->hose->global_number,
>  			pe->pe_number);
>  	pnv_pci_link_table_and_group(phb->hose->node, 0, tbl, &pe->table_group);
> diff --git a/arch/powerpc/platforms/powernv/pci.c b/arch/powerpc/platforms/powernv/pci.c
> index eb835e977e33..9acdf6889c0d 100644
> --- a/arch/powerpc/platforms/powernv/pci.c
> +++ b/arch/powerpc/platforms/powernv/pci.c
> @@ -766,6 +766,9 @@ struct iommu_table *pnv_pci_table_alloc(int nid)
>  	struct iommu_table *tbl;
>  
>  	tbl = kzalloc_node(sizeof(struct iommu_table), GFP_KERNEL, nid);
> +	if (!tbl)
> +		return NULL;
> +
>  	INIT_LIST_HEAD_RCU(&tbl->it_group_list);
>  
>  	return tbl;
>
Alexey Kardashevskiy April 28, 2017, 6:21 a.m. UTC | #2
On Tue, 11 Apr 2017 18:28:42 +1000
Alexey Kardashevskiy <aik@ozlabs.ru> wrote:

> On 27/03/17 19:27, Alexey Kardashevskiy wrote:
> > pnv_pci_table_alloc() ignores possible failure from kzalloc_node(),
> > this adds a check. There are 2 callers of pnv_pci_table_alloc(),
> > one already checks for tbl!=NULL, this adds WARN_ON() to the other path
> > which only happens during boot time in IODA1 and not expected to fail.
> > 
> > Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
> > ---
> > Changes:
> > v2:
> > * s/BUG_ON/WARN_ON/  
> 
> Bad/good?

Ping?


> 
> 
> > ---
> >  arch/powerpc/platforms/powernv/pci-ioda.c | 3 +++
> >  arch/powerpc/platforms/powernv/pci.c      | 3 +++
> >  2 files changed, 6 insertions(+)
> > 
> > diff --git a/arch/powerpc/platforms/powernv/pci-ioda.c b/arch/powerpc/platforms/powernv/pci-ioda.c
> > index e36738291c32..04ef03a5201b 100644
> > --- a/arch/powerpc/platforms/powernv/pci-ioda.c
> > +++ b/arch/powerpc/platforms/powernv/pci-ioda.c
> > @@ -2128,6 +2128,9 @@ static void pnv_pci_ioda1_setup_dma_pe(struct pnv_phb *phb,
> >  
> >  found:
> >  	tbl = pnv_pci_table_alloc(phb->hose->node);
> > +	if (WARN_ON(!tbl))
> > +		return;
> > +
> >  	iommu_register_group(&pe->table_group, phb->hose->global_number,
> >  			pe->pe_number);
> >  	pnv_pci_link_table_and_group(phb->hose->node, 0, tbl, &pe->table_group);
> > diff --git a/arch/powerpc/platforms/powernv/pci.c b/arch/powerpc/platforms/powernv/pci.c
> > index eb835e977e33..9acdf6889c0d 100644
> > --- a/arch/powerpc/platforms/powernv/pci.c
> > +++ b/arch/powerpc/platforms/powernv/pci.c
> > @@ -766,6 +766,9 @@ struct iommu_table *pnv_pci_table_alloc(int nid)
> >  	struct iommu_table *tbl;
> >  
> >  	tbl = kzalloc_node(sizeof(struct iommu_table), GFP_KERNEL, nid);
> > +	if (!tbl)
> > +		return NULL;
> > +
> >  	INIT_LIST_HEAD_RCU(&tbl->it_group_list);
> >  
> >  	return tbl;
> >   
> 
> 



--
Alexey
Michael Ellerman May 1, 2017, 2:58 a.m. UTC | #3
On Mon, 2017-03-27 at 08:27:37 UTC, Alexey Kardashevskiy wrote:
> pnv_pci_table_alloc() ignores possible failure from kzalloc_node(),
> this adds a check. There are 2 callers of pnv_pci_table_alloc(),
> one already checks for tbl!=NULL, this adds WARN_ON() to the other path
> which only happens during boot time in IODA1 and not expected to fail.
> 
> Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>

Applied to powerpc next, thanks.

https://git.kernel.org/powerpc/c/82eae1afbbdcaf2d716f88025736dc

cheers
diff mbox

Patch

diff --git a/arch/powerpc/platforms/powernv/pci-ioda.c b/arch/powerpc/platforms/powernv/pci-ioda.c
index e36738291c32..04ef03a5201b 100644
--- a/arch/powerpc/platforms/powernv/pci-ioda.c
+++ b/arch/powerpc/platforms/powernv/pci-ioda.c
@@ -2128,6 +2128,9 @@  static void pnv_pci_ioda1_setup_dma_pe(struct pnv_phb *phb,
 
 found:
 	tbl = pnv_pci_table_alloc(phb->hose->node);
+	if (WARN_ON(!tbl))
+		return;
+
 	iommu_register_group(&pe->table_group, phb->hose->global_number,
 			pe->pe_number);
 	pnv_pci_link_table_and_group(phb->hose->node, 0, tbl, &pe->table_group);
diff --git a/arch/powerpc/platforms/powernv/pci.c b/arch/powerpc/platforms/powernv/pci.c
index eb835e977e33..9acdf6889c0d 100644
--- a/arch/powerpc/platforms/powernv/pci.c
+++ b/arch/powerpc/platforms/powernv/pci.c
@@ -766,6 +766,9 @@  struct iommu_table *pnv_pci_table_alloc(int nid)
 	struct iommu_table *tbl;
 
 	tbl = kzalloc_node(sizeof(struct iommu_table), GFP_KERNEL, nid);
+	if (!tbl)
+		return NULL;
+
 	INIT_LIST_HEAD_RCU(&tbl->it_group_list);
 
 	return tbl;