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

From: Krzysztof Kozlowski
Date: Wed May 13 2015 - 02:56:47 EST


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@xxxxxxxxxxx>
---
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

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/