Skip to content

Commit ebeb49f

Browse files
Angus ChenShawn Guo
authored andcommitted
ARM: imx: Call ida_simple_remove() for ida_simple_get
The function call ida_simple_get maybe fail,we should deal with it. And if ida_simple_get success ,it need to call ida_simple_remove also. BTW,devm_kasprintf can handle id is zero for consistency. Fixes: e76bdfd ("ARM: imx: Added perf functionality to mmdc driver") Signed-off-by: Angus Chen <[email protected]> Signed-off-by: Shawn Guo <[email protected]>
1 parent 1b929c0 commit ebeb49f

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

arch/arm/mach-imx/mmdc.c

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ struct mmdc_pmu {
9999
cpumask_t cpu;
100100
struct hrtimer hrtimer;
101101
unsigned int active_events;
102+
int id;
102103
struct device *dev;
103104
struct perf_event *mmdc_events[MMDC_NUM_COUNTERS];
104105
struct hlist_node node;
@@ -433,8 +434,6 @@ static enum hrtimer_restart mmdc_pmu_timer_handler(struct hrtimer *hrtimer)
433434
static int mmdc_pmu_init(struct mmdc_pmu *pmu_mmdc,
434435
void __iomem *mmdc_base, struct device *dev)
435436
{
436-
int mmdc_num;
437-
438437
*pmu_mmdc = (struct mmdc_pmu) {
439438
.pmu = (struct pmu) {
440439
.task_ctx_nr = perf_invalid_context,
@@ -452,15 +451,16 @@ static int mmdc_pmu_init(struct mmdc_pmu *pmu_mmdc,
452451
.active_events = 0,
453452
};
454453

455-
mmdc_num = ida_simple_get(&mmdc_ida, 0, 0, GFP_KERNEL);
454+
pmu_mmdc->id = ida_simple_get(&mmdc_ida, 0, 0, GFP_KERNEL);
456455

457-
return mmdc_num;
456+
return pmu_mmdc->id;
458457
}
459458

460459
static int imx_mmdc_remove(struct platform_device *pdev)
461460
{
462461
struct mmdc_pmu *pmu_mmdc = platform_get_drvdata(pdev);
463462

463+
ida_simple_remove(&mmdc_ida, pmu_mmdc->id);
464464
cpuhp_state_remove_instance_nocalls(cpuhp_mmdc_state, &pmu_mmdc->node);
465465
perf_pmu_unregister(&pmu_mmdc->pmu);
466466
iounmap(pmu_mmdc->mmdc_base);
@@ -474,7 +474,6 @@ static int imx_mmdc_perf_init(struct platform_device *pdev, void __iomem *mmdc_b
474474
{
475475
struct mmdc_pmu *pmu_mmdc;
476476
char *name;
477-
int mmdc_num;
478477
int ret;
479478
const struct of_device_id *of_id =
480479
of_match_device(imx_mmdc_dt_ids, &pdev->dev);
@@ -497,14 +496,14 @@ static int imx_mmdc_perf_init(struct platform_device *pdev, void __iomem *mmdc_b
497496
cpuhp_mmdc_state = ret;
498497
}
499498

500-
mmdc_num = mmdc_pmu_init(pmu_mmdc, mmdc_base, &pdev->dev);
501-
pmu_mmdc->mmdc_ipg_clk = mmdc_ipg_clk;
502-
if (mmdc_num == 0)
503-
name = "mmdc";
504-
else
505-
name = devm_kasprintf(&pdev->dev,
506-
GFP_KERNEL, "mmdc%d", mmdc_num);
499+
ret = mmdc_pmu_init(pmu_mmdc, mmdc_base, &pdev->dev);
500+
if (ret < 0)
501+
goto pmu_free;
507502

503+
name = devm_kasprintf(&pdev->dev,
504+
GFP_KERNEL, "mmdc%d", ret);
505+
506+
pmu_mmdc->mmdc_ipg_clk = mmdc_ipg_clk;
508507
pmu_mmdc->devtype_data = (struct fsl_mmdc_devtype_data *)of_id->data;
509508

510509
hrtimer_init(&pmu_mmdc->hrtimer, CLOCK_MONOTONIC,
@@ -525,6 +524,7 @@ static int imx_mmdc_perf_init(struct platform_device *pdev, void __iomem *mmdc_b
525524

526525
pmu_register_err:
527526
pr_warn("MMDC Perf PMU failed (%d), disabled\n", ret);
527+
ida_simple_remove(&mmdc_ida, pmu_mmdc->id);
528528
cpuhp_state_remove_instance_nocalls(cpuhp_mmdc_state, &pmu_mmdc->node);
529529
hrtimer_cancel(&pmu_mmdc->hrtimer);
530530
pmu_free:

0 commit comments

Comments
 (0)