]> www.infradead.org Git - users/dwmw2/linux.git/commitdiff
coresight: Fixes device's owner field for registered using coresight_init_driver()
authorJunhao He <hejunhao3@huawei.com>
Wed, 18 Sep 2024 03:53:27 +0000 (11:53 +0800)
committerSuzuki K Poulose <suzuki.poulose@arm.com>
Tue, 29 Apr 2025 17:47:37 +0000 (18:47 +0100)
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: 075b7cd7ad7d ("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
drivers/hwtracing/coresight/coresight-catu.c
drivers/hwtracing/coresight/coresight-core.c
drivers/hwtracing/coresight/coresight-cpu-debug.c
drivers/hwtracing/coresight/coresight-funnel.c
drivers/hwtracing/coresight/coresight-replicator.c
drivers/hwtracing/coresight/coresight-stm.c
drivers/hwtracing/coresight/coresight-tmc-core.c
drivers/hwtracing/coresight/coresight-tpiu.c
include/linux/coresight.h

index fa170c966bc3be8a86c16b366106c8e84b1d5d99..96cb48b140afa809c1b5ecc48ce64a7ee16b4dac 100644 (file)
@@ -702,7 +702,7 @@ static int __init catu_init(void)
 {
        int ret;
 
-       ret = coresight_init_driver("catu", &catu_driver, &catu_platform_driver);
+       ret = coresight_init_driver("catu", &catu_driver, &catu_platform_driver, THIS_MODULE);
        tmc_etr_set_catu_ops(&etr_catu_buf_ops);
        return ret;
 }
index fb43ef6a3b1f0d6d9740e729e7eeb86a5d77ba4a..dabec7073aedaa7e300ebe81caca45250f86b515 100644 (file)
@@ -1585,17 +1585,17 @@ module_init(coresight_init);
 module_exit(coresight_exit);
 
 int coresight_init_driver(const char *drv, struct amba_driver *amba_drv,
-                         struct platform_driver *pdev_drv)
+                         struct platform_driver *pdev_drv, struct module *owner)
 {
        int ret;
 
-       ret = amba_driver_register(amba_drv);
+       ret = __amba_driver_register(amba_drv, owner);
        if (ret) {
                pr_err("%s: error registering AMBA driver\n", drv);
                return ret;
        }
 
-       ret = platform_driver_register(pdev_drv);
+       ret = __platform_driver_register(pdev_drv, owner);
        if (!ret)
                return 0;
 
index 342c3aaf414dd88e36b1c1adb944b6ddc872d50d..a871d997330b09bdb741f35c59108b0b3252cc54 100644 (file)
@@ -774,7 +774,8 @@ static struct platform_driver debug_platform_driver = {
 
 static int __init debug_init(void)
 {
-       return coresight_init_driver("debug", &debug_driver, &debug_platform_driver);
+       return coresight_init_driver("debug", &debug_driver, &debug_platform_driver,
+                                    THIS_MODULE);
 }
 
 static void __exit debug_exit(void)
index 0541712b2bcb69e0c08bfcf8cddc940d46edf044..124fc2e26cfb1af9a23ec19d20c00b912a8583cf 100644 (file)
@@ -433,7 +433,8 @@ static struct amba_driver dynamic_funnel_driver = {
 
 static int __init funnel_init(void)
 {
-       return coresight_init_driver("funnel", &dynamic_funnel_driver, &funnel_driver);
+       return coresight_init_driver("funnel", &dynamic_funnel_driver, &funnel_driver,
+                                    THIS_MODULE);
 }
 
 static void __exit funnel_exit(void)
index ee7ee79f6cf7750c41d5d53c5120c32e3c683066..572dcd2bac16d9f56679dbe444ce6a067e06a25e 100644 (file)
@@ -438,7 +438,8 @@ static struct amba_driver dynamic_replicator_driver = {
 
 static int __init replicator_init(void)
 {
-       return coresight_init_driver("replicator", &dynamic_replicator_driver, &replicator_driver);
+       return coresight_init_driver("replicator", &dynamic_replicator_driver, &replicator_driver,
+                                    THIS_MODULE);
 }
 
 static void __exit replicator_exit(void)
index 26f9339f38b938a90440463b74e924d5102e319d..527347e4d16c5d444cd4dc7735b7a384163304ae 100644 (file)
@@ -1058,7 +1058,7 @@ static struct platform_driver stm_platform_driver = {
 
 static int __init stm_init(void)
 {
-       return coresight_init_driver("stm", &stm_driver, &stm_platform_driver);
+       return coresight_init_driver("stm", &stm_driver, &stm_platform_driver, THIS_MODULE);
 }
 
 static void __exit stm_exit(void)
index a7814e8e657b211da77bbfede63b29c482621d77..455b1c9b15682c9e028fe8e018998287b926f1d4 100644 (file)
@@ -1060,7 +1060,7 @@ static struct platform_driver tmc_platform_driver = {
 
 static int __init tmc_init(void)
 {
-       return coresight_init_driver("tmc", &tmc_driver, &tmc_platform_driver);
+       return coresight_init_driver("tmc", &tmc_driver, &tmc_platform_driver, THIS_MODULE);
 }
 
 static void __exit tmc_exit(void)
index 97ef36f03ec20716fbf4e058398e873671bde0c4..3e01592884280819c16398cbb5e09cbaee5d3efb 100644 (file)
@@ -318,7 +318,7 @@ static struct platform_driver tpiu_platform_driver = {
 
 static int __init tpiu_init(void)
 {
-       return coresight_init_driver("tpiu", &tpiu_driver, &tpiu_platform_driver);
+       return coresight_init_driver("tpiu", &tpiu_driver, &tpiu_platform_driver, THIS_MODULE);
 }
 
 static void __exit tpiu_exit(void)
index d79a242b271d6e1ed7021b7c3e156cafb82d2787..cfcf6e4707ed942bebd695b5a5bfe022fc09a6af 100644 (file)
@@ -723,7 +723,7 @@ coresight_find_output_type(struct coresight_platform_data *pdata,
                           union coresight_dev_subtype subtype);
 
 int coresight_init_driver(const char *drv, struct amba_driver *amba_drv,
-                         struct platform_driver *pdev_drv);
+                         struct platform_driver *pdev_drv, struct module *owner);
 
 void coresight_remove_driver(struct amba_driver *amba_drv,
                             struct platform_driver *pdev_drv);