linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] clk: mediatek: fix double free in mtk_clk_register_pllfh()
@ 2023-10-24  5:00 Dan Carpenter
  2023-10-24  9:24 ` AngeloGioacchino Del Regno
  2023-10-24 18:29 ` Stephen Boyd
  0 siblings, 2 replies; 3+ messages in thread
From: Dan Carpenter @ 2023-10-24  5:00 UTC (permalink / raw)
  To: Johnson Wang
  Cc: Michael Turquette, Stephen Boyd, Matthias Brugger,
	AngeloGioacchino Del Regno, Edward-JW Yang, Chen-Yu Tsai,
	linux-clk, linux-arm-kernel, linux-mediatek, kernel-janitors

The mtk_clk_register_pll_ops() currently frees the "pll" parameter.
The function has two callers, mtk_clk_register_pll() and
mtk_clk_register_pllfh().  The first one, the _pll() function relies on
the free, but for the second _pllfh() function it causes a double free
bug.

Really the frees should be done in the caller because that's where
the allocation is.

Fixes: d7964de8a8ea ("clk: mediatek: Add new clock driver to handle FHCTL hardware")
Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>
---
 drivers/clk/mediatek/clk-pll.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/clk/mediatek/clk-pll.c b/drivers/clk/mediatek/clk-pll.c
index a4eca5fd539c..513ab6b1b322 100644
--- a/drivers/clk/mediatek/clk-pll.c
+++ b/drivers/clk/mediatek/clk-pll.c
@@ -321,10 +321,8 @@ struct clk_hw *mtk_clk_register_pll_ops(struct mtk_clk_pll *pll,
 
 	ret = clk_hw_register(NULL, &pll->hw);
 
-	if (ret) {
-		kfree(pll);
+	if (ret)
 		return ERR_PTR(ret);
-	}
 
 	return &pll->hw;
 }
@@ -340,6 +338,8 @@ struct clk_hw *mtk_clk_register_pll(const struct mtk_pll_data *data,
 		return ERR_PTR(-ENOMEM);
 
 	hw = mtk_clk_register_pll_ops(pll, data, base, &mtk_pll_ops);
+	if (IS_ERR(hw))
+		kfree(pll);
 
 	return hw;
 }
-- 
2.42.0


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH] clk: mediatek: fix double free in mtk_clk_register_pllfh()
  2023-10-24  5:00 [PATCH] clk: mediatek: fix double free in mtk_clk_register_pllfh() Dan Carpenter
@ 2023-10-24  9:24 ` AngeloGioacchino Del Regno
  2023-10-24 18:29 ` Stephen Boyd
  1 sibling, 0 replies; 3+ messages in thread
From: AngeloGioacchino Del Regno @ 2023-10-24  9:24 UTC (permalink / raw)
  To: Dan Carpenter, Johnson Wang
  Cc: Michael Turquette, Stephen Boyd, Matthias Brugger, Edward-JW Yang,
	Chen-Yu Tsai, linux-clk, linux-arm-kernel, linux-mediatek,
	kernel-janitors

Il 24/10/23 07:00, Dan Carpenter ha scritto:
> The mtk_clk_register_pll_ops() currently frees the "pll" parameter.
> The function has two callers, mtk_clk_register_pll() and
> mtk_clk_register_pllfh().  The first one, the _pll() function relies on
> the free, but for the second _pllfh() function it causes a double free
> bug.
> 
> Really the frees should be done in the caller because that's where
> the allocation is.
> 
> Fixes: d7964de8a8ea ("clk: mediatek: Add new clock driver to handle FHCTL hardware")
> Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>

Reviewed-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>



_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH] clk: mediatek: fix double free in mtk_clk_register_pllfh()
  2023-10-24  5:00 [PATCH] clk: mediatek: fix double free in mtk_clk_register_pllfh() Dan Carpenter
  2023-10-24  9:24 ` AngeloGioacchino Del Regno
@ 2023-10-24 18:29 ` Stephen Boyd
  1 sibling, 0 replies; 3+ messages in thread
From: Stephen Boyd @ 2023-10-24 18:29 UTC (permalink / raw)
  To: Dan Carpenter, Johnson Wang
  Cc: Michael Turquette, Matthias Brugger, AngeloGioacchino Del Regno,
	Edward-JW Yang, Chen-Yu Tsai, linux-clk, linux-arm-kernel,
	linux-mediatek, kernel-janitors

Quoting Dan Carpenter (2023-10-23 22:00:53)
> The mtk_clk_register_pll_ops() currently frees the "pll" parameter.
> The function has two callers, mtk_clk_register_pll() and
> mtk_clk_register_pllfh().  The first one, the _pll() function relies on
> the free, but for the second _pllfh() function it causes a double free
> bug.
> 
> Really the frees should be done in the caller because that's where
> the allocation is.
> 
> Fixes: d7964de8a8ea ("clk: mediatek: Add new clock driver to handle FHCTL hardware")
> Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>
> ---

Applied to clk-next

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

end of thread, other threads:[~2023-10-24 18:30 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-10-24  5:00 [PATCH] clk: mediatek: fix double free in mtk_clk_register_pllfh() Dan Carpenter
2023-10-24  9:24 ` AngeloGioacchino Del Regno
2023-10-24 18:29 ` 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).