1. 15 12月, 2013 1 次提交
    • S
      clk: Fix debugfs reparenting NULL pointer dereference · 3a5aec24
      Stephen Boyd 提交于
      Adding clocks from a kernel module can cause a NULL pointer
      dereference if the parent of a clock is added after the clock is
      added. This happens because __clk_init() iterates over the list
      of orphans and reparents the orphans to the clock being
      registered before creating the debugfs entry for the clock.
      Create the debugfs entry first before reparenting the orphans.
      
      Unable to handle kernel NULL pointer dereference at virtual address 00000028
      pgd = ef3e4000
      [00000028] *pgd=bf810831
      Internal error: Oops: 17 [#1] PREEMPT SMP ARM
      Modules linked in: mmcc_8960(+)
      CPU: 0 PID: 52 Comm: modprobe Not tainted 3.12.0-rc2-00023-g1021a28-dirty #659
      task: ef319200 ti: ef3a6000 task.ti: ef3a6000
      PC is at lock_rename+0x24/0xc4
      LR is at debugfs_rename+0x34/0x208
      pc : [<c0317238>]    lr : [<c047dfe4>]    psr: 00000013
      sp : ef3a7b88  ip : ef3a7ba8  fp : ef3a7ba4
      r10: ef3d51cc  r9 : ef3bc680  r8 : ef3d5210
      r7 : ef3bc640  r6 : eee287e0  r5 : eee287e0  r4 : 00000000
      r3 : ef3bc640  r2 : 00000000  r1 : eee287e0  r0 : 00000000
      Flags: nzcv  IRQs on  FIQs on  Mode SVC_32  ISA ARM  Segment user
      Control: 10c5787d  Table: af3e406a  DAC: 00000015
      Process modprobe (pid: 52, stack limit = 0xef3a6240)
      Stack: (0xef3a7b88 to 0xef3a8000)
      7b80:                   ef3bc640 ee4047e0 00000000 eee287e0 ef3a7bec ef3a7ba8
      7ba0: c047dfe4 c0317220 ef3bc680 ef3d51cc ef3a7bdc ef3a7bc0 c06e29d0 c0268784
      7bc0: c08946e8 ef3d5210 00000000 ef3bc700 ef3d5290 ef3d5210 ef3bc680 ef3d51cc
      7be0: ef3a7c0c ef3a7bf0 c05b9e9c c047dfbc 00000000 00000000 ef3d5210 ef3d5290
      7c00: ef3a7c24 ef3a7c10 c05baebc c05b9e30 00000001 00000001 ef3a7c64 ef3a7c28
      7c20: c05bb124 c05bae9c bf000cd8 ef3bc7c0 000000d0 c0ff129c bf001774 00000002
      7c40: ef3bc740 ef3d5290 ef0f9a10 bf001774 bf00042c 00000061 ef3a7c8c ef3a7c68
      7c60: c05bb480 c05baed8 bf001774 ef3d5290 ef0f9a10 bf001774 ef38bc10 ef0f9a00
      7c80: ef3a7cac ef3a7c90 c05bb5a8 c05bb3a0 bf001774 00000062 ef0f9a10 ef38bc18
      7ca0: ef3a7cec ef3a7cb0 bf00010c c05bb56c 00000000 ef38ba00 00000000 ef3d60d0
      7cc0: ef3a7cdc c0fefc24 ef0f9a10 c0a091c0 bf000d24 00000000 bf0029f0 bf006000
      7ce0: ef3a7cfc ef3a7cf0 c05156c0 bf000040 ef3a7d2c ef3a7d00 c0513f5c c05156a8
      7d00: ef3a7d2c ef0f9a10 ef0f9a10 bf000d24 ef0f9a44 c09ca588 00000000 bf006000
      7d20: ef3a7d4c ef3a7d30 c05142b8 c0513ecc ef0fd25c 00000000 bf000d24 c0514214
      7d40: ef3a7d74 ef3a7d50 c0512030 c0514220 ef0050a8 ef0fd250 ef0050f8 bf000d24
      7d60: ef37c100 c09ed150 ef3a7d84 ef3a7d78 c05139c8 c0511fd8 ef3a7
      7d80: c051344c c05139a8 bf000864 c09ca588 ef3a7db4 bf000d24 bf002
      7da0: c09ca588 00000000 ef3a7dcc ef3a7db8 c05149dc c0513360 ef3a7
      7dc0: ef3a7ddc ef3a7dd0 c0515914 c0514960 ef3a7dec ef3a7de0 bf006
      7de0: ef3a7e74 ef3a7df0 c0208800 bf00600c ef3a7e1c ef3a7e00 c04c5
      7e00: ffffffff c09d46c4 00000000 bf0029a8 ef3a7e34 ef3a7e20 c024c
      7e20: ffffffff c09d46c4 ef3a7e5c ef3a7e38 c024e2fc c024ce40 00000
      7e40: ef3a7f48 bf0029b4 bf0029a8 271aeb1c ef3a7f48 bf0029a8 00000001 ef383c00
      7e60: bf0029f0 00000001 ef3a7f3c ef3a7e78 c028fac4 c0208718 bf0029b4 00007fff
      7e80: c028cd58 000000d2 f0065000 00000000 ef3a7ebc 00000000 00000000 bf0029b4
      7ea0: 00000000 bf0029ac bf0029b4 ef3a6000 ef3a7efc c08bf128 00000000 00000000
      7ec0: 00000000 00000000 00000000 00000000 6e72656b 00006c65 00000000 00000000
      7ee0: 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
      7f00: 00000000 00000000 00000000 271aeb1c ef3a7f2c 00016376 b6f38008 001d3774
      7f20: 00000080 c020f968 ef3a6000 00000000 ef3a7fa4 ef3a7f40 c02904dc c028e178
      7f40: c020f898 010ccfa8 f0065000 00016376 f0073f60 f0073d7d f007a1e8 00002b24
      7f60: 000039e4 00000000 00000000 00000000 0000002f 00000030 00000019 00000016
      7f80: 00000012 00000000 00000000 010de1b2 b6f38008 010ccfa8 00000000 ef3a7fa8
      7fa0: c020f6c0 c0290434 010de1b2 b6f38008 b6f38008 00016376 001d3774 00000000
      7fc0: 010de1b2 b6f38008 010ccfa8 00000080 010de1b2 bedb6f90 010de1c9 0001d8dc
      7fe0: 0000000c bedb674c 0001ce30 000094c4 60000010 b6f38008 00000008 0000001d
      [<c0317238>] (lock_rename+0x24/0xc4) from [<c047dfe4>] (debugfs_rename+0x34/0x208)
      [<c047dfe4>] (debugfs_rename+0x34/0x208) from [<c05b9e9c>] (clk_debug_reparent+0x78/0xc0)
      [<c05baebc>] (__clk_reparent+0x2c/0x3c) from [<c05bb124>] (__clk_init+0x258/0x4c8)
      [<c05bb124>] (__clk_init+0x258/0x4c8) from [<c05bb480>] (_clk_register+0xec/0x1cc)
      [<c05bb480>] (_clk_register+0xec/0x1cc) from [<c05bb5a8>] (devm_clk_register+0x48/0x7c)
      [<c05bb5a8>] (devm_clk_register+0x48/0x7c) from [<bf00010c>] (msm_mmcc_8960_probe+0xd8/0x190 [mmcc_8960])
      [<bf00010c>] (msm_mmcc_8960_probe+0xd8/0x190 [mmcc_8960]) from [<c05156c0>] (platform_drv_probe+0x24/0x28)
      [<c05156c0>] (platform_drv_probe+0x24/0x28) from [<c0513f5c>] (driver_probe_device+0x9c/0x354)
      [<c0513f5c>] (driver_probe_device+0x9c/0x354) from [<c05142b8>] (__driver_attach+0xa4/0xa8)
      [<c05142b8>] (__driver_attach+0xa4/0xa8) from [<c0512030>] (bus_for_each_dev+0x64/0x98)
      [<c0512030>] (bus_for_each_dev+0x64/0x98) from [<c05139c8>] (driver_attach+0x2c/0x30)
      [<c05139c8>] (driver_attach+0x2c/0x30) from [<c051344c>] (bus_add_driver+0xf8/0x2a8)
      [<c051344c>] (bus_add_driver+0xf8/0x2a8) from [<c05149dc>] (driver_register+0x88/0x104)
      [<c05149dc>] (driver_register+0x88/0x104) from [<c0515914>] (__platform_driver_register+0x58/0x6c)
      [<c0515914>] (__platform_driver_register+0x58/0x6c) from [<bf006018>] (msm_mmcc_8960_driver_init+0x18/0x24 [mmcc_8960])
      [<bf006018>] (msm_mmcc_8960_driver_init+0x18/0x24 [mmcc_8960]) from [<c0208800>] (do_one_initcall+0xf4/0x1b8)
      [<c0208800>] (do_one_initcall+0xf4/0x1b8) from [<c028fac4>] (load_module+0x1958/0x22bc)
      [<c028fac4>] (load_module+0x1958/0x22bc) from [<c02904dc>] (SyS_init_module+0xb4/0x120)
      [<c02904dc>] (SyS_init_module+0xb4/0x120) from [<c020f6c0>] (ret_fast_syscall+0x0/0x48)
      Code: e1500001 e1a04000 e1a05001 0a000021 (e5903028)
      Signed-off-by: NStephen Boyd <sboyd@codeaurora.org>
      Signed-off-by: NMike Turquette <mturquette@linaro.org>
      3a5aec24
  2. 28 11月, 2013 1 次提交
    • A
      clk: clean up everything on debugfs error · b5f98e65
      Alex Elder 提交于
      [Maybe the third time will be the charm. -Alex]
      
      If CONFIG_COMMON_CLK_DEBUG is defined, clk_debug_create_one() is
      called to populate a debugfs directory with a few entries that are
      common for all clock types.
      
      If an error happens after creating the first one debugfs_remove() is
      called on the clock's directory.  The problem with this is that no
      cleanup is done on the debugfs files already created in that
      directory, so the directory never actually gets removed.   This
      problem is silently ignored.
      
      Fix this by calling debugfs_remove_recursive() instead.  Reset the
      clk->dentry field to null afterward, to ensure it can't be mistaken
      as a valid pointer.
      Signed-off-by: NAlex Elder <elder@linaro.org>
      Signed-off-by: NMike Turquette <mturquette@linaro.org>
      b5f98e65
  3. 08 10月, 2013 1 次提交
  4. 02 10月, 2013 3 次提交
    • T
      clk: Correct lookup logic in clk_fetch_parent_index() · da0f0b2c
      Tomasz Figa 提交于
      This function is supposed to iterate over all parents of given child
      clock to find the index of given parent clock in its parent list,
      using parent cache if possible and falling back to string compare
      otherwise. However currently the logic falls back to string compare in
      every iteration in which clock cache entry does not match given parent,
      due to wrong check conditions.
      
      This patch corrects the logic to continue the loop if parent cache entry
      is present and does not match requested parent clock. In addition,
      redundant checks for parent cache array presence are removed, because it
      is always allocated in the beginning of the function.
      Signed-off-by: NTomasz Figa <tomasz.figa@gmail.com>
      Signed-off-by: NMike Turquette <mturquette@linaro.org>
      da0f0b2c
    • T
      clk: Use kcalloc() to allocate arrays · 96a7ed90
      Tomasz Figa 提交于
      Instead of calculating sizes of arrays manually, kcalloc() can be used
      to allocate arrays of elements with defined size. This is just a cleanup
      patch without any functional changes.
      Signed-off-by: NTomasz Figa <tomasz.figa@gmail.com>
      Signed-off-by: NMike Turquette <mturquette@linaro.org>
      96a7ed90
    • T
      clk: Add error handling to clk_fetch_parent_index() · f1c8b2ed
      Tomasz Figa 提交于
      There are at least two different error cases that can happen in
      clk_fetch_parent_index() function:
       - allocation failure,
       - parent clock lookup failure,
      however it returns only an u8, which is supposed to contain parent clock
      index.
      
      This patch modified the function to return full int instead allowing
      positive clock indices and negative error codes to be returned. All
      users of this function are adjusted as well to handle the return value
      correctly.
      Signed-off-by: NTomasz Figa <tomasz.figa@gmail.com>
      Signed-off-by: NMike Turquette <mturquette@linaro.org>
      f1c8b2ed
  5. 10 9月, 2013 1 次提交
    • A
      clk: only call get_parent if there is one · 12d29886
      Alex Elder 提交于
      In __clk_init(), after a clock is mostly initialized, a scan is done
      of the orphan clocks to see if the clock being registered is the
      parent of any of them.
      
      This code assumes that any clock that provides a get_parent method
      actually has at least one parent, and that's not a valid assumption.
      
      As a result, an orphan clock with no parent can return *something*
      as the parent index, and that value is blindly used to dereference
      the orphan's parent_names[] array (which will be ZERO_SIZE_PTR or
      NULL).
      
      Fix this by ensuring get_parent is only called for orphans with at
      least one parent.
      Signed-off-by: NAlex Elder <elder@linaro.org>
      Signed-off-by: NMike Turquette <mturquette@linaro.org>
      12d29886
  6. 04 9月, 2013 1 次提交
  7. 31 8月, 2013 1 次提交
  8. 28 8月, 2013 1 次提交
  9. 22 8月, 2013 1 次提交
    • M
      clk: handle NULL struct clk gracefully · 89ac8d7a
      Mike Turquette 提交于
      At some point changes to clk_set_rate and clk_set_parent introduced a
      bug whereby NULL struct clk pointers were treated as an error. This is
      in violation of the API in include/linux/clk.h. Reintroduce graceful
      handling of NULL clk's by bailing from clk_set_rate and clk_set_parent
      with return codes of zero.
      Signed-off-by: NMike Turquette <mturquette@linaro.org>
      89ac8d7a
  10. 20 8月, 2013 4 次提交
    • J
      clk: clk-mux: implement remuxing on set_rate · e366fdd7
      James Hogan 提交于
      Implement clk-mux remuxing if the CLK_SET_RATE_NO_REPARENT flag isn't
      set. This implements determine_rate for clk-mux to propagate to each
      parent and to choose the best one (like clk-divider this chooses the
      parent which provides the fastest rate <= the requested rate).
      
      The determine_rate op is implemented as a core helper function so that
      it can be easily used by more complex clocks which incorporate muxes.
      Signed-off-by: NJames Hogan <james.hogan@imgtec.com>
      Reviewed-by: NStephen Boyd <sboyd@codeaurora.org>
      Cc: Mike Turquette <mturquette@linaro.org>
      Cc: linux-arm-kernel@lists.infradead.org
      Signed-off-by: NMike Turquette <mturquette@linaro.org>
      e366fdd7
    • J
      clk: add support for clock reparent on set_rate · 71472c0c
      James Hogan 提交于
      Add core support to allow clock implementations to select the best
      parent clock when rounding a rate, e.g. the one which can provide the
      closest clock rate to that requested. This is by way of adding a new
      clock op, determine_rate(), which is like round_rate() but has an extra
      parameter to allow the clock implementation to optionally select a
      different parent clock. The core then takes care of reparenting the
      clock when setting the rate.
      
      The parent change takes place with the help of some new private data
      members. struct clk::new_parent specifies a clock's new parent (NULL
      indicates no change), and struct clk::new_child specifies a clock's new
      child (whose new_parent member points back to it). The purpose of these
      are to allow correct walking of the future tree for notifications prior
      to actually reparenting any clocks, specifically to skip child clocks
      who are being reparented to another clock (they will be notified via the
      new parent), and to include any new child clock. These pointers are set
      by clk_calc_subtree(), and the new_child pointer gets cleared when a
      child is actually reparented to avoid duplicate POST_RATE_CHANGE
      notifications.
      
      Each place where round_rate() is called, determine_rate() is checked
      first and called in preference. This restructures a few of the call
      sites to simplify the logic into if/else blocks.
      Signed-off-by: NJames Hogan <james.hogan@imgtec.com>
      Reviewed-by: NStephen Boyd <sboyd@codeaurora.org>
      Cc: Mike Turquette <mturquette@linaro.org>
      Cc: linux-arm-kernel@lists.infradead.org
      Signed-off-by: NMike Turquette <mturquette@linaro.org>
      71472c0c
    • J
      clk: move some parent related functions upwards · 4935b22c
      James Hogan 提交于
      Move some parent related functions up in clk.c so they can be used by
      the modifications in the following patch which enables clock reparenting
      during set_rate. No other changes are made so this patch makes no
      functional difference in isolation. This is separate from the following
      patch primarily to ease readability of that patch.
      Signed-off-by: NJames Hogan <james.hogan@imgtec.com>
      Reviewed-by: NStephen Boyd <sboyd@codeaurora.org>
      Cc: Mike Turquette <mturquette@linaro.org>
      Cc: linux-arm-kernel@lists.infradead.org
      Signed-off-by: NMike Turquette <mturquette@linaro.org>
      4935b22c
    • J
      clk: abstract parent cache · 7ef3dcc8
      James Hogan 提交于
      Abstract access to the clock parent cache by defining
      clk_get_parent_by_index(clk, index). This allows access to parent
      clocks from clock drivers.
      Signed-off-by: NJames Hogan <james.hogan@imgtec.com>
      Reviewed-by: NStephen Boyd <sboyd@codeaurora.org>
      Cc: Mike Turquette <mturquette@linaro.org>
      Cc: linux-arm-kernel@lists.infradead.org
      Signed-off-by: NMike Turquette <mturquette@linaro.org>
      7ef3dcc8
  11. 26 7月, 2013 1 次提交
  12. 16 6月, 2013 1 次提交
    • S
      clk: Always notify whole subtree when reparenting · f3aab5d6
      Soren Brinkmann 提交于
      A clock's notifier count only reflects notifiers which are registered
      directly for that clock. A reparent operation though affects the whole
      subtree because of a potential rate change.
      When issuing the pre rate change notifications only the notifier count
      for the clock to be changed is considered and notifiers for subclocks
      may never be called. Resulting in clocks in the subtree which have
      registered notifiers, may receive a POST_- or ABORT_RATE_CHANGE
      notification, without a PRE_RATE_CHANGE_NOTIFICATION.
      Therefore always traverse the whole subtree when issueing pre rate
      change notifications during a reparent operation.
      Signed-off-by: NSoren Brinkmann <soren.brinkmann@xilinx.com>
      Signed-off-by: NMike Turquette <mturquette@linaro.org>
      f3aab5d6
  13. 12 6月, 2013 2 次提交
  14. 07 6月, 2013 1 次提交
    • L
      clk: remove notifier from list before freeing it · 72b5322f
      Lai Jiangshan 提交于
      The @cn is stay in @clk_notifier_list after it is freed, it cause
      memory corruption.
      
      Example, if @clk is registered(first), unregistered(first),
      registered(second), unregistered(second).
      
      The freed @cn will be used when @clk is registered(second),
      and the bug will be happened when @clk is unregistered(second):
      
      [  517.040000] clk_notif_dbg clk_notif_dbg.1: clk_notifier_unregister()
      [  517.040000] Unable to handle kernel paging request at virtual address 00df3008
      [  517.050000] pgd = ed858000
      [  517.050000] [00df3008] *pgd=00000000
      [  517.060000] Internal error: Oops: 5 [#1] PREEMPT SMP ARM
      [  517.060000] Modules linked in: clk_notif_dbg(O-) [last unloaded: clk_notif_dbg]
      [  517.060000] CPU: 1 PID: 499 Comm: modprobe Tainted: G           O 3.10.0-rc3-00119-ga93cb29a-dirty #85
      [  517.060000] task: ee1e0180 ti: ee3e6000 task.ti: ee3e6000
      [  517.060000] PC is at srcu_readers_seq_idx+0x48/0x84
      [  517.060000] LR is at srcu_readers_seq_idx+0x60/0x84
      [  517.060000] pc : [<c0052720>]    lr : [<c0052738>]    psr: 80070013
      [  517.060000] sp : ee3e7d48  ip : 00000000  fp : ee3e7d6c
      [  517.060000] r10: 00000000  r9 : ee3e6000  r8 : 00000000
      [  517.060000] r7 : ed84fe4c  r6 : c068ec90  r5 : c068e430  r4 : 00000000
      [  517.060000] r3 : 00df3000  r2 : 00000000  r1 : 00000002  r0 : 00000000
      [  517.060000] Flags: Nzcv  IRQs on  FIQs on  Mode SVC_32  ISA ARM  Segment user
      [  517.060000] Control: 18c5387d  Table: 2d85804a  DAC: 00000015
      [  517.060000] Process modprobe (pid: 499, stack limit = 0xee3e6238)
      [  517.060000] Stack: (0xee3e7d48 to 0xee3e8000)
      ....
      [  517.060000] [<c0052720>] (srcu_readers_seq_idx+0x48/0x84) from [<c0052790>] (try_check_zero+0x34/0xfc)
      [  517.060000] [<c0052790>] (try_check_zero+0x34/0xfc) from [<c00528b0>] (srcu_advance_batches+0x58/0x114)
      [  517.060000] [<c00528b0>] (srcu_advance_batches+0x58/0x114) from [<c0052c30>] (__synchronize_srcu+0x114/0x1ac)
      [  517.060000] [<c0052c30>] (__synchronize_srcu+0x114/0x1ac) from [<c0052d14>] (synchronize_srcu+0x2c/0x34)
      [  517.060000] [<c0052d14>] (synchronize_srcu+0x2c/0x34) from [<c0053a08>] (srcu_notifier_chain_unregister+0x68/0x74)
      [  517.060000] [<c0053a08>] (srcu_notifier_chain_unregister+0x68/0x74) from [<c0375a78>] (clk_notifier_unregister+0x7c/0xc0)
      [  517.060000] [<c0375a78>] (clk_notifier_unregister+0x7c/0xc0) from [<bf008034>] (clk_notif_dbg_remove+0x34/0x9c [clk_notif_dbg])
      [  517.060000] [<bf008034>] (clk_notif_dbg_remove+0x34/0x9c [clk_notif_dbg]) from [<c02bb974>] (platform_drv_remove+0x24/0x28)
      [  517.060000] [<c02bb974>] (platform_drv_remove+0x24/0x28) from [<c02b9bf8>] (__device_release_driver+0x8c/0xd4)
      [  517.060000] [<c02b9bf8>] (__device_release_driver+0x8c/0xd4) from [<c02ba680>] (driver_detach+0x9c/0xc4)
      [  517.060000] [<c02ba680>] (driver_detach+0x9c/0xc4) from [<c02b99c4>] (bus_remove_driver+0xcc/0xfc)
      [  517.060000] [<c02b99c4>] (bus_remove_driver+0xcc/0xfc) from [<c02bace4>] (driver_unregister+0x54/0x78)
      [  517.060000] [<c02bace4>] (driver_unregister+0x54/0x78) from [<c02bbb44>] (platform_driver_unregister+0x1c/0x20)
      [  517.060000] [<c02bbb44>] (platform_driver_unregister+0x1c/0x20) from [<bf0081f8>] (clk_notif_dbg_driver_exit+0x14/0x1c [clk_notif_dbg])
      [  517.060000] [<bf0081f8>] (clk_notif_dbg_driver_exit+0x14/0x1c [clk_notif_dbg]) from [<c00835e4>] (SyS_delete_module+0x200/0x28c)
      [  517.060000] [<c00835e4>] (SyS_delete_module+0x200/0x28c) from [<c000edc0>] (ret_fast_syscall+0x0/0x48)
      [  517.060000] Code: e5973004 e7911102 e0833001 e2881002 (e7933101)
      
      Cc: stable@kernel.org
      Reported-by: NSören Brinkmann <soren.brinkmann@xilinx.com>
      Signed-off-by: NLai Jiangshan <laijs@cn.fujitsu.com>
      Tested-by: NSören Brinkmann <soren.brinkmann@xilinx.com>
      Signed-off-by: NMike Turquette <mturquette@linaro.org>
      [mturquette@linaro.org: shortened $SUBJECT]
      72b5322f
  15. 29 5月, 2013 2 次提交
    • S
      clk: Disable unused clocks after deferred probing is done · d41d5805
      Saravana Kannan 提交于
      With deferred probing, late_initcall() is too soon to declare a clock as
      unused. Wait for deferred probing to finish before declaring a clock as
      unused. Since deferred probing is done in late_initcall(), do the unused
      check to late_initcall_sync.
      Signed-off-by: NSaravana Kannan <skannan@codeaurora.org>
      Signed-off-by: NMike Turquette <mturquette@linaro.org>
      d41d5805
    • S
      clk: Fix race condition between clk_set_parent and clk_enable() · f8aa0bd5
      Saravana Kannan 提交于
      Without this patch, the following race condition is possible.
      * clk-A has two parents - clk-X and clk-Y.
      * All three are disabled and clk-X is current parent.
      * Thread A: clk_set_parent(clk-A, clk-Y).
      * Thread A: <snip execution flow>
      * Thread A: Grabs enable lock.
      * Thread A: Sees enable count of clk-A is 0, so doesn't enable clk-Y.
      * Thread A: Updates clk-A SW parent to clk-Y
      * Thread A: Releases enable lock.
      * Thread B: clk_enable(clk-A).
      * Thread B: clk_enable() enables clk-Y, then enabled clk-A and returns.
      
      clk-A is now enabled in software, but not clocking in hardware since the
      hardware parent is still clk-X.
      
      The only way to avoid race conditions between clk_set_parent() and
      clk_enable/disable() is to ensure that clk_enable/disable() calls don't
      require changes to hardware enable state between changes to software clock
      topology and hardware clock topology.
      
      The options to achieve the above are:
      1. Grab the enable lock before changing software/hardware topology and
         release it afterwards.
      2. Keep the clock enabled for the duration of software/hardware topology
         change so that any additional enable/disable calls don't try to change
         the hardware state. Once the topology change is complete, the clock can
         be put back in its original enable state.
      
      Option (1) is not an acceptable solution since the set_parent() ops might
      need to sleep.
      
      Therefore, this patch implements option (2).
      
      This patch doesn't violate any API semantics. clk_disable() doesn't
      guarantee that the clock is actually disabled. So, no clients of a clock
      can assume that a clock is disabled after their last call to clk_disable().
      So, enabling the clock during a parent change is not a violation of any API
      semantics.
      
      This also has the nice side effect of simplifying the error handling code.
      Signed-off-by: NSaravana Kannan <skannan@codeaurora.org>
      Acked-by: NUlf Hansson <ulf.hansson@linaro.org>
      Signed-off-by: NMike Turquette <mturquette@linaro.org>
      [mturquette@linaro.org: fixed up whitespace issue]
      f8aa0bd5
  16. 28 4月, 2013 1 次提交
  17. 16 4月, 2013 1 次提交
  18. 11 4月, 2013 1 次提交
    • S
      clk: Properly handle notifier return values · fb72a059
      Soren Brinkmann 提交于
      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: NSoren Brinkmann <soren.brinkmann@xilinx.com>
      Signed-off-by: NMike Turquette <mturquette@linaro.org>
      fb72a059
  19. 09 4月, 2013 3 次提交
    • U
      clk: Fixup locking issues for clk_set_parent · a68de8e4
      Ulf Hansson 提交于
      Updating the clock tree topology must be protected with the spinlock
      when doing clk_set_parent, otherwise we can not handle the migration
      of the enable_count in a safe manner.
      
      While issuing the .set_parent callback to make the clk-hw perform the
      switch to the new parent, we can not hold the spinlock since it is must
      be allowed to be slow path. This complicates error handling, but is still
      possible to achieve.
      Signed-off-by: NUlf Hansson <ulf.hansson@linaro.org>
      Cc: Rajagopal Venkat <rajagopal.venkat@linaro.org>
      Signed-off-by: NMike Turquette <mturquette@linaro.org>
      a68de8e4
    • U
      clk: Fixup errorhandling for clk_set_parent · 031dcc9b
      Ulf Hansson 提交于
      Fixup the broken feature of allowing reparent of a clk to the
      orhpan list and vice verse. When operating on a single-parent
      clk, the .set_parent callback for the clk hw is optional to
      implement, but for a multi-parent clk it is mandatory.
      
      Moreover improve the errorhandling by verifying the prerequisites
      before triggering clk notifiers. This will prevent unnecessary
      rollback with ABORT_RATE_CHANGE.
      Signed-off-by: NUlf Hansson <ulf.hansson@linaro.org>
      Cc: Rajagopal Venkat <rajagopal.venkat@linaro.org>
      Signed-off-by: NMike Turquette <mturquette@linaro.org>
      031dcc9b
    • U
      clk: Restructure code for __clk_reparent · b33d212f
      Ulf Hansson 提交于
      Split __clk_reparent into three pieces, one for doing the actual
      reparent for updating the clock tree topology, one for the
      COMMON_CLK_DEBUG code and one for doing the rate recalculation.
      
      This patch also makes it possible to hold the spinlock over the
      update of the clock tree topology, which could not be done before
      when both debugfs updates and clock rate updates was done within
      the same function.
      Signed-off-by: NUlf Hansson <ulf.hansson@linaro.org>
      Cc: Rajagopal Venkat <rajagopal.venkat@linaro.org>
      Signed-off-by: NMike Turquette <mturquette@linaro.org>
      b33d212f
  20. 03 4月, 2013 2 次提交
    • M
      clk: allow reentrant calls into the clk framework · 533ddeb1
      Mike Turquette 提交于
      Reentrancy into the clock framework is necessary for clock operations
      that result in nested calls to the clk api.  A common example is a clock
      that is prepared via an i2c transaction, such as a clock inside of a
      discrete audio chip or a power management IC.  The i2c subsystem itself
      will use the clk api resulting in a deadlock:
      
      clk_prepare(audio_clk)
      	i2c_transfer(..)
      		clk_prepare(i2c_controller_clk)
      
      The ability to reenter the clock framework prevents this deadlock.
      
      Other use cases exist such as allowing .set_rate callbacks to call
      clk_set_parent to achieve the best rate, or to save power in certain
      configurations.  Yet another example is performing pinctrl operations
      from a clk_ops callback.  Calls into the pinctrl subsystem may call
      clk_{un}prepare on an unrelated clock.  Allowing for nested calls to
      reenter the clock framework enables both of these use cases.
      
      Reentrancy is implemented by two global pointers that track the owner
      currently holding a global lock.  One pointer tracks the owner during
      sleepable, mutex-protected operations and the other one tracks the owner
      during non-interruptible, spinlock-protected operations.
      
      When the clk framework is entered we try to hold the global lock.  If it
      is held we compare the current task against the current owner; a match
      implies a nested call and we reenter.  If the values do not match then
      we block on the lock until it is released.
      Signed-off-by: NMike Turquette <mturquette@linaro.org>
      Cc: Rajagopal Venkat <rajagopal.venkat@linaro.org>
      Cc: David Brown <davidb@codeaurora.org>
      Tested-by: NLaurent Pinchart <laurent.pinchart@ideasonboard.com>
      Reviewed-by: NThomas Gleixner <tglx@linutronix.de>
      Reviewed-by: NUlf Hansson <ulf.hansson@linaro.org>
      533ddeb1
    • M
      clk: abstract locking out into helper functions · eab89f69
      Mike Turquette 提交于
      Create locking helpers for the global mutex and global spinlock.  The
      definitions of these helpers will be expanded upon in the next patch
      which introduces reentrancy into the locking scheme.
      Signed-off-by: NMike Turquette <mturquette@linaro.org>
      Cc: Rajagopal Venkat <rajagopal.venkat@linaro.org>
      Cc: David Brown <davidb@codeaurora.org>
      Tested-by: NLaurent Pinchart <laurent.pinchart@ideasonboard.com>
      Reviewed-by: NThomas Gleixner <tglx@linutronix.de>
      Reviewed-by: NUlf Hansson <ulf.hansson@linaro.org>
      eab89f69
  21. 23 3月, 2013 1 次提交
  22. 20 3月, 2013 3 次提交
  23. 28 2月, 2013 1 次提交
    • S
      hlist: drop the node parameter from iterators · b67bfe0d
      Sasha Levin 提交于
      I'm not sure why, but the hlist for each entry iterators were conceived
      
              list_for_each_entry(pos, head, member)
      
      The hlist ones were greedy and wanted an extra parameter:
      
              hlist_for_each_entry(tpos, pos, head, member)
      
      Why did they need an extra pos parameter? I'm not quite sure. Not only
      they don't really need it, it also prevents the iterator from looking
      exactly like the list iterator, which is unfortunate.
      
      Besides the semantic patch, there was some manual work required:
      
       - Fix up the actual hlist iterators in linux/list.h
       - Fix up the declaration of other iterators based on the hlist ones.
       - A very small amount of places were using the 'node' parameter, this
       was modified to use 'obj->member' instead.
       - Coccinelle didn't handle the hlist_for_each_entry_safe iterator
       properly, so those had to be fixed up manually.
      
      The semantic patch which is mostly the work of Peter Senna Tschudin is here:
      
      @@
      iterator name hlist_for_each_entry, hlist_for_each_entry_continue, hlist_for_each_entry_from, hlist_for_each_entry_rcu, hlist_for_each_entry_rcu_bh, hlist_for_each_entry_continue_rcu_bh, for_each_busy_worker, ax25_uid_for_each, ax25_for_each, inet_bind_bucket_for_each, sctp_for_each_hentry, sk_for_each, sk_for_each_rcu, sk_for_each_from, sk_for_each_safe, sk_for_each_bound, hlist_for_each_entry_safe, hlist_for_each_entry_continue_rcu, nr_neigh_for_each, nr_neigh_for_each_safe, nr_node_for_each, nr_node_for_each_safe, for_each_gfn_indirect_valid_sp, for_each_gfn_sp, for_each_host;
      
      type T;
      expression a,c,d,e;
      identifier b;
      statement S;
      @@
      
      -T b;
          <+... when != b
      (
      hlist_for_each_entry(a,
      - b,
      c, d) S
      |
      hlist_for_each_entry_continue(a,
      - b,
      c) S
      |
      hlist_for_each_entry_from(a,
      - b,
      c) S
      |
      hlist_for_each_entry_rcu(a,
      - b,
      c, d) S
      |
      hlist_for_each_entry_rcu_bh(a,
      - b,
      c, d) S
      |
      hlist_for_each_entry_continue_rcu_bh(a,
      - b,
      c) S
      |
      for_each_busy_worker(a, c,
      - b,
      d) S
      |
      ax25_uid_for_each(a,
      - b,
      c) S
      |
      ax25_for_each(a,
      - b,
      c) S
      |
      inet_bind_bucket_for_each(a,
      - b,
      c) S
      |
      sctp_for_each_hentry(a,
      - b,
      c) S
      |
      sk_for_each(a,
      - b,
      c) S
      |
      sk_for_each_rcu(a,
      - b,
      c) S
      |
      sk_for_each_from
      -(a, b)
      +(a)
      S
      + sk_for_each_from(a) S
      |
      sk_for_each_safe(a,
      - b,
      c, d) S
      |
      sk_for_each_bound(a,
      - b,
      c) S
      |
      hlist_for_each_entry_safe(a,
      - b,
      c, d, e) S
      |
      hlist_for_each_entry_continue_rcu(a,
      - b,
      c) S
      |
      nr_neigh_for_each(a,
      - b,
      c) S
      |
      nr_neigh_for_each_safe(a,
      - b,
      c, d) S
      |
      nr_node_for_each(a,
      - b,
      c) S
      |
      nr_node_for_each_safe(a,
      - b,
      c, d) S
      |
      - for_each_gfn_sp(a, c, d, b) S
      + for_each_gfn_sp(a, c, d) S
      |
      - for_each_gfn_indirect_valid_sp(a, c, d, b) S
      + for_each_gfn_indirect_valid_sp(a, c, d) S
      |
      for_each_host(a,
      - b,
      c) S
      |
      for_each_host_safe(a,
      - b,
      c, d) S
      |
      for_each_mesh_entry(a,
      - b,
      c, d) S
      )
          ...+>
      
      [akpm@linux-foundation.org: drop bogus change from net/ipv4/raw.c]
      [akpm@linux-foundation.org: drop bogus hunk from net/ipv6/raw.c]
      [akpm@linux-foundation.org: checkpatch fixes]
      [akpm@linux-foundation.org: fix warnings]
      [akpm@linux-foudnation.org: redo intrusive kvm changes]
      Tested-by: NPeter Senna Tschudin <peter.senna@gmail.com>
      Acked-by: NPaul E. McKenney <paulmck@linux.vnet.ibm.com>
      Signed-off-by: NSasha Levin <sasha.levin@oracle.com>
      Cc: Wu Fengguang <fengguang.wu@intel.com>
      Cc: Marcelo Tosatti <mtosatti@redhat.com>
      Cc: Gleb Natapov <gleb@redhat.com>
      Signed-off-by: NAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
      b67bfe0d
  24. 25 1月, 2013 1 次提交
  25. 22 1月, 2013 1 次提交
  26. 12 1月, 2013 3 次提交
    • P
      clk: JSON debugfs clock tree summary · bddca894
      Prashant Gaikwad 提交于
      Clock information is dumped in JSON format which is easy
      for machines to parse.
      
      Each clock is represented as an object which has same name as
      clock and following properties
      	- enable_count
      	- prepare_count
      	- rate
      
      Output is verified using online JSON editor.
      Signed-off-by: NPrashant Gaikwad <pgaikwad@nvidia.com>
      Signed-off-by: NMike Turquette <mturquette@linaro.org>
      bddca894
    • P
      clk: human-readable debugfs clock tree summary · 1af599df
      Prashant Gaikwad 提交于
      Adds debug file "clk_summary" in /sys/kernel/debug/clk dir.
      It helps to view all the clock registered in human-readable format.
      
      For example:
         clock                        enable_cnt  prepare_cnt  rate
      ---------------------------------------------------------------------
       i2s0_sync                      0           0            24000000
       spdif_in_sync                  0           0            24000000
          spdif_mux                   0           0            24000000
             spdif                    0           0            24000000
                spdif_doubler         0           0            48000000
                   spdif_div          0           0            48000000
                      spdif_2x        0           0            48000000
       clk_32k                        2           2            32768
          blink_override              1           1            32768
             blink                    1           1            32768
       clk_m                          2           2            12000000
          clk_out_3_mux               0           0            12000000
             clk_out_3                0           0            12000000
          pll_ref                     3           3            12000000
             pll_e_mux                0           0            12000000
                pll_e                 0           0            100000000
                   cml0               0           0            100000000
                   cml1               0           0            100000000
                   pciex              0           0            100000000
             pll_d2                   0           0            1000000
                pll_d2_out0           0           0            500000
             pll_d                    0           0            1000000
                pll_d_out0            0           0            500000
                   dsib_mux           0           0            500000
                      dsib            0           0            500000
                   dsia               0           0            500000
      Signed-off-by: NPrashant Gaikwad <pgaikwad@nvidia.com>
      Signed-off-by: NMike Turquette <mturquette@linaro.org>
      1af599df
    • N
      clk: export __clk_get_name for re-use in imx-ipu-v3 and others · 4895084c
      Niels de Vos 提交于
      This fixes the following error when building for arm-imx:
      > ERROR: "__clk_get_name" [drivers/staging/imx-drm/ipu-v3/imx-ipu-v3.ko] undefined!
      > make[1]: *** [__modpost] Error 1
      > make: *** [modules] Error 2
      
      There are valid usecases to get the name of a clock, be it for debugging
      purposes or to register a children of a clock like done in this IPU driver.
      Therefore exporting __clk_get_name() and make it available for others makes
      sense.
      Reported-by: NPeter Robinson <pbrobinson@gmail.com>
      CC: Sascha Hauer <s.hauer@pengutronix.de>
      CC: Mike Turquette <mturquette@linaro.org>
      Signed-off-by: NNiels de Vos <ndevos@redhat.com>
      Signed-off-by: NMike Turquette <mturquette@linaro.org>
      [mturquette@linaro.org: removal of inline made redundant by 65800b2c]
      4895084c