All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/2] clk: qcom: Remove the KPSS and Krait OF providers on unbind
@ 2026-11-29 16:25 Guangshuo Li
  2026-11-29 16:25 ` [PATCH 1/2] clk: qcom: kpss-xcc: Fix potential use-after-free " Guangshuo Li
  2026-11-29 16:25 ` [PATCH 2/2] clk: qcom: krait-cc: Remove the OF clock provider " Guangshuo Li
  0 siblings, 2 replies; 6+ messages in thread
From: Guangshuo Li @ 2026-11-29 16:25 UTC (permalink / raw)
  To: andersson, sboyd, bmasney+clk, jbrunet+clk, ansuelsmth,
	quic_srichara
  Cc: abelvesa, linux-arm-msm, linux-clk

Release the KPSS XCC and Krait clock providers on driver teardown.

Guangshuo Li (2):
  clk: qcom: kpss-xcc: Fix potential use-after-free on unbind
  clk: qcom: krait-cc: Remove the OF clock provider on unbind

base-commit: d8f05ec001e838cdb94fc14efa7c411e676f9ab9

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH 1/2] clk: qcom: kpss-xcc: Fix potential use-after-free on unbind
  2026-11-29 16:25 [PATCH 0/2] clk: qcom: Remove the KPSS and Krait OF providers on unbind Guangshuo Li
@ 2026-11-29 16:25 ` Guangshuo Li
  2026-11-29 16:34   ` sashiko-bot
  2026-11-30  8:13   ` Konrad Dybcio
  2026-11-29 16:25 ` [PATCH 2/2] clk: qcom: krait-cc: Remove the OF clock provider " Guangshuo Li
  1 sibling, 2 replies; 6+ messages in thread
From: Guangshuo Li @ 2026-11-29 16:25 UTC (permalink / raw)
  To: andersson, sboyd, bmasney+clk, jbrunet+clk, ansuelsmth,
	quic_srichara
  Cc: abelvesa, linux-arm-msm, linux-clk

The OF clock provider remains registered after devres releases the mux
clock. A later lookup can return the freed clk_hw.

Unregister the provider from the device node during removal.

This issue was found by our static analysis tool under development.

Fixes: 09be1a39e685 ("clk: qcom: kpss-xcc: register it as clk provider")
Signed-off-by: Guangshuo Li <liguangshuo@mail.sdu.edu.cn>
---
 drivers/clk/qcom/kpss-xcc.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/drivers/clk/qcom/kpss-xcc.c b/drivers/clk/qcom/kpss-xcc.c
index 97bfb21a5e5e..568a290551db 100644
--- a/drivers/clk/qcom/kpss-xcc.c
+++ b/drivers/clk/qcom/kpss-xcc.c
@@ -60,8 +60,14 @@ static int kpss_xcc_driver_probe(struct platform_device *pdev)
 	return of_clk_add_hw_provider(dev->of_node, of_clk_hw_simple_get, hw);
 }
 
+static void kpss_xcc_driver_remove(struct platform_device *pdev)
+{
+	of_clk_del_provider(pdev->dev.of_node);
+}
+
 static struct platform_driver kpss_xcc_driver = {
 	.probe = kpss_xcc_driver_probe,
+	.remove = kpss_xcc_driver_remove,
 	.driver = {
 		.name = "kpss-xcc",
 		.of_match_table = kpss_xcc_match_table,

-- 
2.43.0


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 2/2] clk: qcom: krait-cc: Remove the OF clock provider on unbind
  2026-11-29 16:25 [PATCH 0/2] clk: qcom: Remove the KPSS and Krait OF providers on unbind Guangshuo Li
  2026-11-29 16:25 ` [PATCH 1/2] clk: qcom: kpss-xcc: Fix potential use-after-free " Guangshuo Li
@ 2026-11-29 16:25 ` Guangshuo Li
  2026-11-30  8:13   ` Konrad Dybcio
  1 sibling, 1 reply; 6+ messages in thread
From: Guangshuo Li @ 2026-11-29 16:25 UTC (permalink / raw)
  To: andersson, sboyd, bmasney+clk, jbrunet+clk, ansuelsmth,
	quic_srichara
  Cc: abelvesa, linux-arm-msm, linux-clk

The Krait clock provider returns clocks from a device-managed array.
Unbinding the driver releases the array while it is still reachable from
the OF provider list. Remove the provider before devres releases its
lookup data.

This issue was found by our static analysis tool under development.

Fixes: bb5c4a85051e ("clk: qcom: Add Krait clock controller driver")
Signed-off-by: Guangshuo Li <liguangshuo@mail.sdu.edu.cn>
---
 drivers/clk/qcom/krait-cc.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/drivers/clk/qcom/krait-cc.c b/drivers/clk/qcom/krait-cc.c
index 37fe990ef6b8..cbcff3726bcc 100644
--- a/drivers/clk/qcom/krait-cc.c
+++ b/drivers/clk/qcom/krait-cc.c
@@ -434,8 +434,14 @@ static int krait_cc_probe(struct platform_device *pdev)
 	return 0;
 }
 
+static void krait_cc_remove(struct platform_device *pdev)
+{
+	of_clk_del_provider(pdev->dev.of_node);
+}
+
 static struct platform_driver krait_cc_driver = {
 	.probe = krait_cc_probe,
+	.remove = krait_cc_remove,
 	.driver = {
 		.name = "krait-cc",
 		.of_match_table = krait_cc_match_table,

-- 
2.43.0


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH 1/2] clk: qcom: kpss-xcc: Fix potential use-after-free on unbind
  2026-11-29 16:25 ` [PATCH 1/2] clk: qcom: kpss-xcc: Fix potential use-after-free " Guangshuo Li
@ 2026-11-29 16:34   ` sashiko-bot
  2026-11-30  8:13   ` Konrad Dybcio
  1 sibling, 0 replies; 6+ messages in thread
From: sashiko-bot @ 2026-11-29 16:34 UTC (permalink / raw)
  To: Guangshuo Li; +Cc: linux-clk

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Low] clk: qcom: kpss-xcc: prefer devm_of_clk_add_hw_provider() over
  manual .remove
--

commit 1a6b29b537b5fcd215d2bf131f69a050eb457d4d
Author: Guangshuo Li <liguangshuo@mail.sdu.edu.cn>

clk: qcom: kpss-xcc: Fix potential use-after-free on unbind

This commit adds a platform driver remove callback to unregister the OF
clock provider when the kpss-xcc device is unbound.

> diff --git a/drivers/clk/qcom/kpss-xcc.c b/drivers/clk/qcom/kpss-xcc.c
> index 97bfb21a5e5ea..568a290551dbc 100644
> --- a/drivers/clk/qcom/kpss-xcc.c
> +++ b/drivers/clk/qcom/kpss-xcc.c
> @@ -60,8 +60,14 @@ static int kpss_xcc_driver_probe(struct platform_device *pdev)
>  	return of_clk_add_hw_provider(dev->of_node, of_clk_hw_simple_get, hw);
>  }
>  
> +static void kpss_xcc_driver_remove(struct platform_device *pdev)
> +{
> +	of_clk_del_provider(pdev->dev.of_node);
> +}
> +
>  static struct platform_driver kpss_xcc_driver = {
>  	.probe = kpss_xcc_driver_probe,
> +	.remove = kpss_xcc_driver_remove,
>  	.driver = {
>  		.name = "kpss-xcc",
>  		.of_match_table = kpss_xcc_match_table,

[Severity: Low]
This isn't a bug, but since kpss_xcc_driver_probe() already manages its
other resources via devres, could it call
devm_of_clk_add_hw_provider(dev, of_clk_hw_simple_get, hw) instead of
adding a manual kpss_xcc_driver_remove() callback?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261130-7242f82796-u09-0@mail.sdu.edu.cn?part=1

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 1/2] clk: qcom: kpss-xcc: Fix potential use-after-free on unbind
  2026-11-29 16:25 ` [PATCH 1/2] clk: qcom: kpss-xcc: Fix potential use-after-free " Guangshuo Li
  2026-11-29 16:34   ` sashiko-bot
@ 2026-11-30  8:13   ` Konrad Dybcio
  1 sibling, 0 replies; 6+ messages in thread
From: Konrad Dybcio @ 2026-11-30  8:13 UTC (permalink / raw)
  To: Guangshuo Li, andersson, sboyd, bmasney+clk, jbrunet+clk,
	ansuelsmth, quic_srichara
  Cc: abelvesa, linux-arm-msm, linux-clk

On 11/29/26 5:25 PM, Guangshuo Li wrote:
> The OF clock provider remains registered after devres releases the mux
> clock. A later lookup can return the freed clk_hw.
> 
> Unregister the provider from the device node during removal.
> 
> This issue was found by our static analysis tool under development.
> 
> Fixes: 09be1a39e685 ("clk: qcom: kpss-xcc: register it as clk provider")
> Signed-off-by: Guangshuo Li <liguangshuo@mail.sdu.edu.cn>
> ---
>  drivers/clk/qcom/kpss-xcc.c | 6 ++++++
>  1 file changed, 6 insertions(+)
> 
> diff --git a/drivers/clk/qcom/kpss-xcc.c b/drivers/clk/qcom/kpss-xcc.c
> index 97bfb21a5e5e..568a290551db 100644
> --- a/drivers/clk/qcom/kpss-xcc.c
> +++ b/drivers/clk/qcom/kpss-xcc.c
> @@ -60,8 +60,14 @@ static int kpss_xcc_driver_probe(struct platform_device *pdev)
>  	return of_clk_add_hw_provider(dev->of_node, of_clk_hw_simple_get, hw);
>  }
>  
> +static void kpss_xcc_driver_remove(struct platform_device *pdev)
> +{
> +	of_clk_del_provider(pdev->dev.of_node);

Instead, let's switch the registering function to
devm_of_clk_add_hw_provider() which will clean up the device for
us

Konrad

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 2/2] clk: qcom: krait-cc: Remove the OF clock provider on unbind
  2026-11-29 16:25 ` [PATCH 2/2] clk: qcom: krait-cc: Remove the OF clock provider " Guangshuo Li
@ 2026-11-30  8:13   ` Konrad Dybcio
  0 siblings, 0 replies; 6+ messages in thread
From: Konrad Dybcio @ 2026-11-30  8:13 UTC (permalink / raw)
  To: Guangshuo Li, andersson, sboyd, bmasney+clk, jbrunet+clk,
	ansuelsmth, quic_srichara
  Cc: abelvesa, linux-arm-msm, linux-clk

On 11/29/26 5:25 PM, Guangshuo Li wrote:
> The Krait clock provider returns clocks from a device-managed array.
> Unbinding the driver releases the array while it is still reachable from
> the OF provider list. Remove the provider before devres releases its
> lookup data.
> 
> This issue was found by our static analysis tool under development.
> 
> Fixes: bb5c4a85051e ("clk: qcom: Add Krait clock controller driver")
> Signed-off-by: Guangshuo Li <liguangshuo@mail.sdu.edu.cn>
> ---
>  drivers/clk/qcom/krait-cc.c | 6 ++++++
>  1 file changed, 6 insertions(+)
> 
> diff --git a/drivers/clk/qcom/krait-cc.c b/drivers/clk/qcom/krait-cc.c
> index 37fe990ef6b8..cbcff3726bcc 100644
> --- a/drivers/clk/qcom/krait-cc.c
> +++ b/drivers/clk/qcom/krait-cc.c
> @@ -434,8 +434,14 @@ static int krait_cc_probe(struct platform_device *pdev)
>  	return 0;
>  }
>  
> +static void krait_cc_remove(struct platform_device *pdev)
> +{
> +	of_clk_del_provider(pdev->dev.of_node);
> +}

Same as patch 1

Konrad

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2026-11-30  8:13 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-29 16:25 [PATCH 0/2] clk: qcom: Remove the KPSS and Krait OF providers on unbind Guangshuo Li
2026-11-29 16:25 ` [PATCH 1/2] clk: qcom: kpss-xcc: Fix potential use-after-free " Guangshuo Li
2026-11-29 16:34   ` sashiko-bot
2026-11-30  8:13   ` Konrad Dybcio
2026-11-29 16:25 ` [PATCH 2/2] clk: qcom: krait-cc: Remove the OF clock provider " Guangshuo Li
2026-11-30  8:13   ` Konrad Dybcio

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.