All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] iommu/msm: add a check for the return of kzalloc()
@ 2022-03-25  2:08 ` xkernel.wang
  0 siblings, 0 replies; 6+ messages in thread
From: xkernel.wang @ 2022-03-25  2:08 UTC (permalink / raw)
  To: agross, bjorn.andersson, joro, will
  Cc: linux-arm-msm, iommu, linux-kernel, Xiaoke Wang

From: Xiaoke Wang <xkernel.wang@foxmail.com>

kzalloc() is a memory allocation function which can return NULL when
some internal memory errors happen. So it is better to check it to
prevent potential wrong memory access.

Signed-off-by: Xiaoke Wang <xkernel.wang@foxmail.com>
---
 drivers/iommu/msm_iommu.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/drivers/iommu/msm_iommu.c b/drivers/iommu/msm_iommu.c
index 3a38352..697ad63 100644
--- a/drivers/iommu/msm_iommu.c
+++ b/drivers/iommu/msm_iommu.c
@@ -597,6 +597,10 @@ static void insert_iommu_master(struct device *dev,
 
 	if (list_empty(&(*iommu)->ctx_list)) {
 		master = kzalloc(sizeof(*master), GFP_ATOMIC);
+		if (!master) {
+			dev_err(dev, "Failed to allocate iommu_master\n");
+			return;
+		}
 		master->of_node = dev->of_node;
 		list_add(&master->list, &(*iommu)->ctx_list);
 		dev_iommu_priv_set(dev, master);
-- 

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

end of thread, other threads:[~2022-04-28 14:52 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-03-25  2:08 [PATCH] iommu/msm: add a check for the return of kzalloc() xkernel.wang
2022-03-25  2:08 ` xkernel.wang
2022-04-28  8:03 ` Joerg Roedel
2022-04-28  8:03   ` Joerg Roedel
2022-04-28 14:51 ` Jeffrey Hugo
2022-04-28 14:51   ` Jeffrey Hugo

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.