clk: samsung: Fix power-domain, bus clock, and missing PLL sentinel bugs
Subsystems (6)
cover clk: samsung: Fix power-domain, bus clock, and missing PLL sentinel bugs
The first two issues were reported by Sashiko; the remaining ten patches append missing zero sentinels to all remaining Samsung PLL rate tables, following Krzysztof Kozlowski's request on the Exynos5420 fix.
This series is based on krzk/linux next/clk.
Lee Jones (12):
clk: samsung: exynos5-subcmu: Detach power domain on add failure
clk: samsung: exynos-arm64: Do not store ERR_PTR in data->clk
clk: samsung: artpec8: Terminate PLL rate table with sentinel
clk: samsung: artpec9: Terminate PLL rate tables with sentinels
clk: samsung: exynos5250: Terminate PLL rate table with sentinel
clk: samsung: exynos5260: Terminate PLL rate tables with sentinels
clk: samsung: exynos5410: Terminate PLL rate table with sentinel
clk: samsung: exynos7885: Terminate PLL rate table with sentinel
clk: samsung: exynos850: Terminate PLL rate table with sentinel
clk: samsung: exynos8895: Terminate PLL rate tables with sentinels
clk: samsung: exynosautov920: Terminate PLL rate table with sentinel
clk: samsung: fsd: Terminate PLL rate tables with sentinels
drivers/clk/samsung/clk-artpec8.c | 1 + drivers/clk/samsung/clk-artpec9.c | 3 +++ drivers/clk/samsung/clk-exynos-arm64.c | 26 ++++++++++++++++-------- drivers/clk/samsung/clk-exynos5-subcmu.c | 9 +++++--- drivers/clk/samsung/clk-exynos5250.c | 1 + drivers/clk/samsung/clk-exynos5260.c | 2 ++ drivers/clk/samsung/clk-exynos5410.c | 1 + drivers/clk/samsung/clk-exynos7885.c | 1 + drivers/clk/samsung/clk-exynos850.c | 1 + drivers/clk/samsung/clk-exynos8895.c | 5 +++++ drivers/clk/samsung/clk-exynosautov920.c | 1 + drivers/clk/samsung/clk-fsd.c | 6 ++++++ 12 files changed, 45 insertions(+), 12 deletions(-)
Signature · 1 line
2.56.1.839.g22a8290db9-goog
PATCH 1/12 clk: samsung: exynos5-subcmu: Detach power domain on add failure
exynos5_clk_register_subcmu() attaches &pdev->dev to its generic power domain via of_genpd_add_device(). If platform_device_add() then fails, it frees pdev via platform_device_put() without detaching it from the power domain, leaving a dangling device pointer in the genpd device list.
Record the return value of of_genpd_add_device() (keeping attachment non-fatal when power domains are disabled) and call pm_genpd_remove_device() before putting pdev if platform_device_add() fails.
--- drivers/clk/samsung/clk-exynos5-subcmu.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)
drivers/clk/samsung/clk-exynos5-subcmu.c +6 -3
@@ -137,7 +137,7 @@ static int __init exynos5_clk_register_subcmu(struct device *parent, {struct of_phandle_args genpdspec = { .np = pd_node };struct platform_device *pdev; -int ret; +int genpd_ret, ret; pdev =platform_device_alloc ("exynos5-subcmu" ,PLATFORM_DEVID_AUTO );if (!pdev)
@@ -145,10 +145,13 @@ static int __init exynos5_clk_register_subcmu(struct device *parent, pdev->dev.parent = parent;platform_set_drvdata (pdev, (void *)info); -of_genpd_add_device (&genpdspec, &pdev->dev); + genpd_ret =of_genpd_add_device (&genpdspec, &pdev->dev); ret =platform_device_add (pdev); -if (ret) +if (ret) { +if (!genpd_ret) +pm_genpd_remove_device (&pdev->dev);platform_device_put (pdev); + }return ret; }
Signature · 1 line
2.56.1.839.g22a8290db9-goog
PATCH 2/12 clk: samsung: exynos-arm64: Do not store ERR_PTR in data->clk
In reply to Lee Jonesexynos_arm64_enable_bus_clk() assigns parent_clk to data->clk before checking IS_ERR(parent_clk) or enabling the clock. Because exynos_arm64_register_cmu_pm() logs the failure and continues registering PM callbacks, exynos_arm64_cmu_suspend() and exynos_arm64_cmu_resume() later pass the error pointer to clk_disable_unprepare() and clk_prepare_enable(), causing a crash.
Only store parent_clk in data->clk after IS_ERR() and clk_prepare_enable() succeed, and release the clock reference on enable failure.
--- drivers/clk/samsung/clk-exynos-arm64.c | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-)
drivers/clk/samsung/clk-exynos-arm64.c +17 -9
@@ -149,25 +149,33 @@ static int __init exynos_arm64_enable_bus_clk(struct device *dev, struct device_node *np, const struct samsung_cmu_info *cmu) { struct clk *parent_clk; +int ret;if (!cmu->clk_name)return 0 ; -if (dev) { -struct exynos_arm64_cmu_data *data; - +if (dev) parent_clk =clk_get (dev, cmu->clk_name); - data =dev_get_drvdata (dev); -if (data) - data->clk = parent_clk; - }else { +else parent_clk =of_clk_get_by_name (np, cmu->clk_name); - }if (IS_ERR (parent_clk))return PTR_ERR (parent_clk); -return clk_prepare_enable (parent_clk); + ret =clk_prepare_enable (parent_clk); +if (ret) { +clk_put (parent_clk); +return ret; + } + +if (dev) { +struct exynos_arm64_cmu_data *data =dev_get_drvdata (dev); + +if (data) + data->clk = parent_clk; + } + +return 0 ; } static int __init exynos_arm64_cmu_prepare_pm(struct device *dev,
Signature · 1 line
2.56.1.839.g22a8290db9-goog
PATCH 3/12 clk: samsung: artpec8: Terminate PLL rate table with sentinel
In reply to Lee Jones_samsung_clk_register_pll() sizes each PLL rate table by scanning until it encounters an entry with .rate == 0, then copies the counted entries into pll->rate_table. However, artpec8_pll_audio_rates omits a terminating zero sentinel, causing out-of-bounds reads into adjacent read-only data and populating pll->rate_table with bogus entries.
Append a sentinel entry to artpec8_pll_audio_rates.
--- drivers/clk/samsung/clk-artpec8.c | 1 + 1 file changed, 1 insertion(+)
drivers/clk/samsung/clk-artpec8.c +1 -0
@@ -173,6 +173,7 @@ static const struct samsung_pll_rate_table artpec8_pll_audio_rates[] __initconstPLL_36XX_RATE (25 *MHZ ,100000000U ,32 ,2 ,2 ,0 ),PLL_36XX_RATE (25 *MHZ ,98303985U ,47 ,3 ,2 ,12184 ), PLL_36XX_RATE(25 * MHZ, 49151992U, 47, 3, 3, 12184), + { /* sentinel */ } }; static const struct samsung_pll_clock cmu_cmu_pll_clks[] __initconst = {
Signature · 1 line
2.56.1.839.g22a8290db9-goog
PATCH 4/12 clk: samsung: artpec9: Terminate PLL rate tables with sentinels
In reply to Lee Jones_samsung_clk_register_pll() sizes each PLL rate table by scanning until it encounters an entry with .rate == 0, then copies the counted entries into pll->rate_table. However, artpec9_pll_audio_rates, artpec9_pll_cpucl_rates, and artpec9_pll_fsys1_rates all omit a terminating zero sentinel, causing out-of-bounds reads into adjacent read-only data and populating pll->rate_table with bogus entries.
Append a sentinel entry to each of the 3 PLL rate tables.
--- drivers/clk/samsung/clk-artpec9.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/clk/samsung/clk-artpec9.c +3 -0
@@ -176,6 +176,7 @@ static const unsigned long cmu_cmu_clk_regs[] __initconst = {static const struct samsung_pll_rate_table artpec9_pll_audio_rates[]__initconst = {PLL_A9FRACO_RATE (25 *MHZ ,589824000U ,94 ,1 ,3 ,6238440 ), + {/* sentinel */ } };static const struct samsung_pll_clock cmu_cmu_pll_clks[]__initconst = {
@@ -490,6 +491,7 @@ static const struct samsung_pll_rate_table artpec9_pll_cpucl_rates[] __initconstPLL_35XX_RATE (25 *MHZ ,1400000000U ,56 ,1 ,0 ),PLL_35XX_RATE (25 *MHZ ,1100000000U ,44 ,1 ,0 ), PLL_35XX_RATE(25 * MHZ, 850000000U, 34, 1, 0), + { /* sentinel */ } }; static const struct samsung_pll_clock cmu_cpucl_pll_clks[] __initconst = {
@@ -815,6 +817,7 @@ static const unsigned long cmu_fsys1_clk_regs[] __initconst = {static const struct samsung_pll_rate_table artpec9_pll_fsys1_rates[]__initconst = {PLL_35XX_RATE (25 *MHZ ,2000000000U ,80 ,1 ,0 ), + {/* sentinel */ } };static const struct samsung_pll_clock cmu_fsys1_pll_clks[]__initconst = {
Signature · 1 line
2.56.1.839.g22a8290db9-goog
PATCH 5/12 clk: samsung: exynos5250: Terminate PLL rate table with sentinel
In reply to Lee Jones_samsung_clk_register_pll() sizes each PLL rate table by scanning until it encounters an entry with .rate == 0, then copies the counted entries into pll->rate_table. However, apll_24mhz_tbl omits a terminating zero sentinel, causing out-of-bounds reads into adjacent read-only data and populating pll->rate_table with bogus entries.
Append a sentinel entry to apll_24mhz_tbl.
--- drivers/clk/samsung/clk-exynos5250.c | 1 + 1 file changed, 1 insertion(+)
drivers/clk/samsung/clk-exynos5250.c +1 -0
@@ -730,6 +730,7 @@ static const struct samsung_pll_rate_table apll_24mhz_tbl[] __initconst = {PLL_35XX_RATE (24 *MHZ ,400000000 ,100 ,3 ,1 ),PLL_35XX_RATE (24 *MHZ ,300000000 ,200 ,4 ,2 ), PLL_35XX_RATE(24 * MHZ, 200000000, 100, 3, 2), + { /* sentinel */ } }; static struct samsung_pll_clock exynos5250_plls[nr_plls] __initdata = {
Signature · 1 line
2.56.1.839.g22a8290db9-goog
PATCH 6/12 clk: samsung: exynos5260: Terminate PLL rate tables with sentinels
In reply to Lee Jones_samsung_clk_register_pll() sizes each PLL rate table by scanning until it encounters an entry with .rate == 0, then copies the counted entries into pll->rate_table. However, pll2550_24mhz_tbl and pll2650_24mhz_tbl both omit a terminating zero sentinel, causing out-of-bounds reads into adjacent read-only data and populating pll->rate_table with bogus entries.
Append a sentinel entry to both PLL rate tables.
--- drivers/clk/samsung/clk-exynos5260.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/clk/samsung/clk-exynos5260.c +2 -0
@@ -59,6 +59,7 @@ static const struct samsung_pll_rate_table pll2550_24mhz_tbl[] __initconst = {PLL_35XX_RATE (24 *MHZ ,266000000 ,266 ,3 ,3 ),PLL_35XX_RATE (24 *MHZ ,200000000 ,200 ,3 ,3 ), PLL_35XX_RATE(24 * MHZ, 160000000, 160, 3, 3), + { /* sentinel */ } };/*
@@ -83,6 +84,7 @@ static const struct samsung_pll_rate_table pll2650_24mhz_tbl[] __initconst = {PLL_36XX_RATE (24 *MHZ ,133000000 ,266 ,3 ,4 ,0 ),PLL_36XX_RATE (24 *MHZ ,100000000 ,200 ,3 ,4 ,0 ), PLL_36XX_RATE(24 * MHZ, 66000000, 176, 2, 5, 0), + { /* sentinel */ } };/* CMU_AUD */
Signature · 1 line
2.56.1.839.g22a8290db9-goog
PATCH 7/12 clk: samsung: exynos5410: Terminate PLL rate table with sentinel
In reply to Lee Jones_samsung_clk_register_pll() sizes each PLL rate table by scanning until it encounters an entry with .rate == 0, then copies the counted entries into pll->rate_table. However, exynos5410_pll2550x_24mhz_tbl omits a terminating zero sentinel, causing out-of-bounds reads into adjacent read-only data and populating pll->rate_table with bogus entries.
Append a sentinel entry to exynos5410_pll2550x_24mhz_tbl.
--- drivers/clk/samsung/clk-exynos5410.c | 1 + 1 file changed, 1 insertion(+)
drivers/clk/samsung/clk-exynos5410.c +1 -0
@@ -235,6 +235,7 @@ static const struct samsung_pll_rate_table exynos5410_pll2550x_24mhz_tbl[] __iniPLL_36XX_RATE (24 *MHZ ,133000000U ,266 ,3 ,4 ,0 ),PLL_36XX_RATE (24 *MHZ ,100000000U ,200 ,3 ,4 ,0 ), PLL_36XX_RATE(24 * MHZ, 66000000U, 176, 2, 5, 0), + { /* sentinel */ } }; static struct samsung_pll_clock exynos5410_plls[nr_plls] __initdata = {
Signature · 1 line
2.56.1.839.g22a8290db9-goog
PATCH 8/12 clk: samsung: exynos7885: Terminate PLL rate table with sentinel
In reply to Lee Jones_samsung_clk_register_pll() sizes each PLL rate table by scanning until it encounters an entry with .rate == 0, then copies the counted entries into pll->rate_table. However, pll_usb_rate_table omits a terminating zero sentinel, causing out-of-bounds reads into adjacent read-only data and populating pll->rate_table with bogus entries.
Append a sentinel entry to pll_usb_rate_table.
--- drivers/clk/samsung/clk-exynos7885.c | 1 + 1 file changed, 1 insertion(+)
drivers/clk/samsung/clk-exynos7885.c +1 -0
@@ -729,6 +729,7 @@ static const unsigned long fsys_clk_regs[] __initconst = {static const struct samsung_pll_rate_table pll_usb_rate_table[]__initconst = {PLL_35XX_RATE (26 *MHZ ,50000000U ,400 ,13 ,4 ), + {/* sentinel */ } };static const struct samsung_pll_clock fsys_pll_clks[]__initconst = {
Signature · 1 line
2.56.1.839.g22a8290db9-goog
PATCH 9/12 clk: samsung: exynos850: Terminate PLL rate table with sentinel
In reply to Lee Jones_samsung_clk_register_pll() sizes each PLL rate table by scanning until it encounters an entry with .rate == 0, then copies the counted entries into pll->rate_table. However, cpu_pll_rates omits a terminating zero sentinel, causing out-of-bounds reads into adjacent read-only data and populating pll->rate_table with bogus entries.
Append a sentinel entry to cpu_pll_rates.
--- drivers/clk/samsung/clk-exynos850.c | 1 + 1 file changed, 1 insertion(+)
drivers/clk/samsung/clk-exynos850.c +1 -0
@@ -1180,6 +1180,7 @@ static const struct samsung_pll_rate_table cpu_pll_rates[] __initconst = {PLL_35XX_RATE (26 *MHZ ,247000000U ,114 ,3 ,2 ),PLL_35XX_RATE (26 *MHZ ,182000000U ,168 ,3 ,3 ), PLL_35XX_RATE(26 * MHZ, 130000000U, 120, 3, 3), + { /* sentinel */ } }; static const struct samsung_pll_clock cpucl0_pll_clks[] __initconst = {
Signature · 1 line
2.56.1.839.g22a8290db9-goog
PATCH 10/12 clk: samsung: exynos8895: Terminate PLL rate tables with sentinels
In reply to Lee Jones_samsung_clk_register_pll() sizes each PLL rate table by scanning until it encounters an entry with .rate == 0, then copies the counted entries into pll->rate_table. However, pll_shared0_rate_table, pll_shared1_rate_table, pll_shared2_rate_table, pll_shared3_rate_table, and pll_shared4_rate_table all omit a terminating zero sentinel, causing out-of-bounds reads into adjacent read-only data and populating pll->rate_table with bogus entries.
Append a sentinel entry to each of the 5 PLL rate tables.
--- drivers/clk/samsung/clk-exynos8895.c | 5 +++++ 1 file changed, 5 insertions(+)
drivers/clk/samsung/clk-exynos8895.c +5 -0
@@ -478,22 +478,27 @@ static const unsigned long top_clk_regs[] __initconst = {static const struct samsung_pll_rate_table pll_shared0_rate_table[]__initconst = {PLL_35XX_RATE (26 *MHZ ,2132000000U ,328 ,4 ,0 ), + {/* sentinel */ } };static const struct samsung_pll_rate_table pll_shared1_rate_table[]__initconst = {PLL_35XX_RATE (26 *MHZ ,1865500000U ,287 ,4 ,0 ), + {/* sentinel */ } };static const struct samsung_pll_rate_table pll_shared2_rate_table[]__initconst = {PLL_35XX_RATE (26 *MHZ ,800000000U ,400 ,13 ,0 ), + {/* sentinel */ } };static const struct samsung_pll_rate_table pll_shared3_rate_table[]__initconst = {PLL_35XX_RATE (26 *MHZ ,630000000U ,315 ,13 ,0 ), + {/* sentinel */ } };static const struct samsung_pll_rate_table pll_shared4_rate_table[]__initconst = {PLL_35XX_RATE (26 *MHZ ,667333333U ,154 ,6 ,0 ), + {/* sentinel */ } };static const struct samsung_pll_clock top_pll_clks[]__initconst = {
Signature · 1 line
2.56.1.839.g22a8290db9-goog
Re: [PATCH 10/12] clk: samsung: exynos8895: Terminate PLL rate tables with sentinels
Quoted 11 lines · Lee Jones
_samsung_clk_register_pll()sizes each PLL rate table by scanning until it encounters an entry with .rate == 0, then copies the counted entries intopll->rate_table. However,pll_shared0_rate_table,pll_shared1_rate_table,pll_shared2_rate_table,pll_shared3_rate_table, andpll_shared4_rate_tableall omit a terminating zero sentinel, causing out-of-bounds reads into adjacent read-only data and populatingpll->rate_tablewith bogus entries.Append a sentinel entry to each of the 5 PLL rate tables.
Fixes 9174fac3b302 ("clk: samsung: Introduce Exynos8895 clock driver")
Looks good to me. Thanks, nice catch!
Quoted 11 lines
Signed-off-by Lee Jones <[email protected]>--- drivers/clk/samsung/clk-exynos8895.c | 5 +++++ 1 file changed, 5 insertions(+)drivers/clk/samsung/clk-exynos8895.c +0
-0
drivers/clk/samsung/clk-exynos8895.c static const unsigned long top_clk_regs[] __initconst = { · line 483
Quoted 6 lines
drivers/clk/samsung/clk-exynos8895.c +1
-0@@ -478,22 +478,27 @@ static const unsigned long top_clk_regs[] __initconst = {static const struct samsung_pll_rate_table pll_shared0_rate_table[]__initconst = {PLL_35XX_RATE (26 *MHZ ,2132000000U ,328 ,4 ,0 ), + {/* sentinel */ } };
...
Best regards,
Ivaylo
PATCH 11/12 clk: samsung: exynosautov920: Terminate PLL rate table with sentinel
In reply to Lee Jones_samsung_clk_register_pll() sizes each PLL rate table by scanning until it encounters an entry with .rate == 0, then copies the counted entries into pll->rate_table. However, cpu_pll_rates omits a terminating zero sentinel, causing out-of-bounds reads into adjacent read-only data and populating pll->rate_table with bogus entries.
Append a sentinel entry to cpu_pll_rates.
--- drivers/clk/samsung/clk-exynosautov920.c | 1 + 1 file changed, 1 insertion(+)
drivers/clk/samsung/clk-exynosautov920.c +1 -0
@@ -1077,6 +1077,7 @@ static const struct samsung_pll_rate_table cpu_pll_rates[] __initconst = {PLL_35XX_RATE (38400000U ,1152000000U ,120 ,4 ,0 ),PLL_35XX_RATE (38400000U ,576000000U ,120 ,4 ,1 ), PLL_35XX_RATE(38400000U, 288000000U, 120, 4, 2), + { /* sentinel */ } }; static const struct samsung_pll_clock cpucl0_pll_clks[] __initconst = {
Signature · 1 line
2.56.1.839.g22a8290db9-goog
PATCH 12/12 clk: samsung: fsd: Terminate PLL rate tables with sentinels
In reply to Lee Jones_samsung_clk_register_pll() sizes each PLL rate table by scanning until it encounters an entry with .rate == 0, then copies the counted entries into pll->rate_table. However, pll_shared0_rate_table, pll_shared1_rate_table, pll_shared2_rate_table, pll_shared3_rate_table, pll_mfc_rate_table, and pll_cam_csi_rate_table all omit a terminating zero sentinel, causing out-of-bounds reads into adjacent read-only data and populating pll->rate_table with bogus entries.
Append a sentinel entry to each of the 6 PLL rate tables.
--- drivers/clk/samsung/clk-fsd.c | 6 ++++++ 1 file changed, 6 insertions(+)
drivers/clk/samsung/clk-fsd.c +6 -0
@@ -155,18 +155,22 @@ static const unsigned long cmu_clk_regs[] __initconst = {static const struct samsung_pll_rate_table pll_shared0_rate_table[]__initconst = {PLL_35XX_RATE (24 *MHZ ,2000000000U ,250 ,3 ,0 ), + {/* sentinel */ } };static const struct samsung_pll_rate_table pll_shared1_rate_table[]__initconst = {PLL_35XX_RATE (24 *MHZ ,2400000000U ,200 ,2 ,0 ), + {/* sentinel */ } };static const struct samsung_pll_rate_table pll_shared2_rate_table[]__initconst = {PLL_35XX_RATE (24 *MHZ ,2400000000U ,200 ,2 ,0 ), + {/* sentinel */ } };static const struct samsung_pll_rate_table pll_shared3_rate_table[]__initconst = {PLL_35XX_RATE (24 *MHZ ,1800000000U ,150 ,2 ,0 ), + {/* sentinel */ } };static const struct samsung_pll_clock cmu_pll_clks[]__initconst = {
@@ -1482,6 +1486,7 @@ static const unsigned long mfc_clk_regs[] __initconst = {static const struct samsung_pll_rate_table pll_mfc_rate_table[]__initconst = {PLL_35XX_RATE (24 *MHZ ,666000000U ,111 ,4 ,0 ), + {/* sentinel */ } };static const struct samsung_pll_clock mfc_pll_clks[]__initconst = {
@@ -1642,6 +1647,7 @@ static const unsigned long cam_csi_clk_regs[] __initconst = {static const struct samsung_pll_rate_table pll_cam_csi_rate_table[]__initconst = {PLL_35XX_RATE (24 *MHZ ,1066000000U ,533 ,12 ,0 ), + {/* sentinel */ } };static const struct samsung_pll_clock cam_csi_pll_clks[]__initconst = {
Signature · 1 line
2.56.1.839.g22a8290db9-goog