linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] powerpc/pseries: Add a null judgment after iommu_pseries_alloc_group
@ 2022-07-01  9:17 Deming Wang
  2022-11-24 11:08 ` Michael Ellerman
  0 siblings, 1 reply; 2+ messages in thread
From: Deming Wang @ 2022-07-01  9:17 UTC (permalink / raw)
  To: mpe; +Cc: benh, paulus, linuxppc-dev, linux-kernel, Deming Wang

We should avoid use the return value directly after  call
iommu_pseries_alloc_group. Because it_may return a null.

Signed-off-by: Deming Wang <wangdeming@inspur.com>
---
 arch/powerpc/platforms/pseries/iommu.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/arch/powerpc/platforms/pseries/iommu.c b/arch/powerpc/platforms/pseries/iommu.c
index fba64304e859..801eb9d4bdca 100644
--- a/arch/powerpc/platforms/pseries/iommu.c
+++ b/arch/powerpc/platforms/pseries/iommu.c
@@ -649,6 +649,9 @@ static void pci_dma_bus_setup_pSeries(struct pci_bus *bus)
 	pci->phb->dma_window_base_cur = 0x8000000ul;
 
 	pci->table_group = iommu_pseries_alloc_group(pci->phb->node);
+	if (!pci->table_group)
+		return;
+
 	tbl = pci->table_group->tables[0];
 
 	iommu_table_setparms(pci->phb, dn, tbl);
@@ -734,6 +737,9 @@ static void pci_dma_bus_setup_pSeriesLP(struct pci_bus *bus)
 
 	if (!ppci->table_group) {
 		ppci->table_group = iommu_pseries_alloc_group(ppci->phb->node);
+		if (!ppci->table_group)
+			return;
+
 		tbl = ppci->table_group->tables[0];
 		iommu_table_setparms_lpar(ppci->phb, pdn, tbl,
 				ppci->table_group, dma_window);
@@ -765,6 +771,9 @@ static void pci_dma_dev_setup_pSeries(struct pci_dev *dev)
 
 		pr_debug(" --> first child, no bridge. Allocating iommu table.\n");
 		PCI_DN(dn)->table_group = iommu_pseries_alloc_group(phb->node);
+		if (!PCI_DN(dn)->table_group)
+			return;
+
 		tbl = PCI_DN(dn)->table_group->tables[0];
 		iommu_table_setparms(phb, dn, tbl);
 
@@ -1521,6 +1530,9 @@ static void pci_dma_dev_setup_pSeriesLP(struct pci_dev *dev)
 	pci = PCI_DN(pdn);
 	if (!pci->table_group) {
 		pci->table_group = iommu_pseries_alloc_group(pci->phb->node);
+		if (!pci->table_group)
+			return;
+
 		tbl = pci->table_group->tables[0];
 		iommu_table_setparms_lpar(pci->phb, pdn, tbl,
 				pci->table_group, dma_window);
-- 
2.27.0


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] powerpc/pseries: Add a null judgment after iommu_pseries_alloc_group
  2022-07-01  9:17 [PATCH] powerpc/pseries: Add a null judgment after iommu_pseries_alloc_group Deming Wang
@ 2022-11-24 11:08 ` Michael Ellerman
  0 siblings, 0 replies; 2+ messages in thread
From: Michael Ellerman @ 2022-11-24 11:08 UTC (permalink / raw)
  To: Deming Wang; +Cc: benh, paulus, linuxppc-dev, linux-kernel, Deming Wang

Deming Wang <wangdeming@inspur.com> writes:
> We should avoid use the return value directly after  call
> iommu_pseries_alloc_group. Because it_may return a null.

We should probably at least print a warning in that case though?

Otherwise someone's PCI device will not work with no indication why, or
more likely the kernel will crash elsewhere with no indication that the
group allocation is the original cause.

cheers

> diff --git a/arch/powerpc/platforms/pseries/iommu.c b/arch/powerpc/platforms/pseries/iommu.c
> index fba64304e859..801eb9d4bdca 100644
> --- a/arch/powerpc/platforms/pseries/iommu.c
> +++ b/arch/powerpc/platforms/pseries/iommu.c
> @@ -649,6 +649,9 @@ static void pci_dma_bus_setup_pSeries(struct pci_bus *bus)
>  	pci->phb->dma_window_base_cur = 0x8000000ul;
>  
>  	pci->table_group = iommu_pseries_alloc_group(pci->phb->node);
> +	if (!pci->table_group)
> +		return;
> +
>  	tbl = pci->table_group->tables[0];
>  
>  	iommu_table_setparms(pci->phb, dn, tbl);
> @@ -734,6 +737,9 @@ static void pci_dma_bus_setup_pSeriesLP(struct pci_bus *bus)
>  
>  	if (!ppci->table_group) {
>  		ppci->table_group = iommu_pseries_alloc_group(ppci->phb->node);
> +		if (!ppci->table_group)
> +			return;
> +
>  		tbl = ppci->table_group->tables[0];
>  		iommu_table_setparms_lpar(ppci->phb, pdn, tbl,
>  				ppci->table_group, dma_window);
> @@ -765,6 +771,9 @@ static void pci_dma_dev_setup_pSeries(struct pci_dev *dev)
>  
>  		pr_debug(" --> first child, no bridge. Allocating iommu table.\n");
>  		PCI_DN(dn)->table_group = iommu_pseries_alloc_group(phb->node);
> +		if (!PCI_DN(dn)->table_group)
> +			return;
> +
>  		tbl = PCI_DN(dn)->table_group->tables[0];
>  		iommu_table_setparms(phb, dn, tbl);
>  
> @@ -1521,6 +1530,9 @@ static void pci_dma_dev_setup_pSeriesLP(struct pci_dev *dev)
>  	pci = PCI_DN(pdn);
>  	if (!pci->table_group) {
>  		pci->table_group = iommu_pseries_alloc_group(pci->phb->node);
> +		if (!pci->table_group)
> +			return;
> +
>  		tbl = pci->table_group->tables[0];
>  		iommu_table_setparms_lpar(pci->phb, pdn, tbl,
>  				pci->table_group, dma_window);
> -- 
> 2.27.0

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-11-24 11:08 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-07-01  9:17 [PATCH] powerpc/pseries: Add a null judgment after iommu_pseries_alloc_group Deming Wang
2022-11-24 11:08 ` Michael Ellerman

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).