Skip to content

Commit bb5bdc5

Browse files
x2018joergroedel
authored andcommitted
iommu/msm: Add a check for the return of kzalloc()
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. Besides, to propagate the error to the caller, the type of insert_iommu_master() is changed to `int`. Several instructions related to it are also updated. Signed-off-by: Xiaoke Wang <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Joerg Roedel <[email protected]>
1 parent af2d861 commit bb5bdc5

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

drivers/iommu/msm_iommu.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -583,7 +583,7 @@ static void print_ctx_regs(void __iomem *base, int ctx)
583583
GET_SCTLR(base, ctx), GET_ACTLR(base, ctx));
584584
}
585585

586-
static void insert_iommu_master(struct device *dev,
586+
static int insert_iommu_master(struct device *dev,
587587
struct msm_iommu_dev **iommu,
588588
struct of_phandle_args *spec)
589589
{
@@ -592,6 +592,10 @@ static void insert_iommu_master(struct device *dev,
592592

593593
if (list_empty(&(*iommu)->ctx_list)) {
594594
master = kzalloc(sizeof(*master), GFP_ATOMIC);
595+
if (!master) {
596+
dev_err(dev, "Failed to allocate iommu_master\n");
597+
return -ENOMEM;
598+
}
595599
master->of_node = dev->of_node;
596600
list_add(&master->list, &(*iommu)->ctx_list);
597601
dev_iommu_priv_set(dev, master);
@@ -601,10 +605,11 @@ static void insert_iommu_master(struct device *dev,
601605
if (master->mids[sid] == spec->args[0]) {
602606
dev_warn(dev, "Stream ID 0x%hx repeated; ignoring\n",
603607
sid);
604-
return;
608+
return 0;
605609
}
606610

607611
master->mids[master->num_mids++] = spec->args[0];
612+
return 0;
608613
}
609614

610615
static int qcom_iommu_of_xlate(struct device *dev,
@@ -624,7 +629,7 @@ static int qcom_iommu_of_xlate(struct device *dev,
624629
goto fail;
625630
}
626631

627-
insert_iommu_master(dev, &iommu, spec);
632+
ret = insert_iommu_master(dev, &iommu, spec);
628633
fail:
629634
spin_unlock_irqrestore(&msm_iommu_lock, flags);
630635

0 commit comments

Comments
 (0)