]> rtime.felk.cvut.cz Git - zynq/linux.git/commitdiff
clk: Properly handle notifier return values
authorSoren Brinkmann <soren.brinkmann@xilinx.com>
Wed, 3 Apr 2013 19:17:12 +0000 (12:17 -0700)
committerSoren Brinkmann <soren.brinkmann@xilinx.com>
Thu, 30 May 2013 18:30:52 +0000 (11:30 -0700)
Notifiers may return NOTIFY_(OK|DONE|STOP|BAD). The CCF uses an
inconsistent mix of checking against NOTIFY_STOP or NOTIFY_BAD.
This inconsistency leaves errors undetected in some cases:
clk_set_parent() calls __clk_speculate_rates(), which stops when it
hits a NOTIFIER_BAD (STOP is ignored), and passes this value back to the
caller.
clk_set_parent() compares this return value against NOTIFY_STOP only,
ignoring NOTIFY_BAD returns.

Use NOTIFY_STOP_MASK to detect a negative notifier return value and
document all four return value options.

Signed-off-by: Soren Brinkmann <soren.brinkmann@xilinx.com>
Signed-off-by: Mike Turquette <mturquette@linaro.org>
(cherry picked from commit fb72a0590b770f7da6a02bde6b8a147a3d9f6168)

drivers/clk/clk.c
include/linux/clk.h

index 251e45d6024d26b188d1e81195318fcb82cdc502..b9bb6efb083a9e07c1ddc2ad8ec6e9cd6c8b0369 100644 (file)
@@ -744,16 +744,16 @@ static int __clk_speculate_rates(struct clk *clk, unsigned long parent_rate)
        else
                new_rate = parent_rate;
 
-       /* abort the rate change if a driver returns NOTIFY_BAD */
+       /* abort rate change if a driver returns NOTIFY_BAD or NOTIFY_STOP */
        if (clk->notifier_count)
                ret = __clk_notify(clk, PRE_RATE_CHANGE, clk->rate, new_rate);
 
-       if (ret == NOTIFY_BAD)
+       if (ret & NOTIFY_STOP_MASK)
                goto out;
 
        hlist_for_each_entry(child, tmp, &clk->children, child_node) {
                ret = __clk_speculate_rates(child, new_rate);
-               if (ret == NOTIFY_BAD)
+               if (ret & NOTIFY_STOP_MASK)
                        break;
        }
 
@@ -848,7 +848,7 @@ static struct clk *clk_propagate_rate_change(struct clk *clk, unsigned long even
 
        if (clk->notifier_count) {
                ret = __clk_notify(clk, event, clk->rate, clk->new_rate);
-               if (ret == NOTIFY_BAD)
+               if (ret & NOTIFY_STOP_MASK)
                        fail_clk = clk;
        }
 
@@ -1170,7 +1170,7 @@ int clk_set_parent(struct clk *clk, struct clk *parent)
                ret = __clk_speculate_rates(clk, parent->rate);
 
        /* abort if a driver objects */
-       if (ret == NOTIFY_STOP)
+       if (ret & NOTIFY_STOP_MASK)
                goto out;
 
        /* only re-parent if the clock is not in use */
index b3ac22d0fc1fdc4be337e32e7991c5b0b45d9541..9a6d04524b1a3f85fd01a4783bb21fbaca6bd3c1 100644 (file)
@@ -28,16 +28,16 @@ struct clk;
  * PRE_RATE_CHANGE - called immediately before the clk rate is changed,
  *     to indicate that the rate change will proceed.  Drivers must
  *     immediately terminate any operations that will be affected by the
- *     rate change.  Callbacks may either return NOTIFY_DONE or
- *     NOTIFY_STOP.
+ *     rate change.  Callbacks may either return NOTIFY_DONE, NOTIFY_OK,
+ *     NOTIFY_STOP or NOTIFY_BAD.
  *
  * ABORT_RATE_CHANGE: called if the rate change failed for some reason
  *     after PRE_RATE_CHANGE.  In this case, all registered notifiers on
  *     the clk will be called with ABORT_RATE_CHANGE. Callbacks must
- *     always return NOTIFY_DONE.
+ *     always return NOTIFY_DONE or NOTIFY_OK.
  *
  * POST_RATE_CHANGE - called after the clk rate change has successfully
- *     completed.  Callbacks must always return NOTIFY_DONE.
+ *     completed.  Callbacks must always return NOTIFY_DONE or NOTIFY_OK.
  *
  */
 #define PRE_RATE_CHANGE                        BIT(0)