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.
User a macro to automatically add the THIS_MODULE param to coresight_init_driver() to fix this.
Fixes: 075b7cd7ad7d ("coresight: Add helpers registering/removing both AMBA and platform drivers") Signed-off-by: Junhao He hejunhao3@huawei.com --- Changes in v2: - even a macro to automatically add the THIS_MODULE param for coresight_init_driver(); - Link to v1: https://lore.kernel.org/lkml/c3744062-f7c1-82df-2fa1-591da3b2dc5e@huawei.com... --- drivers/hwtracing/coresight/coresight-core.c | 11 ++++++----- include/linux/coresight.h | 7 +++++-- 2 files changed, 11 insertions(+), 7 deletions(-)
diff --git a/drivers/hwtracing/coresight/coresight-core.c b/drivers/hwtracing/coresight/coresight-core.c index 0a9380350fb5..abf2e4fd4de0 100644 --- a/drivers/hwtracing/coresight/coresight-core.c +++ b/drivers/hwtracing/coresight/coresight-core.c @@ -1486,18 +1486,19 @@ static void __exit coresight_exit(void) 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) +int coresight_init_driver_owner(const char *drv, struct amba_driver *amba_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;
@@ -1505,7 +1506,7 @@ int coresight_init_driver(const char *drv, struct amba_driver *amba_drv, amba_driver_unregister(amba_drv); return ret; } -EXPORT_SYMBOL_GPL(coresight_init_driver); +EXPORT_SYMBOL_GPL(coresight_init_driver_owner);
void coresight_remove_driver(struct amba_driver *amba_drv, struct platform_driver *pdev_drv) diff --git a/include/linux/coresight.h b/include/linux/coresight.h index 17276965ff1d..b07455956f7a 100644 --- a/include/linux/coresight.h +++ b/include/linux/coresight.h @@ -689,8 +689,11 @@ coresight_find_output_type(struct coresight_platform_data *pdata, enum coresight_dev_type type, union coresight_dev_subtype subtype);
-int coresight_init_driver(const char *drv, struct amba_driver *amba_drv, - struct platform_driver *pdev_drv); +int coresight_init_driver_owner(const char *drv, struct amba_driver *amba_drv, + struct platform_driver *pdev_drv, struct module *owner); + +#define coresight_init_driver(name, amba_drv, pdev_drv) \ + coresight_init_driver_owner(name, amba_drv, pdev_drv, THIS_MODULE)
void coresight_remove_driver(struct amba_driver *amba_drv, struct platform_driver *pdev_drv);