Skip to content

Commit 1c2b104

Browse files
KunWuChanShawn Guo
authored andcommitted
ARM: imx: Check return value of devm_kasprintf in imx_mmdc_perf_init
devm_kasprintf() returns a pointer to dynamically allocated memory which can be NULL upon failure. Ensure the allocation was successful by checking the pointer validity. Release the id allocated in 'mmdc_pmu_init' when 'devm_kasprintf' return NULL Suggested-by: Ahmad Fatoum <[email protected]> Fixes: e76bdfd ("ARM: imx: Added perf functionality to mmdc driver") Signed-off-by: Kunwu Chan <[email protected]> Signed-off-by: Shawn Guo <[email protected]>
1 parent 8ae06f1 commit 1c2b104

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

arch/arm/mach-imx/mmdc.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -501,6 +501,10 @@ static int imx_mmdc_perf_init(struct platform_device *pdev, void __iomem *mmdc_b
501501

502502
name = devm_kasprintf(&pdev->dev,
503503
GFP_KERNEL, "mmdc%d", ret);
504+
if (!name) {
505+
ret = -ENOMEM;
506+
goto pmu_release_id;
507+
}
504508

505509
pmu_mmdc->mmdc_ipg_clk = mmdc_ipg_clk;
506510
pmu_mmdc->devtype_data = (struct fsl_mmdc_devtype_data *)of_id->data;
@@ -523,9 +527,10 @@ static int imx_mmdc_perf_init(struct platform_device *pdev, void __iomem *mmdc_b
523527

524528
pmu_register_err:
525529
pr_warn("MMDC Perf PMU failed (%d), disabled\n", ret);
526-
ida_simple_remove(&mmdc_ida, pmu_mmdc->id);
527530
cpuhp_state_remove_instance_nocalls(cpuhp_mmdc_state, &pmu_mmdc->node);
528531
hrtimer_cancel(&pmu_mmdc->hrtimer);
532+
pmu_release_id:
533+
ida_simple_remove(&mmdc_ida, pmu_mmdc->id);
529534
pmu_free:
530535
kfree(pmu_mmdc);
531536
return ret;

0 commit comments

Comments
 (0)