1. 16 4月, 2019 1 次提交
  2. 05 4月, 2019 1 次提交
    • M
      power: supply: Fix the simple battery property names · f0459fe1
      Maxime Ripard 提交于
      Commit c08b1f45 ("power: supply: core: Add power_supply_battery_info
      and API") introduced code to parse the simple-battery node and express
      battery charging constraints. However, it parsed that node using the
      properties constant_charge_current_max_microamp and
      constant_charge_voltage_max_microvolt, while the device tree binding for
      the simple-battery node uses dashes to separate the words in those
      properties (constant-charge-current-max-microamp and
      constant-charge-voltage-max-microvolt).
      
      Let's make the code match the binding.
      
      Fixes: c08b1f45 ("power: supply: core: Add power_supply_battery_info and API")
      Signed-off-by: NMaxime Ripard <maxime.ripard@bootlin.com>
      Signed-off-by: NSebastian Reichel <sebastian.reichel@collabora.com>
      f0459fe1
  3. 20 2月, 2019 1 次提交
  4. 21 1月, 2019 1 次提交
  5. 13 12月, 2018 1 次提交
  6. 10 11月, 2018 2 次提交
  7. 06 7月, 2018 1 次提交
    • B
      power: remove possible deadlock when unregistering power_supply · 3ffa6583
      Benjamin Tissoires 提交于
      If a device gets removed right after having registered a power_supply node,
      we might enter in a deadlock between the remove call (that has a lock on
      the parent device) and the deferred register work.
      
      Allow the deferred register work to exit without taking the lock when
      we are in the remove state.
      
      Stack trace on a Ubuntu 16.04:
      
      [16072.109121] INFO: task kworker/u16:2:1180 blocked for more than 120 seconds.
      [16072.109127]       Not tainted 4.13.0-41-generic #46~16.04.1-Ubuntu
      [16072.109129] "echo 0 > /proc/sys/kernel/hung_task_timeout_secs" disables this message.
      [16072.109132] kworker/u16:2   D    0  1180      2 0x80000000
      [16072.109142] Workqueue: events_power_efficient power_supply_deferred_register_work
      [16072.109144] Call Trace:
      [16072.109152]  __schedule+0x3d6/0x8b0
      [16072.109155]  schedule+0x36/0x80
      [16072.109158]  schedule_preempt_disabled+0xe/0x10
      [16072.109161]  __mutex_lock.isra.2+0x2ab/0x4e0
      [16072.109166]  __mutex_lock_slowpath+0x13/0x20
      [16072.109168]  ? __mutex_lock_slowpath+0x13/0x20
      [16072.109171]  mutex_lock+0x2f/0x40
      [16072.109174]  power_supply_deferred_register_work+0x2b/0x50
      [16072.109179]  process_one_work+0x15b/0x410
      [16072.109182]  worker_thread+0x4b/0x460
      [16072.109186]  kthread+0x10c/0x140
      [16072.109189]  ? process_one_work+0x410/0x410
      [16072.109191]  ? kthread_create_on_node+0x70/0x70
      [16072.109194]  ret_from_fork+0x35/0x40
      [16072.109199] INFO: task test:2257 blocked for more than 120 seconds.
      [16072.109202]       Not tainted 4.13.0-41-generic #46~16.04.1-Ubuntu
      [16072.109204] "echo 0 > /proc/sys/kernel/hung_task_timeout_secs" disables this message.
      [16072.109206] test            D    0  2257   2256 0x00000004
      [16072.109208] Call Trace:
      [16072.109211]  __schedule+0x3d6/0x8b0
      [16072.109215]  schedule+0x36/0x80
      [16072.109218]  schedule_timeout+0x1f3/0x360
      [16072.109221]  ? check_preempt_curr+0x5a/0xa0
      [16072.109224]  ? ttwu_do_wakeup+0x1e/0x150
      [16072.109227]  wait_for_completion+0xb4/0x140
      [16072.109230]  ? wait_for_completion+0xb4/0x140
      [16072.109233]  ? wake_up_q+0x70/0x70
      [16072.109236]  flush_work+0x129/0x1e0
      [16072.109240]  ? worker_detach_from_pool+0xb0/0xb0
      [16072.109243]  __cancel_work_timer+0x10f/0x190
      [16072.109247]  ? device_del+0x264/0x310
      [16072.109250]  ? __wake_up+0x44/0x50
      [16072.109253]  cancel_delayed_work_sync+0x13/0x20
      [16072.109257]  power_supply_unregister+0x37/0xb0
      [16072.109260]  devm_power_supply_release+0x11/0x20
      [16072.109263]  release_nodes+0x110/0x200
      [16072.109266]  devres_release_group+0x7c/0xb0
      [16072.109274]  wacom_remove+0xc2/0x110 [wacom]
      [16072.109279]  hid_device_remove+0x6e/0xd0 [hid]
      [16072.109284]  device_release_driver_internal+0x158/0x210
      [16072.109288]  device_release_driver+0x12/0x20
      [16072.109291]  bus_remove_device+0xec/0x160
      [16072.109293]  device_del+0x1de/0x310
      [16072.109298]  hid_destroy_device+0x27/0x60 [hid]
      [16072.109303]  usbhid_disconnect+0x51/0x70 [usbhid]
      [16072.109308]  usb_unbind_interface+0x77/0x270
      [16072.109311]  device_release_driver_internal+0x158/0x210
      [16072.109315]  device_release_driver+0x12/0x20
      [16072.109318]  usb_driver_release_interface+0x77/0x80
      [16072.109321]  proc_ioctl+0x20f/0x250
      [16072.109325]  usbdev_do_ioctl+0x57f/0x1140
      [16072.109327]  ? __wake_up+0x44/0x50
      [16072.109331]  usbdev_ioctl+0xe/0x20
      [16072.109336]  do_vfs_ioctl+0xa4/0x600
      [16072.109339]  ? vfs_write+0x15a/0x1b0
      [16072.109343]  SyS_ioctl+0x79/0x90
      [16072.109347]  entry_SYSCALL_64_fastpath+0x24/0xab
      [16072.109349] RIP: 0033:0x7f20da807f47
      [16072.109351] RSP: 002b:00007ffc422ae398 EFLAGS: 00000246 ORIG_RAX: 0000000000000010
      [16072.109353] RAX: ffffffffffffffda RBX: 00000000010b8560 RCX: 00007f20da807f47
      [16072.109355] RDX: 00007ffc422ae3a0 RSI: 00000000c0105512 RDI: 0000000000000009
      [16072.109356] RBP: 0000000000000000 R08: 00007ffc422ae3e0 R09: 0000000000000010
      [16072.109357] R10: 00000000000000a6 R11: 0000000000000246 R12: 0000000000000000
      [16072.109359] R13: 00000000010b8560 R14: 00007ffc422ae2e0 R15: 0000000000000000
      Reported-and-tested-by: NRichard Hughes <rhughes@redhat.com>
      Tested-by: NAaron Skomra <Aaron.Skomra@wacom.com>
      Signed-off-by: NBenjamin Tissoires <benjamin.tissoires@redhat.com>
      Fixes: 7f1a57fd ("power_supply: Fix possible NULL pointer dereference on early uevent")
      Signed-off-by: NSebastian Reichel <sebastian.reichel@collabora.co.uk>
      3ffa6583
  8. 13 6月, 2018 1 次提交
    • K
      treewide: devm_kzalloc() -> devm_kcalloc() · a86854d0
      Kees Cook 提交于
      The devm_kzalloc() function has a 2-factor argument form, devm_kcalloc().
      This patch replaces cases of:
      
              devm_kzalloc(handle, a * b, gfp)
      
      with:
              devm_kcalloc(handle, a * b, gfp)
      
      as well as handling cases of:
      
              devm_kzalloc(handle, a * b * c, gfp)
      
      with:
      
              devm_kzalloc(handle, array3_size(a, b, c), gfp)
      
      as it's slightly less ugly than:
      
              devm_kcalloc(handle, array_size(a, b), c, gfp)
      
      This does, however, attempt to ignore constant size factors like:
      
              devm_kzalloc(handle, 4 * 1024, gfp)
      
      though any constants defined via macros get caught up in the conversion.
      
      Any factors with a sizeof() of "unsigned char", "char", and "u8" were
      dropped, since they're redundant.
      
      Some manual whitespace fixes were needed in this patch, as Coccinelle
      really liked to write "=devm_kcalloc..." instead of "= devm_kcalloc...".
      
      The Coccinelle script used for this was:
      
      // Fix redundant parens around sizeof().
      @@
      expression HANDLE;
      type TYPE;
      expression THING, E;
      @@
      
      (
        devm_kzalloc(HANDLE,
      -	(sizeof(TYPE)) * E
      +	sizeof(TYPE) * E
        , ...)
      |
        devm_kzalloc(HANDLE,
      -	(sizeof(THING)) * E
      +	sizeof(THING) * E
        , ...)
      )
      
      // Drop single-byte sizes and redundant parens.
      @@
      expression HANDLE;
      expression COUNT;
      typedef u8;
      typedef __u8;
      @@
      
      (
        devm_kzalloc(HANDLE,
      -	sizeof(u8) * (COUNT)
      +	COUNT
        , ...)
      |
        devm_kzalloc(HANDLE,
      -	sizeof(__u8) * (COUNT)
      +	COUNT
        , ...)
      |
        devm_kzalloc(HANDLE,
      -	sizeof(char) * (COUNT)
      +	COUNT
        , ...)
      |
        devm_kzalloc(HANDLE,
      -	sizeof(unsigned char) * (COUNT)
      +	COUNT
        , ...)
      |
        devm_kzalloc(HANDLE,
      -	sizeof(u8) * COUNT
      +	COUNT
        , ...)
      |
        devm_kzalloc(HANDLE,
      -	sizeof(__u8) * COUNT
      +	COUNT
        , ...)
      |
        devm_kzalloc(HANDLE,
      -	sizeof(char) * COUNT
      +	COUNT
        , ...)
      |
        devm_kzalloc(HANDLE,
      -	sizeof(unsigned char) * COUNT
      +	COUNT
        , ...)
      )
      
      // 2-factor product with sizeof(type/expression) and identifier or constant.
      @@
      expression HANDLE;
      type TYPE;
      expression THING;
      identifier COUNT_ID;
      constant COUNT_CONST;
      @@
      
      (
      - devm_kzalloc
      + devm_kcalloc
        (HANDLE,
      -	sizeof(TYPE) * (COUNT_ID)
      +	COUNT_ID, sizeof(TYPE)
        , ...)
      |
      - devm_kzalloc
      + devm_kcalloc
        (HANDLE,
      -	sizeof(TYPE) * COUNT_ID
      +	COUNT_ID, sizeof(TYPE)
        , ...)
      |
      - devm_kzalloc
      + devm_kcalloc
        (HANDLE,
      -	sizeof(TYPE) * (COUNT_CONST)
      +	COUNT_CONST, sizeof(TYPE)
        , ...)
      |
      - devm_kzalloc
      + devm_kcalloc
        (HANDLE,
      -	sizeof(TYPE) * COUNT_CONST
      +	COUNT_CONST, sizeof(TYPE)
        , ...)
      |
      - devm_kzalloc
      + devm_kcalloc
        (HANDLE,
      -	sizeof(THING) * (COUNT_ID)
      +	COUNT_ID, sizeof(THING)
        , ...)
      |
      - devm_kzalloc
      + devm_kcalloc
        (HANDLE,
      -	sizeof(THING) * COUNT_ID
      +	COUNT_ID, sizeof(THING)
        , ...)
      |
      - devm_kzalloc
      + devm_kcalloc
        (HANDLE,
      -	sizeof(THING) * (COUNT_CONST)
      +	COUNT_CONST, sizeof(THING)
        , ...)
      |
      - devm_kzalloc
      + devm_kcalloc
        (HANDLE,
      -	sizeof(THING) * COUNT_CONST
      +	COUNT_CONST, sizeof(THING)
        , ...)
      )
      
      // 2-factor product, only identifiers.
      @@
      expression HANDLE;
      identifier SIZE, COUNT;
      @@
      
      - devm_kzalloc
      + devm_kcalloc
        (HANDLE,
      -	SIZE * COUNT
      +	COUNT, SIZE
        , ...)
      
      // 3-factor product with 1 sizeof(type) or sizeof(expression), with
      // redundant parens removed.
      @@
      expression HANDLE;
      expression THING;
      identifier STRIDE, COUNT;
      type TYPE;
      @@
      
      (
        devm_kzalloc(HANDLE,
      -	sizeof(TYPE) * (COUNT) * (STRIDE)
      +	array3_size(COUNT, STRIDE, sizeof(TYPE))
        , ...)
      |
        devm_kzalloc(HANDLE,
      -	sizeof(TYPE) * (COUNT) * STRIDE
      +	array3_size(COUNT, STRIDE, sizeof(TYPE))
        , ...)
      |
        devm_kzalloc(HANDLE,
      -	sizeof(TYPE) * COUNT * (STRIDE)
      +	array3_size(COUNT, STRIDE, sizeof(TYPE))
        , ...)
      |
        devm_kzalloc(HANDLE,
      -	sizeof(TYPE) * COUNT * STRIDE
      +	array3_size(COUNT, STRIDE, sizeof(TYPE))
        , ...)
      |
        devm_kzalloc(HANDLE,
      -	sizeof(THING) * (COUNT) * (STRIDE)
      +	array3_size(COUNT, STRIDE, sizeof(THING))
        , ...)
      |
        devm_kzalloc(HANDLE,
      -	sizeof(THING) * (COUNT) * STRIDE
      +	array3_size(COUNT, STRIDE, sizeof(THING))
        , ...)
      |
        devm_kzalloc(HANDLE,
      -	sizeof(THING) * COUNT * (STRIDE)
      +	array3_size(COUNT, STRIDE, sizeof(THING))
        , ...)
      |
        devm_kzalloc(HANDLE,
      -	sizeof(THING) * COUNT * STRIDE
      +	array3_size(COUNT, STRIDE, sizeof(THING))
        , ...)
      )
      
      // 3-factor product with 2 sizeof(variable), with redundant parens removed.
      @@
      expression HANDLE;
      expression THING1, THING2;
      identifier COUNT;
      type TYPE1, TYPE2;
      @@
      
      (
        devm_kzalloc(HANDLE,
      -	sizeof(TYPE1) * sizeof(TYPE2) * COUNT
      +	array3_size(COUNT, sizeof(TYPE1), sizeof(TYPE2))
        , ...)
      |
        devm_kzalloc(HANDLE,
      -	sizeof(TYPE1) * sizeof(THING2) * (COUNT)
      +	array3_size(COUNT, sizeof(TYPE1), sizeof(TYPE2))
        , ...)
      |
        devm_kzalloc(HANDLE,
      -	sizeof(THING1) * sizeof(THING2) * COUNT
      +	array3_size(COUNT, sizeof(THING1), sizeof(THING2))
        , ...)
      |
        devm_kzalloc(HANDLE,
      -	sizeof(THING1) * sizeof(THING2) * (COUNT)
      +	array3_size(COUNT, sizeof(THING1), sizeof(THING2))
        , ...)
      |
        devm_kzalloc(HANDLE,
      -	sizeof(TYPE1) * sizeof(THING2) * COUNT
      +	array3_size(COUNT, sizeof(TYPE1), sizeof(THING2))
        , ...)
      |
        devm_kzalloc(HANDLE,
      -	sizeof(TYPE1) * sizeof(THING2) * (COUNT)
      +	array3_size(COUNT, sizeof(TYPE1), sizeof(THING2))
        , ...)
      )
      
      // 3-factor product, only identifiers, with redundant parens removed.
      @@
      expression HANDLE;
      identifier STRIDE, SIZE, COUNT;
      @@
      
      (
        devm_kzalloc(HANDLE,
      -	(COUNT) * STRIDE * SIZE
      +	array3_size(COUNT, STRIDE, SIZE)
        , ...)
      |
        devm_kzalloc(HANDLE,
      -	COUNT * (STRIDE) * SIZE
      +	array3_size(COUNT, STRIDE, SIZE)
        , ...)
      |
        devm_kzalloc(HANDLE,
      -	COUNT * STRIDE * (SIZE)
      +	array3_size(COUNT, STRIDE, SIZE)
        , ...)
      |
        devm_kzalloc(HANDLE,
      -	(COUNT) * (STRIDE) * SIZE
      +	array3_size(COUNT, STRIDE, SIZE)
        , ...)
      |
        devm_kzalloc(HANDLE,
      -	COUNT * (STRIDE) * (SIZE)
      +	array3_size(COUNT, STRIDE, SIZE)
        , ...)
      |
        devm_kzalloc(HANDLE,
      -	(COUNT) * STRIDE * (SIZE)
      +	array3_size(COUNT, STRIDE, SIZE)
        , ...)
      |
        devm_kzalloc(HANDLE,
      -	(COUNT) * (STRIDE) * (SIZE)
      +	array3_size(COUNT, STRIDE, SIZE)
        , ...)
      |
        devm_kzalloc(HANDLE,
      -	COUNT * STRIDE * SIZE
      +	array3_size(COUNT, STRIDE, SIZE)
        , ...)
      )
      
      // Any remaining multi-factor products, first at least 3-factor products,
      // when they're not all constants...
      @@
      expression HANDLE;
      expression E1, E2, E3;
      constant C1, C2, C3;
      @@
      
      (
        devm_kzalloc(HANDLE, C1 * C2 * C3, ...)
      |
        devm_kzalloc(HANDLE,
      -	(E1) * E2 * E3
      +	array3_size(E1, E2, E3)
        , ...)
      |
        devm_kzalloc(HANDLE,
      -	(E1) * (E2) * E3
      +	array3_size(E1, E2, E3)
        , ...)
      |
        devm_kzalloc(HANDLE,
      -	(E1) * (E2) * (E3)
      +	array3_size(E1, E2, E3)
        , ...)
      |
        devm_kzalloc(HANDLE,
      -	E1 * E2 * E3
      +	array3_size(E1, E2, E3)
        , ...)
      )
      
      // And then all remaining 2 factors products when they're not all constants,
      // keeping sizeof() as the second factor argument.
      @@
      expression HANDLE;
      expression THING, E1, E2;
      type TYPE;
      constant C1, C2, C3;
      @@
      
      (
        devm_kzalloc(HANDLE, sizeof(THING) * C2, ...)
      |
        devm_kzalloc(HANDLE, sizeof(TYPE) * C2, ...)
      |
        devm_kzalloc(HANDLE, C1 * C2 * C3, ...)
      |
        devm_kzalloc(HANDLE, C1 * C2, ...)
      |
      - devm_kzalloc
      + devm_kcalloc
        (HANDLE,
      -	sizeof(TYPE) * (E2)
      +	E2, sizeof(TYPE)
        , ...)
      |
      - devm_kzalloc
      + devm_kcalloc
        (HANDLE,
      -	sizeof(TYPE) * E2
      +	E2, sizeof(TYPE)
        , ...)
      |
      - devm_kzalloc
      + devm_kcalloc
        (HANDLE,
      -	sizeof(THING) * (E2)
      +	E2, sizeof(THING)
        , ...)
      |
      - devm_kzalloc
      + devm_kcalloc
        (HANDLE,
      -	sizeof(THING) * E2
      +	E2, sizeof(THING)
        , ...)
      |
      - devm_kzalloc
      + devm_kcalloc
        (HANDLE,
      -	(E1) * E2
      +	E1, E2
        , ...)
      |
      - devm_kzalloc
      + devm_kcalloc
        (HANDLE,
      -	(E1) * (E2)
      +	E1, E2
        , ...)
      |
      - devm_kzalloc
      + devm_kcalloc
        (HANDLE,
      -	E1 * E2
      +	E1, E2
        , ...)
      )
      Signed-off-by: NKees Cook <keescook@chromium.org>
      a86854d0
  9. 25 5月, 2018 1 次提交
  10. 25 4月, 2018 2 次提交
  11. 22 2月, 2018 1 次提交
  12. 06 11月, 2017 1 次提交
  13. 29 8月, 2017 2 次提交
  14. 09 8月, 2017 1 次提交
  15. 15 6月, 2017 1 次提交
  16. 08 6月, 2017 1 次提交
  17. 15 5月, 2017 1 次提交
  18. 01 5月, 2017 1 次提交
    • H
      power: supply: Make power_supply_am_i_supplied return -ENODEV if there are no suppliers · 2848e039
      Hans de Goede 提交于
      It is sensible to assume that the hardware actually always has a
      way of charging the battery so when power_supply_am_i_supplied does not
      find any suppliers, that does not mean that there are none, but simply
      that no power_supply-drivers are registered / bound for any suppliers for
      the supply calling power_supply_am_i_supplied.
      
      At which point a fuel-gauge driver calling power_supply_am_i_supplied()
      cannot determine whether the battery is being charged or not.
      
      Allow a caller of power_supply_am_i_supplied to differentiate between
      there not being any suppliers, vs no suppliers being online by returning
      -ENODEV if there are no suppliers matching supplied_to / supplied_from,
      which allows fuel-gauge drivers to return POWER_SUPPLY_STATUS_UNKNOWN
      rather then POWER_SUPPLY_STATUS_DISCHARGING if there are no suppliers.
      Signed-off-by: NHans de Goede <hdegoede@redhat.com>
      Reviewed-by: NKrzysztof Kozlowski <krzk@kernel.org>
      Signed-off-by: NSebastian Reichel <sebastian.reichel@collabora.co.uk>
      2848e039
  19. 19 10月, 2016 1 次提交
  20. 11 8月, 2016 1 次提交
  21. 02 7月, 2016 1 次提交
    • R
      power_supply: fix return value of get_property · e3805385
      Rhyland Klein 提交于
      power_supply_get_property() should ideally return -EAGAIN if it is
      called while the power_supply is being registered. There was no way
      previously to determine if use_cnt == 0 meant that the power_supply
      wasn't fully registered yet, or if it had already been unregistered.
      
      Add a new boolean to the power_supply struct to simply show if
      registration is completed. Lastly, modify the check in
      power_supply_show_property() to also ignore -EAGAIN when so it
      doesn't complain about not returning the property.
      Signed-off-by: NRhyland Klein <rklein@nvidia.com>
      Signed-off-by: NSebastian Reichel <sre@kernel.org>
      e3805385
  22. 15 6月, 2016 1 次提交
    • R
      power_supply: power_supply_read_temp only if use_cnt > 0 · 5bc28b93
      Rhyland Klein 提交于
      Change power_supply_read_temp() to use power_supply_get_property()
      so that it will check the use_cnt and ensure it is > 0. The use_cnt
      will be incremented at the end of __power_supply_register, so this
      will block to case where get_property can be called before the supply
      is fully registered. This fixes the issue show in the stack below:
      
      [    1.452598] power_supply_read_temp+0x78/0x80
      [    1.458680] thermal_zone_get_temp+0x5c/0x11c
      [    1.464765] thermal_zone_device_update+0x34/0xb4
      [    1.471195] thermal_zone_device_register+0x87c/0x8cc
      [    1.477974] __power_supply_register+0x364/0x424
      [    1.484317] power_supply_register_no_ws+0x10/0x18
      [    1.490833] bq27xxx_battery_setup+0x10c/0x164
      [    1.497003] bq27xxx_battery_i2c_probe+0xd0/0x1b0
      [    1.503435] i2c_device_probe+0x174/0x240
      [    1.509172] driver_probe_device+0x1fc/0x29c
      [    1.515167] __driver_attach+0xa4/0xa8
      [    1.520643] bus_for_each_dev+0x58/0x98
      [    1.526204] driver_attach+0x20/0x28
      [    1.531505] bus_add_driver+0x1c8/0x22c
      [    1.537067] driver_register+0x68/0x108
      [    1.542630] i2c_register_driver+0x38/0x7c
      [    1.548457] bq27xxx_battery_i2c_driver_init+0x18/0x20
      [    1.555321] do_one_initcall+0x38/0x12c
      [    1.560886] kernel_init_freeable+0x148/0x1ec
      [    1.566972] kernel_init+0x10/0xfc
      [    1.572101] ret_from_fork+0x10/0x40
      
      Also make the same change to ps_get_max_charge_cntl_limit() and
      ps_get_cur_chrage_cntl_limit() to be safe. Lastly, change the return
      value of power_supply_get_property() to -EAGAIN from -ENODEV if
      use_cnt <= 0.
      
      Fixes: 297d716f ("power_supply: Change ownership from driver to core")
      Cc: stable@vger.kernel.org
      Signed-off-by: NRhyland Klein <rklein@nvidia.com>
      Reviewed-by: NKrzysztof Kozlowski <k.kozlowski@samsung.com>
      Signed-off-by: NSebastian Reichel <sre@kernel.org>
      5bc28b93
  23. 03 8月, 2015 1 次提交
    • S
      thermal: consistently use int for temperatures · 17e8351a
      Sascha Hauer 提交于
      The thermal code uses int, long and unsigned long for temperatures
      in different places.
      
      Using an unsigned type limits the thermal framework to positive
      temperatures without need. Also several drivers currently will report
      temperatures near UINT_MAX for temperatures below 0°C. This will probably
      immediately shut the machine down due to overtemperature if started below
      0°C.
      
      'long' is 64bit on several architectures. This is not needed since INT_MAX °mC
      is above the melting point of all known materials.
      
      Consistently use a plain 'int' for temperatures throughout the thermal code and
      the drivers. This only changes the places in the drivers where the temperature
      is passed around as pointer, when drivers internally use another type this is
      not changed.
      Signed-off-by: NSascha Hauer <s.hauer@pengutronix.de>
      Acked-by: NGeert Uytterhoeven <geert+renesas@glider.be>
      Reviewed-by: NJean Delvare <jdelvare@suse.de>
      Reviewed-by: NLukasz Majewski <l.majewski@samsung.com>
      Reviewed-by: NDarren Hart <dvhart@linux.intel.com>
      Reviewed-by: NHeiko Stuebner <heiko@sntech.de>
      Reviewed-by: NPeter Feuerer <peter@piie.net>
      Cc: Punit Agrawal <punit.agrawal@arm.com>
      Cc: Zhang Rui <rui.zhang@intel.com>
      Cc: Eduardo Valentin <edubezval@gmail.com>
      Cc: linux-pm@vger.kernel.org
      Cc: linux-kernel@vger.kernel.org
      Cc: Jean Delvare <jdelvare@suse.de>
      Cc: Peter Feuerer <peter@piie.net>
      Cc: Heiko Stuebner <heiko@sntech.de>
      Cc: Lukasz Majewski <l.majewski@samsung.com>
      Cc: Stephen Warren <swarren@wwwdotorg.org>
      Cc: Thierry Reding <thierry.reding@gmail.com>
      Cc: linux-acpi@vger.kernel.org
      Cc: platform-driver-x86@vger.kernel.org
      Cc: linux-arm-kernel@lists.infradead.org
      Cc: linux-omap@vger.kernel.org
      Cc: linux-samsung-soc@vger.kernel.org
      Cc: Guenter Roeck <linux@roeck-us.net>
      Cc: Rafael J. Wysocki <rjw@rjwysocki.net>
      Cc: Maxime Ripard <maxime.ripard@free-electrons.com>
      Cc: Darren Hart <dvhart@infradead.org>
      Cc: lm-sensors@lm-sensors.org
      Signed-off-by: NZhang Rui <rui.zhang@intel.com>
      17e8351a
  24. 19 6月, 2015 1 次提交
  25. 10 6月, 2015 1 次提交
  26. 21 5月, 2015 2 次提交
    • K
      power_supply: Fix possible NULL pointer dereference on early uevent · 7f1a57fd
      Krzysztof Kozlowski 提交于
      Don't call the power_supply_changed() from power_supply_register() when
      parent is still probing because it may lead to accessing parent too
      early.
      
      In bq27x00_battery this caused NULL pointer exception because uevent of
      power_supply_changed called back the the get_property() method provided
      by the driver. The get_property() method accessed pointer which should
      be returned by power_supply_register().
      
      Starting from bq27x00_battery_probe():
        di->bat = power_supply_register()
          power_supply_changed()
            kobject_uevent()
              power_supply_uevent()
                power_supply_show_property()
                  power_supply_get_property()
                    bq27x00_battery_get_property()
                      dereference of di->bat which is NULL here
      
      The dereference of di->bat (value returned by power_supply_register())
      is the currently visible problem. However calling back the methods
      provided by driver before ending the probe may lead to accessing other
      driver-related data which is not yet initialized.
      
      The call to power_supply_changed() is postponed till probing ends -
      mutex of parent device is released.
      Reported-by: NH. Nikolaus Schaller <hns@goldelico.com>
      Signed-off-by: NKrzysztof Kozlowski <k.kozlowski@samsung.com>
      Fixes: 297d716f ("power_supply: Change ownership from driver to core")
      Tested-By: NDr. H. Nikolaus Schaller <hns@goldelico.com>
      Signed-off-by: NSebastian Reichel <sre@kernel.org>
      7f1a57fd
    • K
      power_supply: Fix NULL pointer dereference during bq27x00_battery probe · 8e59c7f2
      Krzysztof Kozlowski 提交于
      Power supply is often registered during probe of a driver. The
      power_supply_register() returns pointer to newly allocated structure as
      return value. However before returning the power_supply_register()
      calls back the get_property() method provided by the driver through
      uevent.
      
      In that time the driver probe is still in progress and driver did not
      assigned pointer to power supply to its local variables. This leads to
      NULL pointer dereference from get_property() function.
      Starting from bq27x00_battery_probe():
        di->bat = power_supply_register()
          device_add()
            kobject_uevent()
              power_supply_uevent()
                power_supply_show_property()
                  power_supply_get_property()
                    bq27x00_battery_get_property()
                      dereference of (di->bat) which is NULL here
      
      The first uevent of power supply (the one coming from device creation)
      should not call back to the driver. To prevent that from happening,
      increment the atomic use counter at the end of power_supply_register().
      This means that power_supply_get_property() will return -ENODEV.
      
      IMPORTANT:
      The patch has impact on this first uevent sent from power supply because
      it will not contain properties from power supply.
      
      The uevent with properties will be sent later after indicating that
      power supply has changed. This also has a race now, but will be fixed in
      other patches.
      Reported-by: NH. Nikolaus Schaller <hns@goldelico.com>
      Signed-off-by: NKrzysztof Kozlowski <k.kozlowski@samsung.com>
      Fixes: 297d716f ("power_supply: Change ownership from driver to core")
      Tested-By: NDr. H. Nikolaus Schaller <hns@goldelico.com>
      Signed-off-by: NSebastian Reichel <sre@kernel.org>
      8e59c7f2
  27. 14 3月, 2015 6 次提交
    • K
      power_supply: Increment power supply use counter when obtaining references · 03e81acc
      Krzysztof Kozlowski 提交于
      Increment the power_supply.use_cnt usage counter on:
       - power_supply_get_by_phandle()
       - power_supply_get_by_name()
      and decrement it on power_supply_put() call.
      
      This helps tracking of valid usage of power supply instance by
      consumers. The usage counter itself also allows safe calling of
      power_supply_get_property-like functions even when driver unregisters
      this power supply.
      Signed-off-by: NKrzysztof Kozlowski <k.kozlowski@samsung.com>
      Reviewed-by: NBartlomiej Zolnierkiewicz <b.zolnierkie@samsung.com>
      Signed-off-by: NSebastian Reichel <sre@kernel.org>
      03e81acc
    • K
      power_supply: Add power_supply_put for decrementing device reference counter · 1a352462
      Krzysztof Kozlowski 提交于
      The power_supply_get_by_phandle() and power_supply_get_by_name() use
      function class_find_device() for obtaining the reference to power
      supply. Each use of class_find_device() increases the power supply's
      device reference counter.
      
      However the reference counter was not decreased by users of this API.
      Thus final device_unregister() call from power_supply_unregister() could
      not release the device and clean up its resources. This lead to memory
      leak if at least once power_supply_get_by_*() was called between
      registering and unregistering the power supply.
      
      Add and document new API power_supply_put() for decrementing the
      reference counter.
      Signed-off-by: NKrzysztof Kozlowski <k.kozlowski@samsung.com>
      Acked-by: NPavel Machek <pavel@ucw.cz>
      Reviewed-by: NBartlomiej Zolnierkiewicz <b.zolnierkie@samsung.com>
      Reviewed-by: NSebastian Reichel <sre@kernel.org>
      Signed-off-by: NSebastian Reichel <sre@kernel.org>
      1a352462
    • K
      power_supply: Change ownership from driver to core · 297d716f
      Krzysztof Kozlowski 提交于
      Change the ownership of power_supply structure from each driver
      implementing the class to the power supply core.
      
      The patch changes power_supply_register() function thus all drivers
      implementing power supply class are adjusted.
      
      Each driver provides the implementation of power supply. However it
      should not be the owner of power supply class instance because it is
      exposed by core to other subsystems with power_supply_get_by_name().
      These other subsystems have no knowledge when the driver will unregister
      the power supply. This leads to several issues when driver is unbound -
      mostly because user of power supply accesses freed memory.
      
      Instead let the core own the instance of struct 'power_supply'.  Other
      users of this power supply will still access valid memory because it
      will be freed when device reference count reaches 0. Currently this
      means "it will leak" but power_supply_put() call in next patches will
      solve it.
      
      This solves invalid memory references in following race condition
      scenario:
      
      Thread 1: charger manager
      Thread 2: power supply driver, used by charger manager
      
      THREAD 1 (charger manager)         THREAD 2 (power supply driver)
      ==========================         ==============================
      psy = power_supply_get_by_name()
                                         Driver unbind, .remove
                                           power_supply_unregister()
                                           Device fully removed
      psy->get_property()
      
      The 'get_property' call is executed in invalid context because the driver was
      unbound and struct 'power_supply' memory was freed.
      
      This could be observed easily with charger manager driver (here compiled
      with max17040 fuel gauge):
      
      $ cat /sys/devices/virtual/power_supply/cm-battery/capacity &
      $ echo "1-0036" > /sys/bus/i2c/drivers/max17040/unbind
      [   55.725123] Unable to handle kernel NULL pointer dereference at virtual address 00000000
      [   55.732584] pgd = d98d4000
      [   55.734060] [00000000] *pgd=5afa2831, *pte=00000000, *ppte=00000000
      [   55.740318] Internal error: Oops: 80000007 [#1] PREEMPT SMP ARM
      [   55.746210] Modules linked in:
      [   55.749259] CPU: 1 PID: 2936 Comm: cat Tainted: G        W       3.19.0-rc1-next-20141226-00048-gf79f475f3c44-dirty #1496
      [   55.760190] Hardware name: SAMSUNG EXYNOS (Flattened Device Tree)
      [   55.766270] task: d9b76f00 ti: daf54000 task.ti: daf54000
      [   55.771647] PC is at 0x0
      [   55.774182] LR is at charger_get_property+0x2f4/0x36c
      [   55.779201] pc : [<00000000>]    lr : [<c034b0b4>]    psr: 60000013
      [   55.779201] sp : daf55e90  ip : 00000003  fp : 00000000
      [   55.790657] r10: 00000000  r9 : c06e2878  r8 : d9b26c68
      [   55.795865] r7 : dad81610  r6 : daec7410  r5 : daf55ebc  r4 : 00000000
      [   55.802367] r3 : 00000000  r2 : daf55ebc  r1 : 0000002a  r0 : d9b26c68
      [   55.808879] Flags: nZCv  IRQs on  FIQs on  Mode SVC_32  ISA ARM  Segment user
      [   55.815994] Control: 10c5387d  Table: 598d406a  DAC: 00000015
      [   55.821723] Process cat (pid: 2936, stack limit = 0xdaf54210)
      [   55.827451] Stack: (0xdaf55e90 to 0xdaf56000)
      [   55.831795] 5e80:                                     60000013 c01459c4 0000002a c06f8ef8
      [   55.839956] 5ea0: db651000 c06f8ef8 daebac00 c04cb668 daebac08 c0346864 00000000 c01459c4
      [   55.848115] 5ec0: d99eaa80 c06f8ef8 00000fff 00001000 db651000 c027f25c c027f240 d99eaa80
      [   55.856274] 5ee0: d9a06c00 c0146218 daf55f18 00001000 d99eaa80 db4c18c0 00000001 00000001
      [   55.864468] 5f00: daf55f80 c0144c78 c0144c54 c0107f90 00015000 d99eaab0 00000000 00000000
      [   55.872603] 5f20: 000051c7 00000000 db4c18c0 c04a9370 00015000 00001000 daf55f80 00001000
      [   55.880763] 5f40: daf54000 00015000 00000000 c00e53dc db4c18c0 c00e548c 0000000d 00008124
      [   55.888937] 5f60: 00000001 00000000 00000000 db4c18c0 db4c18c0 00001000 00015000 c00e5550
      [   55.897099] 5f80: 00000000 00000000 00001000 00001000 00015000 00000003 00000003 c000f364
      [   55.905239] 5fa0: 00000000 c000f1a0 00001000 00015000 00000003 00015000 00001000 0001333c
      [   55.913399] 5fc0: 00001000 00015000 00000003 00000003 00000002 00000000 00000000 00000000
      [   55.921560] 5fe0: 7fffe000 be999850 0000a225 b6f3c19c 60000010 00000003 00000000 00000000
      [   55.929744] [<c034b0b4>] (charger_get_property) from [<c0346864>] (power_supply_show_property+0x48/0x20c)
      [   55.939286] [<c0346864>] (power_supply_show_property) from [<c027f25c>] (dev_attr_show+0x1c/0x48)
      [   55.948130] [<c027f25c>] (dev_attr_show) from [<c0146218>] (sysfs_kf_seq_show+0x84/0x104)
      [   55.956298] [<c0146218>] (sysfs_kf_seq_show) from [<c0144c78>] (kernfs_seq_show+0x24/0x28)
      [   55.964536] [<c0144c78>] (kernfs_seq_show) from [<c0107f90>] (seq_read+0x1b0/0x484)
      [   55.972172] [<c0107f90>] (seq_read) from [<c00e53dc>] (__vfs_read+0x18/0x4c)
      [   55.979188] [<c00e53dc>] (__vfs_read) from [<c00e548c>] (vfs_read+0x7c/0x100)
      [   55.986304] [<c00e548c>] (vfs_read) from [<c00e5550>] (SyS_read+0x40/0x8c)
      [   55.993164] [<c00e5550>] (SyS_read) from [<c000f1a0>] (ret_fast_syscall+0x0/0x48)
      [   56.000626] Code: bad PC value
      [   56.011652] ---[ end trace 7b64343fbdae8ef1 ]---
      Signed-off-by: NKrzysztof Kozlowski <k.kozlowski@samsung.com>
      Reviewed-by: NBartlomiej Zolnierkiewicz <b.zolnierkie@samsung.com>
      
      [for the nvec part]
      Reviewed-by: NMarc Dietrich <marvin24@gmx.de>
      
      [for compal-laptop.c]
      Acked-by: NDarren Hart <dvhart@linux.intel.com>
      
      [for the mfd part]
      Acked-by: NLee Jones <lee.jones@linaro.org>
      
      [for the hid part]
      Acked-by: NJiri Kosina <jkosina@suse.cz>
      
      [for the acpi part]
      Acked-by: NRafael J. Wysocki <rafael.j.wysocki@intel.com>
      Signed-off-by: NSebastian Reichel <sre@kernel.org>
      297d716f
    • K
      power_supply: Add API for safe access of power supply function attrs · bc154056
      Krzysztof Kozlowski 提交于
      Add simple wrappers for accessing power supply's function attributes:
       - get_property -> power_supply_get_property
       - set_property -> power_supply_set_property
       - property_is_writeable -> power_supply_property_is_writeable
       - external_power_changed -> power_supply_external_power_changed
      
      This API along with atomic usage counter adds a safe way of accessing a
      power supply from another driver. If power supply is unregistered after
      obtaining reference to it by some driver, then the API wrappers won't be
      executed in invalid (freed) context.
      
      Next patch changing the ownership of power supply class is still needed
      to fully fix race conditions in accessing freed power supply.
      Signed-off-by: NKrzysztof Kozlowski <k.kozlowski@samsung.com>
      Reviewed-by: NBartlomiej Zolnierkiewicz <b.zolnierkie@samsung.com>
      Reviewed-by: NSebastian Reichel <sre@kernel.org>
      Acked-by: NPavel Machek <pavel@ucw.cz>
      Signed-off-by: NSebastian Reichel <sre@kernel.org>
      bc154056
    • K
      power_supply: Move run-time configuration to separate structure · 2dc9215d
      Krzysztof Kozlowski 提交于
      Add new structure 'power_supply_config' for holding run-time
      initialization data like of_node, supplies and private driver data.
      
      The power_supply_register() function is changed so all power supply
      drivers need updating.
      
      When registering the power supply this new 'power_supply_config' should be
      used instead of directly initializing 'struct power_supply'. This allows
      changing the ownership of power_supply structure from driver to the
      power supply core in next patches.
      
      When a driver does not use of_node or supplies then it should use NULL
      as config. If driver uses of_node or supplies then it should allocate
      config on stack and initialize it with proper values.
      Signed-off-by: NKrzysztof Kozlowski <k.kozlowski@samsung.com>
      Reviewed-by: NBartlomiej Zolnierkiewicz <b.zolnierkie@samsung.com>
      Acked-by: NPavel Machek <pavel@ucw.cz>
      
      [for the nvec part]
      Reviewed-by: NMarc Dietrich <marvin24@gmx.de>
      
      [for drivers/platform/x86/compal-laptop.c]
      Reviewed-by: NDarren Hart <dvhart@linux.intel.com>
      
      [for drivers/hid/*]
      Reviewed-by: NJiri Kosina <jkosina@suse.cz>
      Signed-off-by: NSebastian Reichel <sre@kernel.org>
      2dc9215d
    • K
      power_supply: Add driver private data · e44ea364
      Krzysztof Kozlowski 提交于
      Allow drivers to store private data inside power_supply structure for
      later usage in power supply operations.
      
      Usage of driver private data is necessary to access driver's state
      container object from power supply calls (like get_property()) if struct
      'power_supply' is a stored there as a pointer, for example:
      
      struct some_driver_info {
      	struct i2c_client       *client;
      	struct power_supply     *power_supply;
      	...
      }
      
      In such case one cannot use container_of() and must store pointer to
      state container as private data.
      Signed-off-by: NKrzysztof Kozlowski <k.kozlowski@samsung.com>
      Reviewed-by: NBartlomiej Zolnierkiewicz <b.zolnierkie@samsung.com>
      Reviewed-by: NSebastian Reichel <sre@kernel.org>
      Acked-by: NPavel Machek <pavel@ucw.cz>
      Signed-off-by: NSebastian Reichel <sre@kernel.org>
      e44ea364
  28. 26 2月, 2015 1 次提交
  29. 28 10月, 2014 1 次提交
    • K
      power_supply: Add no_thermal property to prevent recursive get_temp calls · a69d82b9
      Krzysztof Kozlowski 提交于
      Add a 'no_thermal' property to the power supply class. If true then
      thermal zone won't be created for this power supply in
      power_supply_register().
      
      Power supply drivers may want to set it if they support
      POWER_SUPPLY_PROP_TEMP and they are forwarding this get property call to
      other thermal zone.
      
      If they won't set it lockdep may report false positive deadlock for
      thermal zone's mutex because of nested calls to thermal_zone_get_temp().
      First is the call to thermal_zone_get_temp() of the driver's thermal
      zone. Thermal core gets POWER_SUPPLY_PROP_TEMP property from this
      driver. The driver then calls other thermal zone thermal_zone_get_temp()
      and returns result.
      
      Example of such driver is charger manager.
      Signed-off-by: NKrzysztof Kozlowski <k.kozlowski@samsung.com>
      Signed-off-by: NSebastian Reichel <sre@kernel.org>
      a69d82b9
  30. 16 9月, 2014 2 次提交