linux-omap.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [RFT PATCH 0/8] clk: ti: Fix possible ERR_PTR dereferences from clk_get_sys
@ 2015-05-13  6:54 Krzysztof Kozlowski
  2015-05-13  6:54 ` [RFT PATCH 1/8] clk: ti: dra7-atl-clock: Fix possible ERR_PTR dereference Krzysztof Kozlowski
                   ` (8 more replies)
  0 siblings, 9 replies; 11+ messages in thread
From: Krzysztof Kozlowski @ 2015-05-13  6:54 UTC (permalink / raw)
  To: Tero Kristo, Mike Turquette, Stephen Boyd, linux-omap, linux-clk,
	linux-kernel
  Cc: Krzysztof Kozlowski

Hi,


clk_get_sys() may return ERR_PTR but the drivers immediately
dereferenced the return value. This could lead to oops.

I tried only to fix possible ERR_PTR dereference and to not change
the logic. This is why some of the patches look quite complex.
For example in clk-7xx driver proceeds to next clocks if first one fails.

WARNING:
The patchset was only compile tested (plus static checkers), as
I do not have the hardware. I am kindly asking for tests.


Best regards,
Krzysztof


Krzysztof Kozlowski (8):
  clk: ti: dra7-atl-clock: Fix possible ERR_PTR dereference
  clk: ti: clk-2xxx: Prevent possible ERR_PTR dereference
  clk: ti: clk-3xxx: Prevent possible ERR_PTR dereference
  clk: ti: clk-33xx: Prevent possible ERR_PTR dereference
  clk: ti: clk-43xx: Prevent possible ERR_PTR dereference
  clk: ti: clk-43xx: Prevent possible ERR_PTR dereference
  clk: ti: clk-54xx: Prevent possible ERR_PTR dereference
  clk: ti: clk-7xx: Prevent possible ERR_PTR dereference

 drivers/clk/ti/clk-2xxx.c     | 18 ++++++++++++----
 drivers/clk/ti/clk-33xx.c     |  9 +++++---
 drivers/clk/ti/clk-3xxx.c     | 18 ++++++++++++----
 drivers/clk/ti/clk-43xx.c     |  3 ++-
 drivers/clk/ti/clk-44xx.c     | 16 ++++++++++----
 drivers/clk/ti/clk-54xx.c     | 47 +++++++++++++++++++++++++++-------------
 drivers/clk/ti/clk-7xx.c      | 50 +++++++++++++++++++++++++------------------
 drivers/clk/ti/clk-dra7-atl.c |  5 +++++
 8 files changed, 114 insertions(+), 52 deletions(-)

-- 
1.9.1

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

* [RFT PATCH 1/8] clk: ti: dra7-atl-clock: Fix possible ERR_PTR dereference
  2015-05-13  6:54 [RFT PATCH 0/8] clk: ti: Fix possible ERR_PTR dereferences from clk_get_sys Krzysztof Kozlowski
@ 2015-05-13  6:54 ` Krzysztof Kozlowski
  2015-05-14 22:31   ` Stephen Boyd
  2015-05-13  6:54 ` [RFT PATCH 2/8] clk: ti: clk-2xxx: Prevent " Krzysztof Kozlowski
                   ` (7 subsequent siblings)
  8 siblings, 1 reply; 11+ messages in thread
From: Krzysztof Kozlowski @ 2015-05-13  6:54 UTC (permalink / raw)
  To: Tero Kristo, Mike Turquette, Stephen Boyd, linux-omap, linux-clk,
	linux-kernel
  Cc: Krzysztof Kozlowski, stable

of_clk_get_from_provider() returns ERR_PTR on failure. The
dra7-atl-clock driver was not checking its return value and immediately
used it in __clk_get_hw().  __clk_get_hw() dereferences supplied clock,
if it is not NULL, so in that case it would dereference an ERR_PTR.

Signed-off-by: Krzysztof Kozlowski <k.kozlowski@samsung.com>
Cc: <stable@vger.kernel.org>
Fixes: 9ac33b0ce81f ("CLK: TI: Driver for DRA7 ATL (Audio Tracking Logic)")
---
 drivers/clk/ti/clk-dra7-atl.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/drivers/clk/ti/clk-dra7-atl.c b/drivers/clk/ti/clk-dra7-atl.c
index d86bc46b93bd..0a1df821860f 100644
--- a/drivers/clk/ti/clk-dra7-atl.c
+++ b/drivers/clk/ti/clk-dra7-atl.c
@@ -252,6 +252,11 @@ static int of_dra7_atl_clk_probe(struct platform_device *pdev)
 		}
 
 		clk = of_clk_get_from_provider(&clkspec);
+		if (IS_ERR(clk)) {
+			pr_err("%s: failed to get atl clock %d from provider\n",
+			       __func__, i);
+			return PTR_ERR(clk);
+		}
 
 		cdesc = to_atl_desc(__clk_get_hw(clk));
 		cdesc->cinfo = cinfo;
-- 
1.9.1

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

* [RFT PATCH 2/8] clk: ti: clk-2xxx: Prevent possible ERR_PTR dereference
  2015-05-13  6:54 [RFT PATCH 0/8] clk: ti: Fix possible ERR_PTR dereferences from clk_get_sys Krzysztof Kozlowski
  2015-05-13  6:54 ` [RFT PATCH 1/8] clk: ti: dra7-atl-clock: Fix possible ERR_PTR dereference Krzysztof Kozlowski
@ 2015-05-13  6:54 ` Krzysztof Kozlowski
  2015-05-13  6:54 ` [RFT PATCH 3/8] clk: ti: clk-3xxx: " Krzysztof Kozlowski
                   ` (6 subsequent siblings)
  8 siblings, 0 replies; 11+ messages in thread
From: Krzysztof Kozlowski @ 2015-05-13  6:54 UTC (permalink / raw)
  To: Tero Kristo, Mike Turquette, Stephen Boyd, linux-omap, linux-clk,
	linux-kernel
  Cc: Krzysztof Kozlowski

Provide a wrapper to prevent possible ERR_PTR dereference by
clk_get_rate().

The return value of clk_get_sys() was immediately used in
clk_get_rate(). The first one may return ERR_PTR and the latter only
checks if supplied argument is non-NULL.

Signed-off-by: Krzysztof Kozlowski <k.kozlowski@samsung.com>
---
 drivers/clk/ti/clk-2xxx.c | 18 ++++++++++++++----
 1 file changed, 14 insertions(+), 4 deletions(-)

diff --git a/drivers/clk/ti/clk-2xxx.c b/drivers/clk/ti/clk-2xxx.c
index c808ab3d2bb2..d6996c3db843 100644
--- a/drivers/clk/ti/clk-2xxx.c
+++ b/drivers/clk/ti/clk-2xxx.c
@@ -220,6 +220,16 @@ enum {
 	OMAP2_SOC_OMAP2430,
 };
 
+static unsigned long __init omap2xxx_clk_get_rate(const char *clk_name)
+{
+	struct clk *clk = clk_get_sys(NULL, clk_name);
+
+	if (IS_ERR(clk))
+		return 0;
+
+	return clk_get_rate(clk);
+}
+
 static int __init omap2xxx_dt_clk_init(int soc_type)
 {
 	ti_dt_clocks_register(omap2xxx_clks);
@@ -237,10 +247,10 @@ static int __init omap2xxx_dt_clk_init(int soc_type)
 				     ARRAY_SIZE(enable_init_clks));
 
 	pr_info("Clocking rate (Crystal/DPLL/MPU): %ld.%01ld/%ld/%ld MHz\n",
-		(clk_get_rate(clk_get_sys(NULL, "sys_ck")) / 1000000),
-		(clk_get_rate(clk_get_sys(NULL, "sys_ck")) / 100000) % 10,
-		(clk_get_rate(clk_get_sys(NULL, "dpll_ck")) / 1000000),
-		(clk_get_rate(clk_get_sys(NULL, "mpu_ck")) / 1000000));
+		(omap2xxx_clk_get_rate("sys_ck") / 1000000),
+		(omap2xxx_clk_get_rate("sys_ck") / 100000) % 10,
+		(omap2xxx_clk_get_rate("dpll_ck") / 1000000),
+		(omap2xxx_clk_get_rate("mpu_ck") / 1000000));
 
 	return 0;
 }
-- 
1.9.1

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

* [RFT PATCH 3/8] clk: ti: clk-3xxx: Prevent possible ERR_PTR dereference
  2015-05-13  6:54 [RFT PATCH 0/8] clk: ti: Fix possible ERR_PTR dereferences from clk_get_sys Krzysztof Kozlowski
  2015-05-13  6:54 ` [RFT PATCH 1/8] clk: ti: dra7-atl-clock: Fix possible ERR_PTR dereference Krzysztof Kozlowski
  2015-05-13  6:54 ` [RFT PATCH 2/8] clk: ti: clk-2xxx: Prevent " Krzysztof Kozlowski
@ 2015-05-13  6:54 ` Krzysztof Kozlowski
  2015-05-13  6:54 ` [RFT PATCH 4/8] clk: ti: clk-33xx: " Krzysztof Kozlowski
                   ` (5 subsequent siblings)
  8 siblings, 0 replies; 11+ messages in thread
From: Krzysztof Kozlowski @ 2015-05-13  6:54 UTC (permalink / raw)
  To: Tero Kristo, Mike Turquette, Stephen Boyd, linux-omap, linux-clk,
	linux-kernel
  Cc: Krzysztof Kozlowski

Provide a wrapper to prevent possible ERR_PTR dereference by
clk_get_rate().

The return value of clk_get_sys() was immediately used in
clk_get_rate(). The first one may return ERR_PTR and the latter only
checks if supplied argument is non-NULL.

Signed-off-by: Krzysztof Kozlowski <k.kozlowski@samsung.com>
---
 drivers/clk/ti/clk-3xxx.c | 18 ++++++++++++++----
 1 file changed, 14 insertions(+), 4 deletions(-)

diff --git a/drivers/clk/ti/clk-3xxx.c b/drivers/clk/ti/clk-3xxx.c
index 757636d166cf..1db3afff34fb 100644
--- a/drivers/clk/ti/clk-3xxx.c
+++ b/drivers/clk/ti/clk-3xxx.c
@@ -324,6 +324,16 @@ enum {
 	OMAP3_SOC_OMAP3630,
 };
 
+static unsigned long __init omap3xxx_clk_get_rate(const char *clk_name)
+{
+	struct clk *clk = clk_get_sys(NULL, clk_name);
+
+	if (IS_ERR(clk))
+		return 0;
+
+	return clk_get_rate(clk);
+}
+
 static int __init omap3xxx_dt_clk_init(int soc_type)
 {
 	if (soc_type == OMAP3_SOC_AM35XX || soc_type == OMAP3_SOC_OMAP3630 ||
@@ -359,10 +369,10 @@ static int __init omap3xxx_dt_clk_init(int soc_type)
 				     ARRAY_SIZE(enable_init_clks));
 
 	pr_info("Clocking rate (Crystal/Core/MPU): %ld.%01ld/%ld/%ld MHz\n",
-		(clk_get_rate(clk_get_sys(NULL, "osc_sys_ck")) / 1000000),
-		(clk_get_rate(clk_get_sys(NULL, "osc_sys_ck")) / 100000) % 10,
-		(clk_get_rate(clk_get_sys(NULL, "core_ck")) / 1000000),
-		(clk_get_rate(clk_get_sys(NULL, "arm_fck")) / 1000000));
+		(omap3xxx_clk_get_rate("osc_sys_ck") / 1000000),
+		(omap3xxx_clk_get_rate("osc_sys_ck") / 100000) % 10,
+		(omap3xxx_clk_get_rate("core_ck") / 1000000),
+		(omap3xxx_clk_get_rate("arm_fck") / 1000000));
 
 	if (soc_type != OMAP3_SOC_OMAP3430_ES1)
 		omap3_clk_lock_dpll5();
-- 
1.9.1

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

* [RFT PATCH 4/8] clk: ti: clk-33xx: Prevent possible ERR_PTR dereference
  2015-05-13  6:54 [RFT PATCH 0/8] clk: ti: Fix possible ERR_PTR dereferences from clk_get_sys Krzysztof Kozlowski
                   ` (2 preceding siblings ...)
  2015-05-13  6:54 ` [RFT PATCH 3/8] clk: ti: clk-3xxx: " Krzysztof Kozlowski
@ 2015-05-13  6:54 ` Krzysztof Kozlowski
  2015-05-13  6:54 ` [RFT PATCH 5/8] clk: ti: clk-43xx: " Krzysztof Kozlowski
                   ` (4 subsequent siblings)
  8 siblings, 0 replies; 11+ messages in thread
From: Krzysztof Kozlowski @ 2015-05-13  6:54 UTC (permalink / raw)
  To: Tero Kristo, Mike Turquette, Stephen Boyd, linux-omap, linux-clk,
	linux-kernel
  Cc: Krzysztof Kozlowski

The return value of clk_get_sys() was immediately used in
clk_set_parent(). The first one may return ERR_PTR and the latter only
checks if supplied argument is non-NULL.

Signed-off-by: Krzysztof Kozlowski <k.kozlowski@samsung.com>
---
 drivers/clk/ti/clk-33xx.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/drivers/clk/ti/clk-33xx.c b/drivers/clk/ti/clk-33xx.c
index 028b33783d38..c08db8944fb8 100644
--- a/drivers/clk/ti/clk-33xx.c
+++ b/drivers/clk/ti/clk-33xx.c
@@ -141,10 +141,12 @@ int __init am33xx_dt_clk_init(void)
 
 	clk1 = clk_get_sys(NULL, "sys_clkin_ck");
 	clk2 = clk_get_sys(NULL, "timer3_fck");
-	clk_set_parent(clk2, clk1);
+	if (!IS_ERR(clk1) && !IS_ERR(clk2))
+		clk_set_parent(clk2, clk1);
 
 	clk2 = clk_get_sys(NULL, "timer6_fck");
-	clk_set_parent(clk2, clk1);
+	if (!IS_ERR(clk1) && !IS_ERR(clk2))
+		clk_set_parent(clk2, clk1);
 	/*
 	 * The On-Chip 32K RC Osc clock is not an accurate clock-source as per
 	 * the design/spec, so as a result, for example, timer which supposed
@@ -154,7 +156,8 @@ int __init am33xx_dt_clk_init(void)
 	 */
 	clk1 = clk_get_sys(NULL, "wdt1_fck");
 	clk2 = clk_get_sys(NULL, "clkdiv32k_ick");
-	clk_set_parent(clk1, clk2);
+	if (!IS_ERR(clk1) && !IS_ERR(clk2))
+		clk_set_parent(clk1, clk2);
 
 	return 0;
 }
-- 
1.9.1


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

* [RFT PATCH 5/8] clk: ti: clk-43xx: Prevent possible ERR_PTR dereference
  2015-05-13  6:54 [RFT PATCH 0/8] clk: ti: Fix possible ERR_PTR dereferences from clk_get_sys Krzysztof Kozlowski
                   ` (3 preceding siblings ...)
  2015-05-13  6:54 ` [RFT PATCH 4/8] clk: ti: clk-33xx: " Krzysztof Kozlowski
@ 2015-05-13  6:54 ` Krzysztof Kozlowski
  2015-05-13  6:54 ` [RFT PATCH 6/8] " Krzysztof Kozlowski
                   ` (3 subsequent siblings)
  8 siblings, 0 replies; 11+ messages in thread
From: Krzysztof Kozlowski @ 2015-05-13  6:54 UTC (permalink / raw)
  To: Tero Kristo, Mike Turquette, Stephen Boyd, linux-omap, linux-clk,
	linux-kernel
  Cc: Krzysztof Kozlowski

The return value of clk_get_sys() was immediately used in
clk_set_parent(). The first one may return ERR_PTR and the latter only
checks if supplied argument is non-NULL.

Signed-off-by: Krzysztof Kozlowski <k.kozlowski@samsung.com>
---
 drivers/clk/ti/clk-43xx.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/clk/ti/clk-43xx.c b/drivers/clk/ti/clk-43xx.c
index 3795fce8a830..c6e1fc704052 100644
--- a/drivers/clk/ti/clk-43xx.c
+++ b/drivers/clk/ti/clk-43xx.c
@@ -134,7 +134,8 @@ int __init am43xx_dt_clk_init(void)
 	 */
 	clk1 = clk_get_sys(NULL, "cpsw_cpts_rft_clk");
 	clk2 = clk_get_sys(NULL, "dpll_core_m5_ck");
-	clk_set_parent(clk1, clk2);
+	if (!IS_ERR(clk1) && !IS_ERR(clk2))
+		clk_set_parent(clk1, clk2);
 
 	return 0;
 }
-- 
1.9.1


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

* [RFT PATCH 6/8] clk: ti: clk-43xx: Prevent possible ERR_PTR dereference
  2015-05-13  6:54 [RFT PATCH 0/8] clk: ti: Fix possible ERR_PTR dereferences from clk_get_sys Krzysztof Kozlowski
                   ` (4 preceding siblings ...)
  2015-05-13  6:54 ` [RFT PATCH 5/8] clk: ti: clk-43xx: " Krzysztof Kozlowski
@ 2015-05-13  6:54 ` Krzysztof Kozlowski
  2015-05-13  6:54 ` [RFT PATCH 7/8] clk: ti: clk-54xx: " Krzysztof Kozlowski
                   ` (2 subsequent siblings)
  8 siblings, 0 replies; 11+ messages in thread
From: Krzysztof Kozlowski @ 2015-05-13  6:54 UTC (permalink / raw)
  To: Tero Kristo, Mike Turquette, Stephen Boyd, linux-omap, linux-clk,
	linux-kernel
  Cc: Krzysztof Kozlowski

The return value of clk_get_sys() was immediately used in
clk_set_parent() and clk_set_rate(). The first one may return ERR_PTR
and the latter only checks if supplied argument is non-NULL.

Signed-off-by: Krzysztof Kozlowski <k.kozlowski@samsung.com>
---
 drivers/clk/ti/clk-44xx.c | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)

diff --git a/drivers/clk/ti/clk-44xx.c b/drivers/clk/ti/clk-44xx.c
index 581db7711f51..6b045ed31747 100644
--- a/drivers/clk/ti/clk-44xx.c
+++ b/drivers/clk/ti/clk-44xx.c
@@ -281,9 +281,11 @@ int __init omap4xxx_dt_clk_init(void)
 	 * domain can transition to retention state when not in use.
 	 */
 	usb_dpll = clk_get_sys(NULL, "dpll_usb_ck");
-	rc = clk_set_rate(usb_dpll, OMAP4_DPLL_USB_DEFFREQ);
-	if (rc)
-		pr_err("%s: failed to configure USB DPLL!\n", __func__);
+	if (!IS_ERR(usb_dpll)) {
+		rc = clk_set_rate(usb_dpll, OMAP4_DPLL_USB_DEFFREQ);
+		if (rc)
+			pr_err("%s: failed to configure USB DPLL!\n", __func__);
+	}
 
 	/*
 	 * On OMAP4460 the ABE DPLL fails to turn on if in idle low-power
@@ -293,9 +295,15 @@ int __init omap4xxx_dt_clk_init(void)
 	 */
 	abe_dpll_ref = clk_get_sys(NULL, "abe_dpll_refclk_mux_ck");
 	sys_32k_ck = clk_get_sys(NULL, "sys_32k_ck");
+	if (IS_ERR(abe_dpll_ref) || IS_ERR(sys_32k_ck)) {
+		pr_err("%s: failed to configure ABE DPLL!\n", __func__);
+		return 0;
+	}
+
 	rc = clk_set_parent(abe_dpll_ref, sys_32k_ck);
+
 	abe_dpll = clk_get_sys(NULL, "dpll_abe_ck");
-	if (!rc)
+	if (!rc && !IS_ERR(abe_dpll))
 		rc = clk_set_rate(abe_dpll, OMAP4_DPLL_ABE_DEFFREQ);
 	if (rc)
 		pr_err("%s: failed to configure ABE DPLL!\n", __func__);
-- 
1.9.1

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

* [RFT PATCH 7/8] clk: ti: clk-54xx: Prevent possible ERR_PTR dereference
  2015-05-13  6:54 [RFT PATCH 0/8] clk: ti: Fix possible ERR_PTR dereferences from clk_get_sys Krzysztof Kozlowski
                   ` (5 preceding siblings ...)
  2015-05-13  6:54 ` [RFT PATCH 6/8] " Krzysztof Kozlowski
@ 2015-05-13  6:54 ` Krzysztof Kozlowski
  2015-05-13  6:54 ` [RFT PATCH 8/8] clk: ti: clk-7xx: " Krzysztof Kozlowski
  2015-05-13  7:07 ` [RFT PATCH 0/8] clk: ti: Fix possible ERR_PTR dereferences from clk_get_sys Tero Kristo
  8 siblings, 0 replies; 11+ messages in thread
From: Krzysztof Kozlowski @ 2015-05-13  6:54 UTC (permalink / raw)
  To: Tero Kristo, Mike Turquette, Stephen Boyd, linux-omap, linux-clk,
	linux-kernel
  Cc: Krzysztof Kozlowski

The return value of clk_get_sys() was immediately used in
clk_set_parent() and clk_set_rate(). The first one may return ERR_PTR
and the latter only checks if supplied argument is non-NULL.

Signed-off-by: Krzysztof Kozlowski <k.kozlowski@samsung.com>
---
 drivers/clk/ti/clk-54xx.c | 47 ++++++++++++++++++++++++++++++++---------------
 1 file changed, 32 insertions(+), 15 deletions(-)

diff --git a/drivers/clk/ti/clk-54xx.c b/drivers/clk/ti/clk-54xx.c
index 96c69a335975..1e7ed6334ab4 100644
--- a/drivers/clk/ti/clk-54xx.c
+++ b/drivers/clk/ti/clk-54xx.c
@@ -222,39 +222,56 @@ static struct ti_dt_clk omap54xx_clks[] = {
 	{ .node_name = NULL },
 };
 
-int __init omap5xxx_dt_clk_init(void)
+static void __init omap5xxx_dt_clk_abe_dpll_init(void)
 {
 	int rc;
-	struct clk *abe_dpll_ref, *abe_dpll, *sys_32k_ck, *usb_dpll;
-
-	ti_dt_clocks_register(omap54xx_clks);
-
-	omap2_clk_disable_autoidle_all();
+	struct clk *abe_dpll_ref, *abe_dpll, *sys_32k_ck;
 
 	abe_dpll_ref = clk_get_sys(NULL, "abe_dpll_clk_mux");
 	sys_32k_ck = clk_get_sys(NULL, "sys_32k_ck");
+	if (IS_ERR(abe_dpll_ref) || IS_ERR(sys_32k_ck)) {
+		pr_err("%s: failed to configure ABE DPLL!\n", __func__);
+		return;
+	}
+
 	rc = clk_set_parent(abe_dpll_ref, sys_32k_ck);
+
 	abe_dpll = clk_get_sys(NULL, "dpll_abe_ck");
-	if (!rc)
+	if (!rc && !IS_ERR(abe_dpll))
 		rc = clk_set_rate(abe_dpll, OMAP5_DPLL_ABE_DEFFREQ);
 	if (rc)
 		pr_err("%s: failed to configure ABE DPLL!\n", __func__);
 
 	abe_dpll = clk_get_sys(NULL, "dpll_abe_m2x2_ck");
-	if (!rc)
+	if (!rc && !IS_ERR(abe_dpll))
 		rc = clk_set_rate(abe_dpll, OMAP5_DPLL_ABE_DEFFREQ * 2);
 	if (rc)
 		pr_err("%s: failed to configure ABE m2x2 DPLL!\n", __func__);
+}
 
-	usb_dpll = clk_get_sys(NULL, "dpll_usb_ck");
-	rc = clk_set_rate(usb_dpll, OMAP5_DPLL_USB_DEFFREQ);
-	if (rc)
-		pr_err("%s: failed to configure USB DPLL!\n", __func__);
+static void __init omap5xxx_dt_clk_usb_dpll_init(const char *clk_name,
+					  unsigned long rate)
+{
+	int rc = -EINVAL;
+	struct clk *clk;
+
+	clk = clk_get_sys(NULL, clk_name);
+	if (!IS_ERR(clk))
+		rc = clk_set_rate(clk, rate);
 
-	usb_dpll = clk_get_sys(NULL, "dpll_usb_m2_ck");
-	rc = clk_set_rate(usb_dpll, OMAP5_DPLL_USB_DEFFREQ/2);
 	if (rc)
-		pr_err("%s: failed to set USB_DPLL M2 OUT\n", __func__);
+		pr_err("%s: failed to configure %s!\n", __func__, clk_name);
+}
+
+int __init omap5xxx_dt_clk_init(void)
+{
+	ti_dt_clocks_register(omap54xx_clks);
+
+	omap2_clk_disable_autoidle_all();
+
+	omap5xxx_dt_clk_abe_dpll_init();
+	omap5xxx_dt_clk_usb_dpll_init("dpll_usb_ck", OMAP5_DPLL_USB_DEFFREQ);
+	omap5xxx_dt_clk_usb_dpll_init("dpll_usb_m2_ck", OMAP5_DPLL_USB_DEFFREQ/2);
 
 	return 0;
 }
-- 
1.9.1

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

* [RFT PATCH 8/8] clk: ti: clk-7xx: Prevent possible ERR_PTR dereference
  2015-05-13  6:54 [RFT PATCH 0/8] clk: ti: Fix possible ERR_PTR dereferences from clk_get_sys Krzysztof Kozlowski
                   ` (6 preceding siblings ...)
  2015-05-13  6:54 ` [RFT PATCH 7/8] clk: ti: clk-54xx: " Krzysztof Kozlowski
@ 2015-05-13  6:54 ` Krzysztof Kozlowski
  2015-05-13  7:07 ` [RFT PATCH 0/8] clk: ti: Fix possible ERR_PTR dereferences from clk_get_sys Tero Kristo
  8 siblings, 0 replies; 11+ messages in thread
From: Krzysztof Kozlowski @ 2015-05-13  6:54 UTC (permalink / raw)
  To: Tero Kristo, Mike Turquette, Stephen Boyd, linux-omap, linux-clk,
	linux-kernel
  Cc: Krzysztof Kozlowski

The return value of clk_get_sys() was immediately used in
clk_set_parent() and clk_set_rate(). The first one may return ERR_PTR
and the latter only checks if supplied argument is non-NULL.

Signed-off-by: Krzysztof Kozlowski <k.kozlowski@samsung.com>
---
 drivers/clk/ti/clk-7xx.c | 50 ++++++++++++++++++++++++++++--------------------
 1 file changed, 29 insertions(+), 21 deletions(-)

diff --git a/drivers/clk/ti/clk-7xx.c b/drivers/clk/ti/clk-7xx.c
index 5d2217ae4478..ce1a77092788 100644
--- a/drivers/clk/ti/clk-7xx.c
+++ b/drivers/clk/ti/clk-7xx.c
@@ -308,44 +308,52 @@ static struct ti_dt_clk dra7xx_clks[] = {
 	{ .node_name = NULL },
 };
 
-int __init dra7xx_dt_clk_init(void)
+static void __init dra7xx_dt_clk_abe_dpll_init(void)
 {
 	int rc;
 	struct clk *abe_dpll_mux, *sys_clkin2, *dpll_ck;
 
-	ti_dt_clocks_register(dra7xx_clks);
-
-	omap2_clk_disable_autoidle_all();
-
 	abe_dpll_mux = clk_get_sys(NULL, "abe_dpll_sys_clk_mux");
 	sys_clkin2 = clk_get_sys(NULL, "sys_clkin2");
 	dpll_ck = clk_get_sys(NULL, "dpll_abe_ck");
 
+	if (IS_ERR(abe_dpll_mux) || IS_ERR(sys_clkin2) || IS_ERR(dpll_ck)) {
+		pr_err("%s: failed to configure ABE DPLL!\n", __func__);
+		return;
+	}
+
 	rc = clk_set_parent(abe_dpll_mux, sys_clkin2);
 	if (!rc)
 		rc = clk_set_rate(dpll_ck, DRA7_DPLL_ABE_DEFFREQ);
 	if (rc)
 		pr_err("%s: failed to configure ABE DPLL!\n", __func__);
+}
 
-	dpll_ck = clk_get_sys(NULL, "dpll_abe_m2x2_ck");
-	rc = clk_set_rate(dpll_ck, DRA7_DPLL_ABE_DEFFREQ * 2);
-	if (rc)
-		pr_err("%s: failed to configure ABE DPLL m2x2!\n", __func__);
-
-	dpll_ck = clk_get_sys(NULL, "dpll_gmac_ck");
-	rc = clk_set_rate(dpll_ck, DRA7_DPLL_GMAC_DEFFREQ);
-	if (rc)
-		pr_err("%s: failed to configure GMAC DPLL!\n", __func__);
+static int __init dra7xx_dt_clk_dpll_init(const char *clk_name,
+				    unsigned long rate)
+{
+	int rc = -EINVAL;
+	struct clk *clk;
 
-	dpll_ck = clk_get_sys(NULL, "dpll_usb_ck");
-	rc = clk_set_rate(dpll_ck, DRA7_DPLL_USB_DEFFREQ);
-	if (rc)
-		pr_err("%s: failed to configure USB DPLL!\n", __func__);
+	clk = clk_get_sys(NULL, clk_name);
+	if (!IS_ERR(clk))
+		rc = clk_set_rate(clk, rate);
 
-	dpll_ck = clk_get_sys(NULL, "dpll_usb_m2_ck");
-	rc = clk_set_rate(dpll_ck, DRA7_DPLL_USB_DEFFREQ/2);
 	if (rc)
-		pr_err("%s: failed to set USB_DPLL M2 OUT\n", __func__);
+		pr_err("%s: failed to configure %s!\n", __func__, clk_name);
 
 	return rc;
 }
+
+int __init dra7xx_dt_clk_init(void)
+{
+	ti_dt_clocks_register(dra7xx_clks);
+
+	omap2_clk_disable_autoidle_all();
+
+	dra7xx_dt_clk_abe_dpll_init();
+	dra7xx_dt_clk_dpll_init("dpll_abe_m2x2_ck", DRA7_DPLL_ABE_DEFFREQ * 2);
+	dra7xx_dt_clk_dpll_init("dpll_gmac_ck", DRA7_DPLL_GMAC_DEFFREQ);
+	dra7xx_dt_clk_dpll_init("dpll_usb_ck", DRA7_DPLL_USB_DEFFREQ);
+	return dra7xx_dt_clk_dpll_init("dpll_usb_m2_ck", DRA7_DPLL_USB_DEFFREQ/2);
+}
-- 
1.9.1


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

* Re: [RFT PATCH 0/8] clk: ti: Fix possible ERR_PTR dereferences from clk_get_sys
  2015-05-13  6:54 [RFT PATCH 0/8] clk: ti: Fix possible ERR_PTR dereferences from clk_get_sys Krzysztof Kozlowski
                   ` (7 preceding siblings ...)
  2015-05-13  6:54 ` [RFT PATCH 8/8] clk: ti: clk-7xx: " Krzysztof Kozlowski
@ 2015-05-13  7:07 ` Tero Kristo
  8 siblings, 0 replies; 11+ messages in thread
From: Tero Kristo @ 2015-05-13  7:07 UTC (permalink / raw)
  To: Krzysztof Kozlowski, Mike Turquette, Stephen Boyd, linux-omap,
	linux-clk, linux-kernel

On 05/13/2015 09:54 AM, Krzysztof Kozlowski wrote:
> Hi,
>
>
> clk_get_sys() may return ERR_PTR but the drivers immediately
> dereferenced the return value. This could lead to oops.
>
> I tried only to fix possible ERR_PTR dereference and to not change
> the logic. This is why some of the patches look quite complex.
> For example in clk-7xx driver proceeds to next clocks if first one fails.
>
> WARNING:
> The patchset was only compile tested (plus static checkers), as
> I do not have the hardware. I am kindly asking for tests.
>
>
> Best regards,
> Krzysztof

Hi Krzysztof,

These should be rather fixed by using assigned-clock-parents / 
assigned-clock-rates DT properties and removing the offending legacy 
code from clk-* files. Patch #1 is good to go as is.

-Tero

>
>
> Krzysztof Kozlowski (8):
>    clk: ti: dra7-atl-clock: Fix possible ERR_PTR dereference
>    clk: ti: clk-2xxx: Prevent possible ERR_PTR dereference
>    clk: ti: clk-3xxx: Prevent possible ERR_PTR dereference
>    clk: ti: clk-33xx: Prevent possible ERR_PTR dereference
>    clk: ti: clk-43xx: Prevent possible ERR_PTR dereference
>    clk: ti: clk-43xx: Prevent possible ERR_PTR dereference
>    clk: ti: clk-54xx: Prevent possible ERR_PTR dereference
>    clk: ti: clk-7xx: Prevent possible ERR_PTR dereference
>
>   drivers/clk/ti/clk-2xxx.c     | 18 ++++++++++++----
>   drivers/clk/ti/clk-33xx.c     |  9 +++++---
>   drivers/clk/ti/clk-3xxx.c     | 18 ++++++++++++----
>   drivers/clk/ti/clk-43xx.c     |  3 ++-
>   drivers/clk/ti/clk-44xx.c     | 16 ++++++++++----
>   drivers/clk/ti/clk-54xx.c     | 47 +++++++++++++++++++++++++++-------------
>   drivers/clk/ti/clk-7xx.c      | 50 +++++++++++++++++++++++++------------------
>   drivers/clk/ti/clk-dra7-atl.c |  5 +++++
>   8 files changed, 114 insertions(+), 52 deletions(-)
>


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

* Re: [RFT PATCH 1/8] clk: ti: dra7-atl-clock: Fix possible ERR_PTR dereference
  2015-05-13  6:54 ` [RFT PATCH 1/8] clk: ti: dra7-atl-clock: Fix possible ERR_PTR dereference Krzysztof Kozlowski
@ 2015-05-14 22:31   ` Stephen Boyd
  0 siblings, 0 replies; 11+ messages in thread
From: Stephen Boyd @ 2015-05-14 22:31 UTC (permalink / raw)
  To: Krzysztof Kozlowski
  Cc: Tero Kristo, Mike Turquette, linux-omap, linux-clk, linux-kernel,
	stable

On 05/13, Krzysztof Kozlowski wrote:
> of_clk_get_from_provider() returns ERR_PTR on failure. The
> dra7-atl-clock driver was not checking its return value and immediately
> used it in __clk_get_hw().  __clk_get_hw() dereferences supplied clock,
> if it is not NULL, so in that case it would dereference an ERR_PTR.
> 
> Signed-off-by: Krzysztof Kozlowski <k.kozlowski@samsung.com>
> Cc: <stable@vger.kernel.org>
> Fixes: 9ac33b0ce81f ("CLK: TI: Driver for DRA7 ATL (Audio Tracking Logic)")
> ---

Applied to clk-next

-- 
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum,
a Linux Foundation Collaborative Project

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

end of thread, other threads:[~2015-05-14 22:31 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-05-13  6:54 [RFT PATCH 0/8] clk: ti: Fix possible ERR_PTR dereferences from clk_get_sys Krzysztof Kozlowski
2015-05-13  6:54 ` [RFT PATCH 1/8] clk: ti: dra7-atl-clock: Fix possible ERR_PTR dereference Krzysztof Kozlowski
2015-05-14 22:31   ` Stephen Boyd
2015-05-13  6:54 ` [RFT PATCH 2/8] clk: ti: clk-2xxx: Prevent " Krzysztof Kozlowski
2015-05-13  6:54 ` [RFT PATCH 3/8] clk: ti: clk-3xxx: " Krzysztof Kozlowski
2015-05-13  6:54 ` [RFT PATCH 4/8] clk: ti: clk-33xx: " Krzysztof Kozlowski
2015-05-13  6:54 ` [RFT PATCH 5/8] clk: ti: clk-43xx: " Krzysztof Kozlowski
2015-05-13  6:54 ` [RFT PATCH 6/8] " Krzysztof Kozlowski
2015-05-13  6:54 ` [RFT PATCH 7/8] clk: ti: clk-54xx: " Krzysztof Kozlowski
2015-05-13  6:54 ` [RFT PATCH 8/8] clk: ti: clk-7xx: " Krzysztof Kozlowski
2015-05-13  7:07 ` [RFT PATCH 0/8] clk: ti: Fix possible ERR_PTR dereferences from clk_get_sys Tero Kristo

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).