Skip to contentSkip to conversation

iommu: add null pointer check

PATCH In review [email protected] 2 participants 2 messages Mar 29, 2022 – Apr 28, 2022 IOMMU

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 iommu: add null pointer check

From: Lv Ruyi <[email protected]>

kmem_cache_zalloc is a memory allocation function which can return NULL when some internal memory errors happen. Add null pointer check to avoid dereferencing null pointer.

---
 drivers/iommu/fsl_pamu_domain.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/iommu/fsl_pamu_domain.c +4 -0
index 69a4a62dc3b9..43849c027298 100644
@@ -152,6 +152,10 @@ static void attach_device(struct fsl_dma_domain *dma_domain, int liodn, struct d
 	}
 
 	info = kmem_cache_zalloc(iommu_devinfo_cache, GFP_ATOMIC);
+	if (!info) {
+		spin_unlock_irqrestore(&device_domain_lock, flags);
+		return;
+	}
 
 	info->dev = dev;
 	info->liodn = liodn;
Signature · 6 lines
2.25.1

_______________________________________________
iommu mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/iommu
maintainer
#1 lore raw
Quoted 17 lines · On Tue, Mar 29, 2022 at 05:53:22AM +0000, [email protected] wrote:

From: Lv Ruyi <[email protected]>

kmem_cache_zalloc is a memory allocation function which can return NULL when some internal memory errors happen. Add null pointer check to avoid dereferencing null pointer.

---
 drivers/iommu/fsl_pamu_domain.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/iommu/fsl_pamu_domain.c +0 -0
index 69a4a62dc3b9..43849c027298 100644

drivers/iommu/fsl_pamu_domain.c static void attach_device(struct fsl_dma_domain *dma_domain, int liodn, struct d · line 158

Quoted 7 lines
drivers/iommu/fsl_pamu_domain.c +4 -0
@@ -152,6 +152,10 @@ static void attach_device(struct fsl_dma_domain *dma_domain, int liodn, struct d
 	}
 
 	info = kmem_cache_zalloc(iommu_devinfo_cache, GFP_ATOMIC);
+	if (!info) {
+		spin_unlock_irqrestore(&device_domain_lock, flags);
+		return;
+	}

Such errors need to be propagated.

_______________________________________________
iommu mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/iommu