clk: mediatek: fix memory leak on module removal
Subsystems (3)
v2 cover clk: mediatek: fix memory leak on module removal
Some MediaTek clock drivers do not call platform_set_drvdata() during probe,
but their remove callback calls platform_get_drvdata(). This results in platform_get_drvdata() returning NULL, which leads to calling kfree(NULL) in mtk_free_clk_data(NULL). This leaves clk_data unreleased, causing a memory leak.
Fix this by calling platform_set_drvdata() during probe.
Changes in v2:
- Add a newline between platform_set_drvdata() and return (suggested by Brian Masney)
- Split the patch per SoC, (also suggested by Brian Masney)
- Add "Cc: [email protected]"
Link to v1: https://lore.kernel.org/linux-mediatek/[email protected]/T/#u
Akari Tsuyukusa (6):
clk: mediatek: mt2712: fix memory leak on module removal
clk: mediatek: mt6795: fix memory leak on module removal
clk: mediatek: mt7622: fix memory leak on module removal
clk: mediatek: mt8135: fix memory leak on module removal
clk: mediatek: mt8173: fix memory leak on module removal
clk: mediatek: mt8192: fix memory leak on module removal
drivers/clk/mediatek/clk-mt2712-apmixedsys.c | 2 ++ drivers/clk/mediatek/clk-mt6795-apmixedsys.c | 2 ++ drivers/clk/mediatek/clk-mt6795-infracfg.c | 2 ++ drivers/clk/mediatek/clk-mt6795-pericfg.c | 2 ++ drivers/clk/mediatek/clk-mt7622-apmixedsys.c | 2 ++ drivers/clk/mediatek/clk-mt7622-infracfg.c | 2 ++ drivers/clk/mediatek/clk-mt8135-apmixedsys.c | 2 ++ drivers/clk/mediatek/clk-mt8173-apmixedsys.c | 2 ++ drivers/clk/mediatek/clk-mt8173-infracfg.c | 2 ++ drivers/clk/mediatek/clk-mt8192-apmixedsys.c | 2 ++ 10 files changed, 20 insertions(+)
Signature · 1 line
2.54.0
PATCH v2 1/6 clk: mediatek: mt2712: fix memory leak on module removal
clk_mt2712_apmixed_probe() in clk-mt2712-apmixedsys.c does not call platform_set_drvdata(), but clk_mt2712_apmixed_remove() callback calls platform_get_drvdata().
This results in platform_get_drvdata() returning NULL, which leads to calling kfree(NULL) in mtk_free_clk_data(NULL).
This leaves clk_data unreleased, causing a memory leak.
Fix this by calling platform_set_drvdata() during probe.
--- drivers/clk/mediatek/clk-mt2712-apmixedsys.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/clk/mediatek/clk-mt2712-apmixedsys.c +2 -0
@@ -129,6 +129,8 @@ static int clk_mt2712_apmixed_probe(struct platform_device *pdev) goto unregister_plls; } +platform_set_drvdata (pdev, clk_data); +return 0 ; unregister_plls:
Signature · 1 line
2.54.0
Re: [PATCH v2 1/6] clk: mediatek: mt2712: fix memory leak on module removal
Quoted 7 lines · Akari Tsuyukusa
clk_mt2712_apmixed_probe()inclk-mt2712-apmixedsys.cdoes not callplatform_set_drvdata(), butclk_mt2712_apmixed_remove()callback callsplatform_get_drvdata().
This results inplatform_get_drvdata()returning NULL, which leads to calling kfree(NULL) inmtk_free_clk_data(NULL).
This leavesclk_dataunreleased, causing a memory leak.
Quoted 5 lines
Fix this by calling
platform_set_drvdata()during probe.Fixes c6368ce86435 ("clk: mediatek: mt2712-apmixedsys: Add .remove() callback for module build")Signed-off-by Akari Tsuyukusa <[email protected]>
PATCH v2 2/6 clk: mediatek: mt6795: fix memory leak on module removal
In reply to Akari Tsuyukusaclk-mt6795-apmixedsys.c, clk-mt6795-infracfg.c and clk-mt6795-pericfg.c do not call platform_set_drvdata() during their driver probe callback, but their remove callback calls platform_get_drvdata().
This results in platform_get_drvdata() returning NULL, which leads to calling kfree(NULL) in mtk_free_clk_data(NULL).
This leaves clk_data unreleased, causing a memory leak.
Fix this by calling platform_set_drvdata() during probe.
--- drivers/clk/mediatek/clk-mt6795-apmixedsys.c | 2 ++ drivers/clk/mediatek/clk-mt6795-infracfg.c | 2 ++ drivers/clk/mediatek/clk-mt6795-pericfg.c | 2 ++ 3 files changed, 6 insertions(+)
drivers/clk/mediatek/clk-mt6795-apmixedsys.c +2 -0
@@ -175,6 +175,8 @@ static int clk_mt6795_apmixed_probe(struct platform_device *pdev)dev_dbg (dev,"Performing initial setup for MD1\n" );clk_mt6795_apmixed_setup_md1 (base); +platform_set_drvdata (pdev, clk_data); +return 0 ; unregister_ref2usb:
drivers/clk/mediatek/clk-mt6795-infracfg.c +2 -0
@@ -116,6 +116,8 @@ static int clk_mt6795_infracfg_probe(struct platform_device *pdev)if (ret) goto unregister_cpumuxes; +platform_set_drvdata (pdev, clk_data); +return 0 ; unregister_cpumuxes:
drivers/clk/mediatek/clk-mt6795-pericfg.c +2 -0
@@ -125,6 +125,8 @@ static int clk_mt6795_pericfg_probe(struct platform_device *pdev)if (ret) goto unregister_composites; +platform_set_drvdata (pdev, clk_data); +return 0 ; unregister_composites:
Signature · 1 line
2.54.0
Re: [PATCH v2 2/6] clk: mediatek: mt6795: fix memory leak on module removal
Quoted 7 lines · Akari Tsuyukusa
clk-mt6795-apmixedsys.c,clk-mt6795-infracfg.candclk-mt6795-pericfg.cdo not callplatform_set_drvdata()during their driver probe callback, but their remove callback callsplatform_get_drvdata().
This results inplatform_get_drvdata()returning NULL, which leads to calling kfree(NULL) inmtk_free_clk_data(NULL).
This leavesclk_dataunreleased, causing a memory leak.
Quoted 5 lines
Fix this by calling
platform_set_drvdata()during probe.Fixes 0d363282bb0c ("clk: mediatek: Add MediaTek Helio X10 MT6795 clock drivers")Signed-off-by Akari Tsuyukusa <[email protected]>
PATCH v2 3/6 clk: mediatek: mt7622: fix memory leak on module removal
In reply to Akari Tsuyukusaclk-mt7622-apmixedsys.c and clk-mt7622-infracfg.c do not call platform_set_drvdata() during their driver probe callback, but their remove callback calls platform_get_drvdata(). This results in platform_get_drvdata() returning NULL, which leads to calling kfree(NULL) in mtk_free_clk_data(NULL). This leaves clk_data unreleased, causing a memory leak.
Fix this by calling platform_set_drvdata() during probe.
--- drivers/clk/mediatek/clk-mt7622-apmixedsys.c | 2 ++ drivers/clk/mediatek/clk-mt7622-infracfg.c | 2 ++ 2 files changed, 4 insertions(+)
drivers/clk/mediatek/clk-mt7622-apmixedsys.c +2 -0
@@ -109,6 +109,8 @@ static int clk_mt7622_apmixed_probe(struct platform_device *pdev)if (ret) goto unregister_gates; +platform_set_drvdata (pdev, clk_data); +return 0 ; unregister_gates:
drivers/clk/mediatek/clk-mt7622-infracfg.c +2 -0
@@ -90,6 +90,8 @@ static int clk_mt7622_infracfg_probe(struct platform_device *pdev)if (ret) goto unregister_cpumuxes; +platform_set_drvdata (pdev, clk_data); +return 0 ; unregister_cpumuxes:
Signature · 1 line
2.54.0
Re: [PATCH v2 3/6] clk: mediatek: mt7622: fix memory leak on module removal
Quoted 7 lines · Akari Tsuyukusa
clk-mt7622-apmixedsys.candclk-mt7622-infracfg.cdo not callplatform_set_drvdata()during their driver probe callback, but their remove callback callsplatform_get_drvdata(). This results inplatform_get_drvdata()returning NULL, which leads to calling kfree(NULL) inmtk_free_clk_data(NULL). This leavesclk_dataunreleased, causing a memory leak.
Quoted 6 lines
Fix this by calling
platform_set_drvdata()during probe.Fixes c50e2ea6507b ("clk: mediatek: mt7622-apmixedsys: Add .remove() callback for module build")Fixes 838b86331c5e ("clk: mediatek: mt7622: Move infracfg to clk-mt7622-infracfg.c")Signed-off-by Akari Tsuyukusa <[email protected]>
PATCH v2 4/6 clk: mediatek: mt8135: fix memory leak on module removal
In reply to Akari Tsuyukusaclk_mt8135_apmixed_probe() in clk-mt8135-apmixedsys.c does not call platform_set_drvdata(), but clk_mt8135_apmixed_remove() callback calls platform_get_drvdata().
This results in platform_get_drvdata() returning NULL, which leads to calling kfree(NULL) in mtk_free_clk_data(NULL). This leaves clk_data unreleased, causing a memory leak.
Fix this by calling platform_set_drvdata() during probe.
--- drivers/clk/mediatek/clk-mt8135-apmixedsys.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/clk/mediatek/clk-mt8135-apmixedsys.c +2 -0
@@ -66,6 +66,8 @@ static int clk_mt8135_apmixed_probe(struct platform_device *pdev)if (ret) goto unregister_plls; +platform_set_drvdata (pdev, clk_data); +return 0 ; unregister_plls:
Signature · 1 line
2.54.0
Re: [PATCH v2 4/6] clk: mediatek: mt8135: fix memory leak on module removal
Quoted 7 lines · Akari Tsuyukusa
clk_mt8135_apmixed_probe()inclk-mt8135-apmixedsys.cdoes not callplatform_set_drvdata(), butclk_mt8135_apmixed_remove()callback callsplatform_get_drvdata().
This results inplatform_get_drvdata()returning NULL, which leads to calling kfree(NULL) inmtk_free_clk_data(NULL). This leavesclk_dataunreleased, causing a memory leak.
Quoted 5 lines
Fix this by calling
platform_set_drvdata()during probe.Fixes 54b7026f011e ("clk: mediatek: mt8135-apmixedsys: Convert to platform_driver and module")Signed-off-by Akari Tsuyukusa <[email protected]>
PATCH v2 5/6 clk: mediatek: mt8173: fix memory leak on module removal
In reply to Akari Tsuyukusaclk-mt8173-apmixedsys.c and clk-mt8173-infracfg.c do not call platform_set_drvdata() during their driver probe callback, but their remove callback calls platform_get_drvdata(). This results in platform_get_drvdata() returning NULL, which leads to calling kfree(NULL) in mtk_free_clk_data(NULL). This leaves clk_data unreleased, causing a memory leak.
Fix this by calling platform_set_drvdata() during probe.
--- drivers/clk/mediatek/clk-mt8173-apmixedsys.c | 2 ++ drivers/clk/mediatek/clk-mt8173-infracfg.c | 2 ++ 2 files changed, 4 insertions(+)
drivers/clk/mediatek/clk-mt8173-apmixedsys.c +2 -0
@@ -179,6 +179,8 @@ static int clk_mt8173_apmixed_probe(struct platform_device *pdev)if (r) goto unregister_ref2usb; +platform_set_drvdata (pdev, clk_data); +return 0 ; unregister_ref2usb:
drivers/clk/mediatek/clk-mt8173-infracfg.c +2 -0
@@ -128,6 +128,8 @@ static int clk_mt8173_infracfg_probe(struct platform_device *pdev)if (r) goto unregister_clk_hw; +platform_set_drvdata (pdev, clk_data); +return 0 ; unregister_clk_hw:
Signature · 1 line
2.54.0
Re: [PATCH v2 5/6] clk: mediatek: mt8173: fix memory leak on module removal
Quoted 7 lines · Akari Tsuyukusa
clk-mt8173-apmixedsys.candclk-mt8173-infracfg.cdo not callplatform_set_drvdata()during their driver probe callback, but their remove callback callsplatform_get_drvdata(). This results inplatform_get_drvdata()returning NULL, which leads to calling kfree(NULL) inmtk_free_clk_data(NULL). This leavesclk_dataunreleased, causing a memory leak.
Quoted 5 lines
Fix this by calling
platform_set_drvdata()during probe.Fixes 4c02c9af3cb9 ("clk: mediatek: mt8173: Break down clock drivers and allow module build")Signed-off-by Akari Tsuyukusa <[email protected]>
Re: [PATCH v2 5/6] clk: mediatek: mt8173: fix memory leak on module removal
In reply to Akari TsuyukusaHi Akari,
Quoted 35 lines · Akari Tsuyukusa
clk-mt8173-apmixedsys.candclk-mt8173-infracfg.cdo not callplatform_set_drvdata()during their driver probe callback, but their remove callback callsplatform_get_drvdata(). This results inplatform_get_drvdata()returning NULL, which leads to calling kfree(NULL) inmtk_free_clk_data(NULL). This leavesclk_dataunreleased, causing a memory leak.Fix this by calling
platform_set_drvdata()during probe.Fixes 4c02c9af3cb9 ("clk: mediatek: mt8173: Break down clock drivers and allow module build")Signed-off-by Akari Tsuyukusa <[email protected]>--- drivers/clk/mediatek/clk-mt8173-apmixedsys.c | 2 ++ drivers/clk/mediatek/clk-mt8173-infracfg.c | 2 ++ 2 files changed, 4 insertions(+)drivers/clk/mediatek/clk-mt8173-apmixedsys.c +2
-0@@ -179,6 +179,8 @@ static int clk_mt8173_apmixed_probe(struct platform_device *pdev)if (r) goto unregister_ref2usb; +platform_set_drvdata (pdev, clk_data); +return 0 ; unregister_ref2usb:drivers/clk/mediatek/clk-mt8173-infracfg.c +0
-0
drivers/clk/mediatek/clk-mt8173-infracfg.c static int clk_mt8173_infracfg_probe(struct platform_device *pdev) · line 132
Quoted 5 lines
drivers/clk/mediatek/clk-mt8173-infracfg.c +2
-0@@ -128,6 +128,8 @@ static int clk_mt8173_infracfg_probe(struct platform_device *pdev)if (r) goto unregister_clk_hw; +platform_set_drvdata (pdev, clk_data); +
This patch doesn't compile.
drivers/clk/mediatek/clk-mt8173-infracfg.c: In function ‘clk_mt8173_infracfg_probe’:
drivers/clk/mediatek/clk-mt8173-infracfg.c:131:36: error: ‘clk_data’ undeclared (first use in this function); did you mean ‘clk_gate’?
Brian
Re: [PATCH v2 5/6] clk: mediatek: mt8173: fix memory leak on module removal
Hi Brian,
Quoted 39 lines · Brian Masney
Quoted 38 lines · Akari Tsuyukusa
clk-mt8173-apmixedsys.candclk-mt8173-infracfg.cdo not callplatform_set_drvdata()during their driver probe callback, but their remove callback callsplatform_get_drvdata(). This results inplatform_get_drvdata()returning NULL, which leads to calling kfree(NULL) inmtk_free_clk_data(NULL). This leavesclk_dataunreleased, causing a memory leak.Fix this by calling
platform_set_drvdata()during probe.Fixes 4c02c9af3cb9 ("clk: mediatek: mt8173: Break down clock drivers and allow module build")Signed-off-by Akari Tsuyukusa <[email protected]>--- drivers/clk/mediatek/clk-mt8173-apmixedsys.c | 2 ++ drivers/clk/mediatek/clk-mt8173-infracfg.c | 2 ++ 2 files changed, 4 insertions(+)drivers/clk/mediatek/clk-mt8173-apmixedsys.c +2
-0@@ -179,6 +179,8 @@ static int clk_mt8173_apmixed_probe(struct platform_device *pdev)if (r) goto unregister_ref2usb; +platform_set_drvdata (pdev, clk_data); +return 0 ; unregister_ref2usb:drivers/clk/mediatek/clk-mt8173-infracfg.c +0
-0@@ -128,6 +128,8 @@ static int clk_mt8173_infracfg_probe(struct platform_device *pdev)if (r) goto unregister_clk_hw;
Quoted 7 lines
drivers/clk/mediatek/clk-mt8173-infracfg.c static int clk_mt8173_infracfg_probe(struct platform_device *pdev) · line 132
Quoted 2 lines
drivers/clk/mediatek/clk-mt8173-infracfg.c +2
-0+platform_set_drvdata (pdev, clk_data); +This patch doesn't compile.
drivers/clk/mediatek/clk-mt8173-infracfg.c: In function ‘clk_mt8173_infracfg_probe’:
drivers/clk/mediatek/clk-mt8173-infracfg.c:131:36: error: ‘clk_data’ undeclared (first use in this function); did you mean ‘clk_gate’?
Sorry for sending you a broken patch.
I accidentally built only with ARCH=arm and missed the build failure.
While fixing this, I noticed that clk-mt8173-infracfg.c can be converted to use mtk_clk_simple_probe()/remove() instead of adding driver-specific drvdata handling.
The helper currently lacks cpumux support, but I have a reviewed patch for it:
https://lore.kernel.org/lkml/[email protected]/
(Reviewed-by: Chen-Yu Tsai <[email protected]>)
Also, adding PLL support to the helper should allow more MediaTek clock drivers to use the common probe/remove path:
https://github.com/TeamYogaBlade2/linux/commit/d991a61887ab76fd83708dffe8e48192e01023d5
Would it be preferable to extend mtk_clk_simple_probe()/remove() with cpumux and PLL support and reorganize this series around it? or should I keep this series focused on the current simple fixes?
Best Regards,
Akari
Re: [PATCH v2 5/6] clk: mediatek: mt8173: fix memory leak on module removal
Hi Akari,
Quoted 60 lines · Akari Tsuyukusa
Quoted 39 lines · Brian Masney
Quoted 38 lines · Akari Tsuyukusa
clk-mt8173-apmixedsys.candclk-mt8173-infracfg.cdo not callplatform_set_drvdata()during their driver probe callback, but their remove callback callsplatform_get_drvdata(). This results inplatform_get_drvdata()returning NULL, which leads to calling kfree(NULL) inmtk_free_clk_data(NULL). This leavesclk_dataunreleased, causing a memory leak.Fix this by calling
platform_set_drvdata()during probe.Fixes 4c02c9af3cb9 ("clk: mediatek: mt8173: Break down clock drivers and allow module build")Signed-off-by Akari Tsuyukusa <[email protected]>--- drivers/clk/mediatek/clk-mt8173-apmixedsys.c | 2 ++ drivers/clk/mediatek/clk-mt8173-infracfg.c | 2 ++ 2 files changed, 4 insertions(+)drivers/clk/mediatek/clk-mt8173-apmixedsys.c +2
-0@@ -179,6 +179,8 @@ static int clk_mt8173_apmixed_probe(struct platform_device *pdev)if (r) goto unregister_ref2usb; +platform_set_drvdata (pdev, clk_data); +return 0 ; unregister_ref2usb:drivers/clk/mediatek/clk-mt8173-infracfg.c +0
-0@@ -128,6 +128,8 @@ static int clk_mt8173_infracfg_probe(struct platform_device *pdev)if (r) goto unregister_clk_hw;Quoted 7 lines
drivers/clk/mediatek/clk-mt8173-infracfg.c static int clk_mt8173_infracfg_probe(struct platform_device *pdev) · line 132
Quoted 2 lines
drivers/clk/mediatek/clk-mt8173-infracfg.c +2
-0+platform_set_drvdata (pdev, clk_data); +This patch doesn't compile.
drivers/clk/mediatek/clk-mt8173-infracfg.c: In function ‘clk_mt8173_infracfg_probe’:
drivers/clk/mediatek/clk-mt8173-infracfg.c:131:36: error: ‘clk_data’ undeclared (first use in this function); did you mean ‘clk_gate’?Sorry for sending you a broken patch.
I accidentally built only with ARCH=arm and missed the build failure.While fixing this, I noticed that
clk-mt8173-infracfg.ccan be converted to use mtk_clk_simple_probe()/remove() instead of adding driver-specific drvdata handling.The helper currently lacks cpumux support, but I have a reviewed patch for it:
https://lore.kernel.org/lkml/[email protected]/
(Reviewed-by: Chen-Yu Tsai <[email protected]>)
Quoted 6 lines
Also, adding PLL support to the helper should allow more MediaTek clock drivers to use the common probe/remove path:
https://github.com/TeamYogaBlade2/linux/commit/d991a61887ab76fd83708dffe8e48192e01023d5Would it be preferable to extend mtk_clk_simple_probe()/remove() with cpumux and PLL support and reorganize this series around it?
Yes, that sounds good.
Brian
PATCH v2 6/6 clk: mediatek: mt8192: fix memory leak on module removal
In reply to Akari Tsuyukusaclk_mt8192_apmixed_probe() in clk-mt8192-apmixedsys.c does not call platform_set_drvdata(), but clk_mt8192_apmixed_remove() callback calls platform_get_drvdata().
This results in platform_get_drvdata() returning NULL, which leads to calling kfree(NULL) in mtk_free_clk_data(NULL). This leaves clk_data unreleased, causing a memory leak.
Fix this by calling platform_set_drvdata() during probe.
--- drivers/clk/mediatek/clk-mt8192-apmixedsys.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/clk/mediatek/clk-mt8192-apmixedsys.c +2 -0
@@ -176,6 +176,8 @@ static int clk_mt8192_apmixed_probe(struct platform_device *pdev)if (r) goto unregister_gates; +platform_set_drvdata (pdev, clk_data); +return r; unregister_gates:
Signature · 1 line
2.54.0
Re: [PATCH v2 6/6] clk: mediatek: mt8192: fix memory leak on module removal
Quoted 7 lines · Akari Tsuyukusa
clk_mt8192_apmixed_probe()inclk-mt8192-apmixedsys.cdoes not callplatform_set_drvdata(), butclk_mt8192_apmixed_remove()callback callsplatform_get_drvdata().
This results inplatform_get_drvdata()returning NULL, which leads to calling kfree(NULL) inmtk_free_clk_data(NULL). This leavesclk_dataunreleased, causing a memory leak.
Quoted 5 lines
Fix this by calling
platform_set_drvdata()during probe.Fixes 124294ff468f ("clk: mediatek: mt8192: Move apmixedsys clock driver to its own file")Signed-off-by Akari Tsuyukusa <[email protected]>