Skip to contentSkip to conversation

sparc64: move dereference after check for NULL

PATCH New Dan Carpenter 1 participant 1 message Nov 25, 2016

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 sparc64: move dereference after check for NULL

We shouldn't dereference "iommu" until after we have checked that it is non-NULL.

Fixes f08978b0fdbf ("sparc64: Enable sun4v dma ops to use IOMMU v2 APIs")

---
Applies to sparc.git

arch/sparc/kernel/pci_sun4v.c +2 -3
index 06981cc7..cabb609 100644
@@ -478,11 +478,10 @@ static int dma_4v_map_sg(struct device *dev, struct scatterlist *sglist,
 	BUG_ON(direction = DMA_NONE);
 
 	iommu = dev->archdata.iommu;
-	atu = iommu->atu;
-
 	if (nelems = 0 || !iommu)
 		return 0;
-	
+	atu = iommu->atu;
+
 	prot = HV_PCI_MAP_ATTR_READ;
 	if (direction != DMA_TO_DEVICE)
 		prot |= HV_PCI_MAP_ATTR_WRITE;