Skip to contentSkip to conversation

clk: scu/imx8qxp: do not register driver in probe()

PATCH Applied Danilo Krummrich 5 participants 11 messages Feb 12 – Mar 18

Subsystems (4)
lore
Share & tools
lore

Danilo Krummrich

author maintainer
#0 lore raw

PATCH v2 1/1 clk: scu/imx8qxp: do not register driver in probe()

imx_clk_scu_init() registers the imx_clk_scu_driver while commonly being called from IMX driver's probe() callbacks.

However, it neither makes sense to register drivers from probe() callbacks of other drivers, nor does the driver core allow registering drivers with a device lock already being held.

The latter was revealed by commit dc23806a7c47 ("driver core: enforce device_lock for driver_match_device()") leading to a deadlock condition described in [1].

Besides that, nothing seems to unregister the imx_clk_scu_driver once the corresponding driver module is unloaded, which leaves the driver-core with a dangling pointer.

Also, if there are multiple matching devices for the imx8qxp_clk_driver, imx8qxp_clk_probe() calls imx_clk_scu_init() multiple times. However, any subsequent call after the first one will fail, since the driver-core does not allow to register the same struct platform_driver multiple times.

Hence, register the imx_clk_scu_driver from module_init() and unregister it in module_exit().

Note that we first register the imx8qxp_clk_driver and then call imx_clk_scu_module_init() to avoid having to call imx_clk_scu_module_exit() in the unwind path of imx8qxp_clk_init().

Fixes dc23806a7c47 ("driver core: enforce device_lock for driver_match_device()")
Fixes 220175cd3979 ("clk: imx: scu: fix build break when compiled as modules")

---
Changes in v2:
- Expand commit message, mentioning a third bug fixed by this patch and noting the order of platform_driver_register() and imx_clk_scu_module_init() in imx8qxp_clk_init().
- Rename imx8qxp_{init,exit} to imx8qxp_clk_{init,exit}.
- Link to v1: https://lore.kernel.org/driver-core/[email protected]/

---
 drivers/clk/imx/clk-imx8qxp.c | 24 +++++++++++++++++++++++-
 drivers/clk/imx/clk-scu.c     | 12 +++++++++++-
 drivers/clk/imx/clk-scu.h     |  2 ++
 3 files changed, 36 insertions(+), 2 deletions(-)
drivers/clk/imx/clk-imx8qxp.c +23 -1
index 3ae162625bb1..c781425a005e 100644
@@ -346,7 +346,29 @@ static struct platform_driver imx8qxp_clk_driver = {
 	},
 	.probe = imx8qxp_clk_probe,
 };
-module_platform_driver(imx8qxp_clk_driver);
+
+static int __init imx8qxp_clk_init(void)
+{
+	int ret;
+
+	ret = platform_driver_register(&imx8qxp_clk_driver);
+	if (ret)
+		return ret;
+
+	ret = imx_clk_scu_module_init();
+	if (ret)
+		platform_driver_unregister(&imx8qxp_clk_driver);
+
+	return ret;
+}
+module_init(imx8qxp_clk_init);
+
+static void __exit imx8qxp_clk_exit(void)
+{
+	imx_clk_scu_module_exit();
+	platform_driver_unregister(&imx8qxp_clk_driver);
+}
+module_exit(imx8qxp_clk_exit);
 
 MODULE_AUTHOR("Aisheng Dong <[email protected]>");
 MODULE_DESCRIPTION("NXP i.MX8QXP clock driver");
drivers/clk/imx/clk-scu.c +11 -1
index 34c9dc1fb20e..c90d21e05f91 100644
@@ -191,6 +191,16 @@ static bool imx_scu_clk_is_valid(u32 rsrc_id)
 	return p != NULL;
 }
 
+int __init imx_clk_scu_module_init(void)
+{
+	return platform_driver_register(&imx_clk_scu_driver);
+}
+
+void __exit imx_clk_scu_module_exit(void)
+{
+	return platform_driver_unregister(&imx_clk_scu_driver);
+}
+
 int imx_clk_scu_init(struct device_node *np,
 		     const struct imx_clk_scu_rsrc_table *data)
 {
@@ -215,7 +225,7 @@ int imx_clk_scu_init(struct device_node *np,
 		rsrc_table = data;
 	}
 
-	return platform_driver_register(&imx_clk_scu_driver);
+	return 0;
 }
 
 /*
drivers/clk/imx/clk-scu.h +2 -0
index af7b697f51ca..ca82f2cce897 100644
@@ -25,6 +25,8 @@ extern const struct imx_clk_scu_rsrc_table imx_clk_scu_rsrc_imx8dxl;
 extern const struct imx_clk_scu_rsrc_table imx_clk_scu_rsrc_imx8qxp;
 extern const struct imx_clk_scu_rsrc_table imx_clk_scu_rsrc_imx8qm;
 
+int __init imx_clk_scu_module_init(void);
+void __exit imx_clk_scu_module_exit(void);
 int imx_clk_scu_init(struct device_node *np,
 		     const struct imx_clk_scu_rsrc_table *data);
 struct clk_hw *imx_scu_of_clk_src_get(struct of_phandle_args *clkspec,

base-commit: 192c0159402e6bfbe13de6f8379546943297783d

Signature · 1 line
2.53.0
Reviewed-by on v2 1/1
#1 lore raw
Quoted 28 lines · Danilo Krummrich

imx_clk_scu_init() registers the imx_clk_scu_driver while commonly being called from IMX driver's probe() callbacks.

However, it neither makes sense to register drivers from probe() callbacks of other drivers, nor does the driver core allow registering drivers with a device lock already being held.

The latter was revealed by commit dc23806a7c47 ("driver core: enforce device_lock for driver_match_device()") leading to a deadlock condition described in [1].

Besides that, nothing seems to unregister the imx_clk_scu_driver once the corresponding driver module is unloaded, which leaves the driver-core with a dangling pointer.

Also, if there are multiple matching devices for the imx8qxp_clk_driver, imx8qxp_clk_probe() calls imx_clk_scu_init() multiple times. However, any subsequent call after the first one will fail, since the driver-core does not allow to register the same struct platform_driver multiple times.

Hence, register the imx_clk_scu_driver from module_init() and unregister it in module_exit().

Note that we first register the imx8qxp_clk_driver and then call imx_clk_scu_module_init() to avoid having to call imx_clk_scu_module_exit() in the unwind path of imx8qxp_clk_init().

Quoted 7 lines
Fixes dc23806a7c47 ("driver core: enforce device_lock for driver_match_device()")
Fixes 220175cd3979 ("clk: imx: scu: fix build break when compiled as modules")
author maintainer
#2 lore raw
In reply to Danilo Krummrich
Quoted 28 lines · Danilo Krummrich

imx_clk_scu_init() registers the imx_clk_scu_driver while commonly being called from IMX driver's probe() callbacks.

However, it neither makes sense to register drivers from probe() callbacks of other drivers, nor does the driver core allow registering drivers with a device lock already being held.

The latter was revealed by commit dc23806a7c47 ("driver core: enforce device_lock for driver_match_device()") leading to a deadlock condition described in [1].

Besides that, nothing seems to unregister the imx_clk_scu_driver once the corresponding driver module is unloaded, which leaves the driver-core with a dangling pointer.

Also, if there are multiple matching devices for the imx8qxp_clk_driver, imx8qxp_clk_probe() calls imx_clk_scu_init() multiple times. However, any subsequent call after the first one will fail, since the driver-core does not allow to register the same struct platform_driver multiple times.

Hence, register the imx_clk_scu_driver from module_init() and unregister it in module_exit().

Note that we first register the imx8qxp_clk_driver and then call imx_clk_scu_module_init() to avoid having to call imx_clk_scu_module_exit() in the unwind path of imx8qxp_clk_init().

Quoted 7 lines
Fixes dc23806a7c47 ("driver core: enforce device_lock for driver_match_device()")
Fixes 220175cd3979 ("clk: imx: scu: fix build break when compiled as modules")

Just a quick reminder now that -rc1 is out; I think it would be good if this could go to Linus for -rc2.

(Just in case it helps, please let me know if you want me to take it through the driver-core tree for this purpose.)

Thanks,
Danilo

Acked-by
#3 lore raw
Quoted 29 lines · Danilo Krummrich
Quoted 28 lines · Danilo Krummrich

imx_clk_scu_init() registers the imx_clk_scu_driver while commonly being called from IMX driver's probe() callbacks.

However, it neither makes sense to register drivers from probe() callbacks of other drivers, nor does the driver core allow registering drivers with a device lock already being held.

The latter was revealed by commit dc23806a7c47 ("driver core: enforce device_lock for driver_match_device()") leading to a deadlock condition described in [1].

Besides that, nothing seems to unregister the imx_clk_scu_driver once the corresponding driver module is unloaded, which leaves the driver-core with a dangling pointer.

Also, if there are multiple matching devices for the imx8qxp_clk_driver, imx8qxp_clk_probe() calls imx_clk_scu_init() multiple times. However, any subsequent call after the first one will fail, since the driver-core does not allow to register the same struct platform_driver multiple times.

Hence, register the imx_clk_scu_driver from module_init() and unregister it in module_exit().

Note that we first register the imx8qxp_clk_driver and then call imx_clk_scu_module_init() to avoid having to call imx_clk_scu_module_exit() in the unwind path of imx8qxp_clk_init().

Quoted 7 lines
Quoted 7 lines
Fixes dc23806a7c47 ("driver core: enforce device_lock for driver_match_device()")
Fixes 220175cd3979 ("clk: imx: scu: fix build break when compiled as modules")
Quoted 6 lines

Just a quick reminder now that -rc1 is out; I think it would be good if this could go to Linus for -rc2.

(Just in case it helps, please let me know if you want me to take it through the driver-core tree for this purpose.)

Sure. Go ahead.

Thanks!

author maintainer Applied
#4 lore raw
Quoted 38 lines · Abel Vesa
Quoted 29 lines · Danilo Krummrich
Quoted 28 lines · Danilo Krummrich

imx_clk_scu_init() registers the imx_clk_scu_driver while commonly being called from IMX driver's probe() callbacks.

However, it neither makes sense to register drivers from probe() callbacks of other drivers, nor does the driver core allow registering drivers with a device lock already being held.

The latter was revealed by commit dc23806a7c47 ("driver core: enforce device_lock for driver_match_device()") leading to a deadlock condition described in [1].

Besides that, nothing seems to unregister the imx_clk_scu_driver once the corresponding driver module is unloaded, which leaves the driver-core with a dangling pointer.

Also, if there are multiple matching devices for the imx8qxp_clk_driver, imx8qxp_clk_probe() calls imx_clk_scu_init() multiple times. However, any subsequent call after the first one will fail, since the driver-core does not allow to register the same struct platform_driver multiple times.

Hence, register the imx_clk_scu_driver from module_init() and unregister it in module_exit().

Note that we first register the imx8qxp_clk_driver and then call imx_clk_scu_module_init() to avoid having to call imx_clk_scu_module_exit() in the unwind path of imx8qxp_clk_init().

Quoted 7 lines
Quoted 7 lines
Fixes dc23806a7c47 ("driver core: enforce device_lock for driver_match_device()")
Fixes 220175cd3979 ("clk: imx: scu: fix build break when compiled as modules")
Quoted 1 line

Applied to driver-core-linus, thanks!

#5 lore raw
In reply to Danilo Krummrich

Sorry for late reply, just back from holiday.

Quoted 70 lines · Danilo Krummrich

imx_clk_scu_init() registers the imx_clk_scu_driver while commonly being called from IMX driver's probe() callbacks.

However, it neither makes sense to register drivers from probe() callbacks of other drivers, nor does the driver core allow registering drivers with a device lock already being held.

The latter was revealed by commit dc23806a7c47 ("driver core: enforce device_lock for driver_match_device()") leading to a deadlock condition described in [1].

Besides that, nothing seems to unregister the imx_clk_scu_driver once the corresponding driver module is unloaded, which leaves the driver-core with a dangling pointer.

Also, if there are multiple matching devices for the imx8qxp_clk_driver, imx8qxp_clk_probe() calls imx_clk_scu_init() multiple times. However, any subsequent call after the first one will fail, since the driver-core does not allow to register the same struct platform_driver multiple times.

Hence, register the imx_clk_scu_driver from module_init() and unregister it in module_exit().

Note that we first register the imx8qxp_clk_driver and then call imx_clk_scu_module_init() to avoid having to call imx_clk_scu_module_exit() in the unwind path of imx8qxp_clk_init().

Fixes dc23806a7c47 ("driver core: enforce device_lock for driver_match_device()")
Fixes 220175cd3979 ("clk: imx: scu: fix build break when compiled as modules")

---
Changes in v2:
- Expand commit message, mentioning a third bug fixed by this patch and noting the order of platform_driver_register() and imx_clk_scu_module_init() in imx8qxp_clk_init().
- Rename imx8qxp_{init,exit} to imx8qxp_clk_{init,exit}.
- Link to v1: https://lore.kernel.org/driver-core/[email protected]/
---

drivers/clk/imx/clk-imx8qxp.c | 24 +++++++++++++++++++++++-
drivers/clk/imx/clk-scu.c     | 12 +++++++++++-
drivers/clk/imx/clk-scu.h     |  2 ++
3 files changed, 36 insertions(+), 2 deletions(-)
drivers/clk/imx/clk-imx8qxp.c +13 -1
index 3ae162625bb1..c781425a005e 100644
@@ -346,7 +346,29 @@ static struct platform_driver imx8qxp_clk_driver = {
 	},
 	.probe = imx8qxp_clk_probe,
 };
-module_platform_driver(imx8qxp_clk_driver);
+
+static int __init imx8qxp_clk_init(void)
+{
+	int ret;
+
+	ret = platform_driver_register(&imx8qxp_clk_driver);
+	if (ret)
+		return ret;
+
+	ret = imx_clk_scu_module_init();
+	if (ret)
+		platform_driver_unregister(&imx8qxp_clk_driver);
+

drivers/clk/imx/clk-imx8qxp.c static struct platform_driver imx8qxp_clk_driver = { · line 371

Quoted 10 lines
drivers/clk/imx/clk-imx8qxp.c +10 -0
+	return ret;
+}
+module_init(imx8qxp_clk_init);
+
+static void __exit imx8qxp_clk_exit(void)
+{
+	imx_clk_scu_module_exit();
+	platform_driver_unregister(&imx8qxp_clk_driver);
+}
+module_exit(imx8qxp_clk_exit);

The clk driver is critical for the system to work, removing this driver will make the system not work properly I think, so it may not make too much value to add an exit function here.

Regards
Peng

author maintainer
#6 lore raw
Quoted 28 lines · Peng Fan
Quoted 28 lines
drivers/clk/imx/clk-imx8qxp.c +19 -1
index 3ae162625bb1..c781425a005e 100644
@@ -346,7 +346,29 @@ static struct platform_driver imx8qxp_clk_driver = {
 	},
 	.probe = imx8qxp_clk_probe,
 };
-module_platform_driver(imx8qxp_clk_driver);
+
+static int __init imx8qxp_clk_init(void)
+{
+	int ret;
+
+	ret = platform_driver_register(&imx8qxp_clk_driver);
+	if (ret)
+		return ret;
+
+	ret = imx_clk_scu_module_init();
+	if (ret)
+		platform_driver_unregister(&imx8qxp_clk_driver);
+
+	return ret;
+}
+module_init(imx8qxp_clk_init);
+
+static void __exit imx8qxp_clk_exit(void)
+{
Quoted 8 lines

drivers/clk/imx/clk-imx8qxp.c static struct platform_driver imx8qxp_clk_driver = { · line 371

Quoted 4 lines
drivers/clk/imx/clk-imx8qxp.c +4 -0
+	imx_clk_scu_module_exit();
+	platform_driver_unregister(&imx8qxp_clk_driver);
+}
+module_exit(imx8qxp_clk_exit);

The clk driver is critical for the system to work, removing this driver will make the system not work properly I think, so it may not make too much value to add an exit function here.

The exit function was there before, just hidden by the module_platform_driver() macro.

If a driver can be built as module, then we have to unregister the driver, when the module is unloaded.

If this driver should always be builtin, that is a separate change, independent from this fix.

reviewer
#7 lore raw
Quoted 42 lines

Subject: Re: [PATCH v2] clk: scu/imx8qxp: do not register driver in probe()

Quoted 2 lines · Peng Fan
Quoted 2 lines
(quoted diff) +0 -0

b/drivers/clk/imx/clk-imx8qxp.c index

3ae162625bb1..c781425a005e

Quoted 4 lines

drivers/clk/imx/clk-imx8qxp.c static struct platform_driver

Quoted 4 lines

100644

drivers/clk/imx/clk-imx8qxp.c +0 -0
@@ -346,7 +346,29 @@ static struct platform_driver

imx8qxp_clk_driver = {

Quoted 21 lines
Quoted 21 lines
drivers/clk/imx/clk-imx8qxp.c +17 -1
 	},
 	.probe = imx8qxp_clk_probe,
 };
-module_platform_driver(imx8qxp_clk_driver);
+
+static int __init imx8qxp_clk_init(void) {
+	int ret;
+
+	ret = platform_driver_register(&imx8qxp_clk_driver);
+	if (ret)
+		return ret;
+
+	ret = imx_clk_scu_module_init();
+	if (ret)
+		platform_driver_unregister(&imx8qxp_clk_driver);
+
+	return ret;
+}
+module_init(imx8qxp_clk_init);
+
+static void __exit imx8qxp_clk_exit(void) {
Quoted 8 lines

drivers/clk/imx/clk-imx8qxp.c static struct platform_driver imx8qxp_clk_driver = { · line 371

Quoted 4 lines
drivers/clk/imx/clk-imx8qxp.c +4 -0
+	imx_clk_scu_module_exit();
+	platform_driver_unregister(&imx8qxp_clk_driver);
+}
+module_exit(imx8qxp_clk_exit);

The clk driver is critical for the system to work, removing this driver will make the system not work properly I think, so it may not make too much value to add an exit function here.

Quoted 5 lines

The exit function was there before, just hidden by the module_platform_driver() macro.

If a driver can be built as module, then we have to unregister the driver, when the module is unloaded.

I see. thanks!

Regards
Peng

Quoted 3 lines

If this driver should always be builtin, that is a separate change, independent from this fix.

Applied
#8 lore raw
In reply to Danilo Krummrich
Quoted 8 lines · Danilo Krummrich

imx_clk_scu_init() registers the imx_clk_scu_driver while commonly being called from IMX driver's probe() callbacks.

However, it neither makes sense to register drivers from probe() callbacks of other drivers, nor does the driver core allow registering drivers with a device lock already being held.

[...]

Applied, thanks!

[1/1] clk: scu/imx8qxp: do not register driver in probe()

      commit: 93a6d39e78bfa78b2160621aafbb490e063f12d9

Best regards,

Signature · 1 line
Abel Vesa <[email protected]>
author maintainer
#9 lore raw
Quoted 9 lines · Abel Vesa
Quoted 7 lines · Danilo Krummrich

imx_clk_scu_init() registers the imx_clk_scu_driver while commonly being called from IMX driver's probe() callbacks.

However, it neither makes sense to register drivers from probe() callbacks of other drivers, nor does the driver core allow registering drivers with a device lock already being held.

Quoted 6 lines
Quoted 1 line

[...]

Applied, thanks!

[1/1] clk: scu/imx8qxp: do not register driver in probe()

      commit: 93a6d39e78bfa78b2160621aafbb490e063f12d9

This is already in Linus' tree, you gave your ACK in [1] for me to take it through the driver-core tree.

[1] https://lore.kernel.org/all/66i6cgh5zmz32ikwjvrz3gtezjotltqmfzdai7ybwjhanx3bif@i5g62ziautwq/

#10 lore raw
Quoted 12 lines · Danilo Krummrich
Quoted 11 lines · Abel Vesa
Quoted 8 lines · Danilo Krummrich

imx_clk_scu_init() registers the imx_clk_scu_driver while commonly being called from IMX driver's probe() callbacks.

However, it neither makes sense to register drivers from probe() callbacks of other drivers, nor does the driver core allow registering drivers with a device lock already being held.

[...]

Quoted 7 lines
Quoted 4 lines

Applied, thanks!

[1/1] clk: scu/imx8qxp: do not register driver in probe()

      commit: 93a6d39e78bfa78b2160621aafbb490e063f12d9

This is already in Linus' tree, you gave your ACK in [1] for me to take it through the driver-core tree.

Will drop from my tree then. Sorry about that.

Thanks for pointing this out.