[RFT PATCH 2/8] clk: ti: clk-2xxx: Prevent possible ERR_PTR dereference

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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

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




[Index of Archives]     [Linux Arm (vger)]     [ARM Kernel]     [ARM MSM]     [Linux Tegra]     [Linux WPAN Networking]     [Linux Wireless Networking]     [Maemo Users]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite Trails]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux