Skip to content

Commit 9f52aec

Browse files
Junhao HeSuzuki K Poulose
authored andcommitted
coresight: Fixes device's owner field for registered using coresight_init_driver()
The coresight_init_driver() of the coresight-core module is called from the sub coresgiht device (such as tmc/stm/funnle/...) module. It calls amba_driver_register() and Platform_driver_register(), which are macro functions that use the coresight-core's module to initialize the caller's owner field. Therefore, when the sub coresight device calls coresight_init_driver(), an incorrect THIS_MODULE value is captured. The sub coesgiht modules can be removed while their callbacks are running, resulting in a general protection failure. Add module parameter to coresight_init_driver() so can be called with the module of the callback. Fixes: 075b7cd ("coresight: Add helpers registering/removing both AMBA and platform drivers") Signed-off-by: Junhao He <hejunhao3@huawei.com> Signed-off-by: Suzuki K Poulose <suzuki.poulose@arm.com> Link: https://lore.kernel.org/r/20240918035327.9710-1-hejunhao3@huawei.com
1 parent 9c32cda commit 9f52aec

9 files changed

Lines changed: 14 additions & 11 deletions

File tree

drivers/hwtracing/coresight/coresight-catu.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -702,7 +702,7 @@ static int __init catu_init(void)
702702
{
703703
int ret;
704704

705-
ret = coresight_init_driver("catu", &catu_driver, &catu_platform_driver);
705+
ret = coresight_init_driver("catu", &catu_driver, &catu_platform_driver, THIS_MODULE);
706706
tmc_etr_set_catu_ops(&etr_catu_buf_ops);
707707
return ret;
708708
}

drivers/hwtracing/coresight/coresight-core.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1585,17 +1585,17 @@ module_init(coresight_init);
15851585
module_exit(coresight_exit);
15861586

15871587
int coresight_init_driver(const char *drv, struct amba_driver *amba_drv,
1588-
struct platform_driver *pdev_drv)
1588+
struct platform_driver *pdev_drv, struct module *owner)
15891589
{
15901590
int ret;
15911591

1592-
ret = amba_driver_register(amba_drv);
1592+
ret = __amba_driver_register(amba_drv, owner);
15931593
if (ret) {
15941594
pr_err("%s: error registering AMBA driver\n", drv);
15951595
return ret;
15961596
}
15971597

1598-
ret = platform_driver_register(pdev_drv);
1598+
ret = __platform_driver_register(pdev_drv, owner);
15991599
if (!ret)
16001600
return 0;
16011601

drivers/hwtracing/coresight/coresight-cpu-debug.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -774,7 +774,8 @@ static struct platform_driver debug_platform_driver = {
774774

775775
static int __init debug_init(void)
776776
{
777-
return coresight_init_driver("debug", &debug_driver, &debug_platform_driver);
777+
return coresight_init_driver("debug", &debug_driver, &debug_platform_driver,
778+
THIS_MODULE);
778779
}
779780

780781
static void __exit debug_exit(void)

drivers/hwtracing/coresight/coresight-funnel.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -433,7 +433,8 @@ static struct amba_driver dynamic_funnel_driver = {
433433

434434
static int __init funnel_init(void)
435435
{
436-
return coresight_init_driver("funnel", &dynamic_funnel_driver, &funnel_driver);
436+
return coresight_init_driver("funnel", &dynamic_funnel_driver, &funnel_driver,
437+
THIS_MODULE);
437438
}
438439

439440
static void __exit funnel_exit(void)

drivers/hwtracing/coresight/coresight-replicator.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -438,7 +438,8 @@ static struct amba_driver dynamic_replicator_driver = {
438438

439439
static int __init replicator_init(void)
440440
{
441-
return coresight_init_driver("replicator", &dynamic_replicator_driver, &replicator_driver);
441+
return coresight_init_driver("replicator", &dynamic_replicator_driver, &replicator_driver,
442+
THIS_MODULE);
442443
}
443444

444445
static void __exit replicator_exit(void)

drivers/hwtracing/coresight/coresight-stm.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1058,7 +1058,7 @@ static struct platform_driver stm_platform_driver = {
10581058

10591059
static int __init stm_init(void)
10601060
{
1061-
return coresight_init_driver("stm", &stm_driver, &stm_platform_driver);
1061+
return coresight_init_driver("stm", &stm_driver, &stm_platform_driver, THIS_MODULE);
10621062
}
10631063

10641064
static void __exit stm_exit(void)

drivers/hwtracing/coresight/coresight-tmc-core.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1060,7 +1060,7 @@ static struct platform_driver tmc_platform_driver = {
10601060

10611061
static int __init tmc_init(void)
10621062
{
1063-
return coresight_init_driver("tmc", &tmc_driver, &tmc_platform_driver);
1063+
return coresight_init_driver("tmc", &tmc_driver, &tmc_platform_driver, THIS_MODULE);
10641064
}
10651065

10661066
static void __exit tmc_exit(void)

drivers/hwtracing/coresight/coresight-tpiu.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ static struct platform_driver tpiu_platform_driver = {
318318

319319
static int __init tpiu_init(void)
320320
{
321-
return coresight_init_driver("tpiu", &tpiu_driver, &tpiu_platform_driver);
321+
return coresight_init_driver("tpiu", &tpiu_driver, &tpiu_platform_driver, THIS_MODULE);
322322
}
323323

324324
static void __exit tpiu_exit(void)

include/linux/coresight.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -723,7 +723,7 @@ coresight_find_output_type(struct coresight_platform_data *pdata,
723723
union coresight_dev_subtype subtype);
724724

725725
int coresight_init_driver(const char *drv, struct amba_driver *amba_drv,
726-
struct platform_driver *pdev_drv);
726+
struct platform_driver *pdev_drv, struct module *owner);
727727

728728
void coresight_remove_driver(struct amba_driver *amba_drv,
729729
struct platform_driver *pdev_drv);

0 commit comments

Comments
 (0)