diff mbox

[RFT,6/8] clk: ti: clk-43xx: Prevent possible ERR_PTR dereference

Message ID 1431500087-2275-7-git-send-email-k.kozlowski@samsung.com (mailing list archive)
State New, archived
Headers show

Commit Message

Krzysztof Kozlowski May 13, 2015, 6:54 a.m. UTC
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 mbox

Patch

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__);