LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
* [PATCH] clk: fix leak on devm_clk_bulk_get_all() unwind
@ 2021-07-31  2:59 Brian Norris
  2021-07-31  7:53 ` Stephen Boyd
  0 siblings, 1 reply; 2+ messages in thread
From: Brian Norris @ 2021-07-31  2:59 UTC (permalink / raw)
  To: Michael Turquette, Stephen Boyd
  Cc: linux-clk, linux-kernel, Brian Norris, Dong Aisheng, stable

clk_bulk_get_all() allocates an array of struct clk_bulk data for us
(unlike clk_bulk_get()), so we need to free it. Let's use the
clk_bulk_put_all() helper.

kmemleak complains, on an RK3399 Gru/Kevin system:

unreferenced object 0xffffff80045def00 (size 128):
  comm "swapper/0", pid 1, jiffies 4294667682 (age 86.394s)
  hex dump (first 32 bytes):
    44 32 60 fe fe ff ff ff 00 00 00 00 00 00 00 00  D2`.............
    48 32 60 fe fe ff ff ff 00 00 00 00 00 00 00 00  H2`.............
  backtrace:
    [<00000000742860d6>] __kmalloc+0x22c/0x39c
    [<00000000b0493f2c>] clk_bulk_get_all+0x64/0x188
    [<00000000325f5900>] devm_clk_bulk_get_all+0x58/0xa8
    [<00000000175b9bc5>] dwc3_probe+0x8ac/0xb5c
    [<000000009169e2f9>] platform_drv_probe+0x9c/0xbc
    [<000000005c51e2ee>] really_probe+0x13c/0x378
    [<00000000c47b1f24>] driver_probe_device+0x84/0xc0
    [<00000000f870fcfb>] __device_attach_driver+0x94/0xb0
    [<000000004d1b92ae>] bus_for_each_drv+0x8c/0xd8
    [<00000000481d60c3>] __device_attach+0xc4/0x150
    [<00000000a163bd36>] device_initial_probe+0x1c/0x28
    [<00000000accb6bad>] bus_probe_device+0x3c/0x9c
    [<000000001a199f89>] device_add+0x218/0x3cc
    [<000000001bd84952>] of_device_add+0x40/0x50
    [<000000009c658c29>] of_platform_device_create_pdata+0xac/0x100
    [<0000000021c69ba4>] of_platform_bus_create+0x190/0x224

Fixes: f08c2e2865f6 ("clk: add managed version of clk_bulk_get_all")
Cc: Dong Aisheng <aisheng.dong@nxp.com>
Cc: stable@vger.kernel.org
Signed-off-by: Brian Norris <briannorris@chromium.org>
---
Never mind that kmemleak appears broken on 5.14-rc3+... but I caught the
leak on an earlier kernel.

 drivers/clk/clk-devres.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/drivers/clk/clk-devres.c b/drivers/clk/clk-devres.c
index be160764911b..f9d5b7334341 100644
--- a/drivers/clk/clk-devres.c
+++ b/drivers/clk/clk-devres.c
@@ -92,13 +92,20 @@ int __must_check devm_clk_bulk_get_optional(struct device *dev, int num_clks,
 }
 EXPORT_SYMBOL_GPL(devm_clk_bulk_get_optional);
 
+static void devm_clk_bulk_release_all(struct device *dev, void *res)
+{
+	struct clk_bulk_devres *devres = res;
+
+	clk_bulk_put_all(devres->num_clks, devres->clks);
+}
+
 int __must_check devm_clk_bulk_get_all(struct device *dev,
 				       struct clk_bulk_data **clks)
 {
 	struct clk_bulk_devres *devres;
 	int ret;
 
-	devres = devres_alloc(devm_clk_bulk_release,
+	devres = devres_alloc(devm_clk_bulk_release_all,
 			      sizeof(*devres), GFP_KERNEL);
 	if (!devres)
 		return -ENOMEM;
-- 
2.32.0.554.ge1b32706d8-goog


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

* Re: [PATCH] clk: fix leak on devm_clk_bulk_get_all() unwind
  2021-07-31  2:59 [PATCH] clk: fix leak on devm_clk_bulk_get_all() unwind Brian Norris
@ 2021-07-31  7:53 ` Stephen Boyd
  0 siblings, 0 replies; 2+ messages in thread
From: Stephen Boyd @ 2021-07-31  7:53 UTC (permalink / raw)
  To: Brian Norris, Michael Turquette
  Cc: linux-clk, linux-kernel, Brian Norris, Dong Aisheng, stable

Quoting Brian Norris (2021-07-30 19:59:50)
> clk_bulk_get_all() allocates an array of struct clk_bulk data for us
> (unlike clk_bulk_get()), so we need to free it. Let's use the
> clk_bulk_put_all() helper.
> 
> kmemleak complains, on an RK3399 Gru/Kevin system:
> 
> unreferenced object 0xffffff80045def00 (size 128):
>   comm "swapper/0", pid 1, jiffies 4294667682 (age 86.394s)
>   hex dump (first 32 bytes):
>     44 32 60 fe fe ff ff ff 00 00 00 00 00 00 00 00  D2`.............
>     48 32 60 fe fe ff ff ff 00 00 00 00 00 00 00 00  H2`.............
>   backtrace:
>     [<00000000742860d6>] __kmalloc+0x22c/0x39c
>     [<00000000b0493f2c>] clk_bulk_get_all+0x64/0x188
>     [<00000000325f5900>] devm_clk_bulk_get_all+0x58/0xa8
>     [<00000000175b9bc5>] dwc3_probe+0x8ac/0xb5c
>     [<000000009169e2f9>] platform_drv_probe+0x9c/0xbc
>     [<000000005c51e2ee>] really_probe+0x13c/0x378
>     [<00000000c47b1f24>] driver_probe_device+0x84/0xc0
>     [<00000000f870fcfb>] __device_attach_driver+0x94/0xb0
>     [<000000004d1b92ae>] bus_for_each_drv+0x8c/0xd8
>     [<00000000481d60c3>] __device_attach+0xc4/0x150
>     [<00000000a163bd36>] device_initial_probe+0x1c/0x28
>     [<00000000accb6bad>] bus_probe_device+0x3c/0x9c
>     [<000000001a199f89>] device_add+0x218/0x3cc
>     [<000000001bd84952>] of_device_add+0x40/0x50
>     [<000000009c658c29>] of_platform_device_create_pdata+0xac/0x100
>     [<0000000021c69ba4>] of_platform_bus_create+0x190/0x224
> 
> Fixes: f08c2e2865f6 ("clk: add managed version of clk_bulk_get_all")
> Cc: Dong Aisheng <aisheng.dong@nxp.com>
> Cc: stable@vger.kernel.org
> Signed-off-by: Brian Norris <briannorris@chromium.org>
> ---

Applied to clk-fixes

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

end of thread, other threads:[~2021-07-31  7:53 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-31  2:59 [PATCH] clk: fix leak on devm_clk_bulk_get_all() unwind Brian Norris
2021-07-31  7:53 ` Stephen Boyd

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).