Skip to content

Commit 66db99f

Browse files
nxpfrankliwilldeacon
authored andcommitted
perf/imx_ddr: Move ida_alloc() from ddr_perf_init() to ddr_perf_probe()
Move ida_alloc() from helper ddr_perf_init() into ddr_perf_probe() to clarify why ida_free() must be called at the error path. Add return value check for ida_alloc(). Rename label 'cpuhp_state_err' to 'idr_free' to make the code clearer, since two error paths now jump to this label. Signed-off-by: Frank Li <Frank.Li@nxp.com> Signed-off-by: Will Deacon <will@kernel.org>
1 parent de8209e commit 66db99f

1 file changed

Lines changed: 12 additions & 9 deletions

File tree

drivers/perf/fsl_imx8_ddr_perf.c

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -645,8 +645,8 @@ static void ddr_perf_pmu_disable(struct pmu *pmu)
645645
{
646646
}
647647

648-
static int ddr_perf_init(struct ddr_pmu *pmu, void __iomem *base,
649-
struct device *dev)
648+
static void ddr_perf_init(struct ddr_pmu *pmu, void __iomem *base,
649+
struct device *dev)
650650
{
651651
*pmu = (struct ddr_pmu) {
652652
.pmu = (struct pmu) {
@@ -667,9 +667,6 @@ static int ddr_perf_init(struct ddr_pmu *pmu, void __iomem *base,
667667
.base = base,
668668
.dev = dev,
669669
};
670-
671-
pmu->id = ida_alloc(&ddr_ida, GFP_KERNEL);
672-
return pmu->id;
673670
}
674671

675672
static irqreturn_t ddr_perf_irq_handler(int irq, void *p)
@@ -753,15 +750,21 @@ static int ddr_perf_probe(struct platform_device *pdev)
753750
if (!pmu)
754751
return -ENOMEM;
755752

756-
num = ddr_perf_init(pmu, base, &pdev->dev);
753+
ddr_perf_init(pmu, base, &pdev->dev);
757754

758755
platform_set_drvdata(pdev, pmu);
759756

757+
num = ida_alloc(&ddr_ida, GFP_KERNEL);
758+
if (num < 0)
759+
return num;
760+
761+
pmu->id = num;
762+
760763
name = devm_kasprintf(&pdev->dev, GFP_KERNEL, DDR_PERF_DEV_NAME "%d",
761764
num);
762765
if (!name) {
763766
ret = -ENOMEM;
764-
goto cpuhp_state_err;
767+
goto idr_free;
765768
}
766769

767770
pmu->devtype_data = of_device_get_match_data(&pdev->dev);
@@ -774,7 +777,7 @@ static int ddr_perf_probe(struct platform_device *pdev)
774777

775778
if (ret < 0) {
776779
dev_err(&pdev->dev, "cpuhp_setup_state_multi failed\n");
777-
goto cpuhp_state_err;
780+
goto idr_free;
778781
}
779782

780783
pmu->cpuhp_state = ret;
@@ -821,7 +824,7 @@ static int ddr_perf_probe(struct platform_device *pdev)
821824
cpuhp_state_remove_instance_nocalls(pmu->cpuhp_state, &pmu->node);
822825
cpuhp_instance_err:
823826
cpuhp_remove_multi_state(pmu->cpuhp_state);
824-
cpuhp_state_err:
827+
idr_free:
825828
ida_free(&ddr_ida, pmu->id);
826829
dev_warn(&pdev->dev, "i.MX8 DDR Perf PMU failed (%d), disabled\n", ret);
827830
return ret;

0 commit comments

Comments
 (0)