hc
2024-01-03 2f7c68cb55ecb7331f2381deb497c27155f32faf
kernel/arch/arm/mach-imx/mmdc.c
....@@ -99,6 +99,7 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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: