OSDN Git Service

clk: msm: clock-debug: acquire prepare lock during measurement
authorOsvaldo Banuelos <osvaldob@codeaurora.org>
Thu, 12 Jan 2017 01:30:03 +0000 (17:30 -0800)
committerOsvaldo Banuelos <osvaldob@codeaurora.org>
Fri, 20 Jan 2017 18:45:29 +0000 (10:45 -0800)
If the rate of the clock being measured changes at the same
time clock_debug_measure_get() is called, there can be a
miscalculation of the value of the divider between the
measurement circuitry and clock output. Acquiring the prepare
lock fixes the race since it prevents clock rate changes during
measurement.

CRs-Fixed: 1109789
Change-Id: I51050379a45a51c22109a06bc4758d767f361da1
Signed-off-by: Osvaldo Banuelos <osvaldob@codeaurora.org>
drivers/clk/msm/clock-debug.c

index 00a86ba..0fe93ed 100644 (file)
@@ -1,6 +1,7 @@
 /*
  * Copyright (C) 2007 Google, Inc.
- * Copyright (c) 2007-2014, 2016, The Linux Foundation. All rights reserved.
+ * Copyright (c) 2007-2014, 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
@@ -77,6 +78,7 @@ static int clock_debug_measure_get(void *data, u64 *val)
        else
                is_hw_gated = 0;
 
+       mutex_lock(&clock->prepare_lock);
        ret = clk_set_parent(measure, clock);
        if (!ret) {
                /*
@@ -107,6 +109,7 @@ static int clock_debug_measure_get(void *data, u64 *val)
         */
        meas_rate = clk_get_rate(clock);
        sw_rate = clk_get_rate(measure->parent);
+       mutex_unlock(&clock->prepare_lock);
        if (sw_rate && meas_rate >= (sw_rate * 2))
                *val *= DIV_ROUND_CLOSEST(meas_rate, sw_rate);