Skip to content

Commit 257aedb

Browse files
Junhao Hewilldeacon
authored andcommitted
drivers/perf: hisi: add NULL check for name
When allocations fails that can be NULL now. If the name provided is NULL, then the initialization process of the PMU type and dev will be skipped in function perf_pmu_register(). Consequently, the PMU will not be able to register into the kernel. Moreover, in the case of unregister the PMU, the function device_del() will need to handle NULL pointers, which potentially can cause issues. So move this allocation above the cpuhp_state_add_instance() and directly return if it does fail. Signed-off-by: Junhao He <[email protected]> Reviewed-by: Jonathan Cameron <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Will Deacon <[email protected]>
1 parent 25d8c25 commit 257aedb

File tree

3 files changed

+20
-15
lines changed

3 files changed

+20
-15
lines changed

drivers/perf/hisilicon/hisi_uncore_ddrc_pmu.c

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -499,13 +499,6 @@ static int hisi_ddrc_pmu_probe(struct platform_device *pdev)
499499
if (ret)
500500
return ret;
501501

502-
ret = cpuhp_state_add_instance(CPUHP_AP_PERF_ARM_HISI_DDRC_ONLINE,
503-
&ddrc_pmu->node);
504-
if (ret) {
505-
dev_err(&pdev->dev, "Error %d registering hotplug;\n", ret);
506-
return ret;
507-
}
508-
509502
if (ddrc_pmu->identifier >= HISI_PMU_V2)
510503
name = devm_kasprintf(&pdev->dev, GFP_KERNEL,
511504
"hisi_sccl%u_ddrc%u_%u",
@@ -516,6 +509,16 @@ static int hisi_ddrc_pmu_probe(struct platform_device *pdev)
516509
"hisi_sccl%u_ddrc%u", ddrc_pmu->sccl_id,
517510
ddrc_pmu->index_id);
518511

512+
if (!name)
513+
return -ENOMEM;
514+
515+
ret = cpuhp_state_add_instance(CPUHP_AP_PERF_ARM_HISI_DDRC_ONLINE,
516+
&ddrc_pmu->node);
517+
if (ret) {
518+
dev_err(&pdev->dev, "Error %d registering hotplug;\n", ret);
519+
return ret;
520+
}
521+
519522
hisi_pmu_init(ddrc_pmu, THIS_MODULE);
520523

521524
ret = perf_pmu_register(&ddrc_pmu->pmu, name, -1);

drivers/perf/hisilicon/hisi_uncore_hha_pmu.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -510,15 +510,18 @@ static int hisi_hha_pmu_probe(struct platform_device *pdev)
510510
if (ret)
511511
return ret;
512512

513+
name = devm_kasprintf(&pdev->dev, GFP_KERNEL, "hisi_sccl%u_hha%u",
514+
hha_pmu->sccl_id, hha_pmu->index_id);
515+
if (!name)
516+
return -ENOMEM;
517+
513518
ret = cpuhp_state_add_instance(CPUHP_AP_PERF_ARM_HISI_HHA_ONLINE,
514519
&hha_pmu->node);
515520
if (ret) {
516521
dev_err(&pdev->dev, "Error %d registering hotplug\n", ret);
517522
return ret;
518523
}
519524

520-
name = devm_kasprintf(&pdev->dev, GFP_KERNEL, "hisi_sccl%u_hha%u",
521-
hha_pmu->sccl_id, hha_pmu->index_id);
522525
hisi_pmu_init(hha_pmu, THIS_MODULE);
523526

524527
ret = perf_pmu_register(&hha_pmu->pmu, name, -1);

drivers/perf/hisilicon/hisi_uncore_l3c_pmu.c

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -544,19 +544,18 @@ static int hisi_l3c_pmu_probe(struct platform_device *pdev)
544544
if (ret)
545545
return ret;
546546

547+
name = devm_kasprintf(&pdev->dev, GFP_KERNEL, "hisi_sccl%u_l3c%u",
548+
l3c_pmu->sccl_id, l3c_pmu->ccl_id);
549+
if (!name)
550+
return -ENOMEM;
551+
547552
ret = cpuhp_state_add_instance(CPUHP_AP_PERF_ARM_HISI_L3_ONLINE,
548553
&l3c_pmu->node);
549554
if (ret) {
550555
dev_err(&pdev->dev, "Error %d registering hotplug\n", ret);
551556
return ret;
552557
}
553558

554-
/*
555-
* CCL_ID is used to identify the L3C in the same SCCL which was
556-
* used _UID by mistake.
557-
*/
558-
name = devm_kasprintf(&pdev->dev, GFP_KERNEL, "hisi_sccl%u_l3c%u",
559-
l3c_pmu->sccl_id, l3c_pmu->ccl_id);
560559
hisi_pmu_init(l3c_pmu, THIS_MODULE);
561560

562561
ret = perf_pmu_register(&l3c_pmu->pmu, name, -1);

0 commit comments

Comments
 (0)