From 807c806fa80be8d0ebd95fc46bba04ac1583348c Mon Sep 17 00:00:00 2001 From: Taniya Das Date: Mon, 23 Jan 2017 17:03:08 +0530 Subject: [PATCH] clk: qcom: Fix uninitialized variable and null pointer exception Initialize the variables before their usage and add null pointer checks before dereferencing pointers. Change-Id: Ibe4140c6e0aa25c37583e6e5e6e2331d86f389aa Signed-off-by: Taniya Das --- drivers/clk/qcom/clk-branch.c | 4 +++- drivers/clk/qcom/clk-cpu-osm.c | 21 +++++++++++++++------ 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/drivers/clk/qcom/clk-branch.c b/drivers/clk/qcom/clk-branch.c index 096e16db02fe..bfaf4482d668 100644 --- a/drivers/clk/qcom/clk-branch.c +++ b/drivers/clk/qcom/clk-branch.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013, 2016, The Linux Foundation. All rights reserved. + * Copyright (c) 2013, 2016-2017, The Linux Foundation. All rights reserved. * * This software is licensed under the terms of the GNU General Public * License version 2, as published by the Free Software Foundation, and @@ -275,6 +275,8 @@ static int clk_branch2_hw_ctl_determine_rate(struct clk_hw *hw, struct clk_hw *clkp; clkp = __clk_get_hw(clk_get_parent(hw->clk)); + if (!clkp) + return -EINVAL; req->best_parent_hw = clkp; req->best_parent_rate = clk_round_rate(clkp->clk, req->rate); diff --git a/drivers/clk/qcom/clk-cpu-osm.c b/drivers/clk/qcom/clk-cpu-osm.c index 5ed0dba189f7..6d13adf7a6ee 100644 --- a/drivers/clk/qcom/clk-cpu-osm.c +++ b/drivers/clk/qcom/clk-cpu-osm.c @@ -1512,7 +1512,7 @@ static int clk_osm_setup_hw_table(struct clk_osm *c) { struct osm_entry *entry = c->osm_table; int i; - u32 freq_val, volt_val, override_val, spare_val; + u32 freq_val = 0, volt_val = 0, override_val = 0, spare_val = 0; u32 table_entry_offset, last_spare, last_virtual_corner = 0; for (i = 0; i < OSM_TABLE_SIZE; i++) { @@ -2472,14 +2472,19 @@ static u64 clk_osm_get_cpu_cycle_counter(int cpu) static void populate_opp_table(struct platform_device *pdev) { int cpu; + struct device *cpu_dev; for_each_possible_cpu(cpu) { if (logical_cpu_to_clk(cpu) == pwrcl_clk.hw.clk) { - WARN(add_opp(&pwrcl_clk, get_cpu_device(cpu)), + cpu_dev = get_cpu_device(cpu); + if (cpu_dev) + WARN(add_opp(&pwrcl_clk, cpu_dev), "Failed to add OPP levels for power cluster\n"); } if (logical_cpu_to_clk(cpu) == perfcl_clk.hw.clk) { - WARN(add_opp(&perfcl_clk, get_cpu_device(cpu)), + cpu_dev = get_cpu_device(cpu); + if (cpu_dev) + WARN(add_opp(&perfcl_clk, cpu_dev), "Failed to add OPP levels for perf cluster\n"); } } @@ -2543,7 +2548,7 @@ static ssize_t debugfs_trace_method_set(struct file *file, const char __user *buf, size_t count, loff_t *ppos) { - struct clk_osm *c = file->private_data; + struct clk_osm *c; u32 val; if (IS_ERR(file) || file == NULL) { @@ -2551,6 +2556,8 @@ static ssize_t debugfs_trace_method_set(struct file *file, return -EINVAL; } + c = file->private_data; + if (!c) { pr_err("invalid clk_osm handle\n"); return -EINVAL; @@ -2593,7 +2600,7 @@ static ssize_t debugfs_trace_method_set(struct file *file, static ssize_t debugfs_trace_method_get(struct file *file, char __user *buf, size_t count, loff_t *ppos) { - struct clk_osm *c = file->private_data; + struct clk_osm *c; int len, rc; if (IS_ERR(file) || file == NULL) { @@ -2601,6 +2608,8 @@ static ssize_t debugfs_trace_method_get(struct file *file, char __user *buf, return -EINVAL; } + c = file->private_data; + if (!c) { pr_err("invalid clk_osm handle\n"); return -EINVAL; @@ -3023,7 +3032,7 @@ static unsigned long perfcl_boot_rate = 1747200000; static int clk_cpu_osm_driver_probe(struct platform_device *pdev) { - int rc, cpu, i; + int rc = 0, cpu, i; int speedbin = 0, pvs_ver = 0; u32 pte_efuse; int num_clks = ARRAY_SIZE(osm_qcom_clk_hws);