[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <tencent_6A5CCC9FB9221C4A1414E1534A3DFFC62008@qq.com>
Date: Fri, 25 Mar 2022 10:08:01 +0800
From: xkernel.wang@...mail.com
To: agross@...nel.org, bjorn.andersson@...aro.org, joro@...tes.org,
will@...nel.org
Cc: linux-arm-msm@...r.kernel.org, iommu@...ts.linux-foundation.org,
linux-kernel@...r.kernel.org,
Xiaoke Wang <xkernel.wang@...mail.com>
Subject: [PATCH] iommu/msm: add a check for the return of kzalloc()
From: Xiaoke Wang <xkernel.wang@...mail.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@...mail.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);
--
Powered by blists - more mailing lists