1. 24 6月, 2019 1 次提交
    • G
      hwmon: (core) Add comment describing how hwdev is freed in error path · 792eac18
      Guenter Roeck 提交于
      The hwmon core registers the hwmon device before adding sensors to the
      thermal core. If that fails, the hwmon device is released and an error
      is returned to the caller. From the code flow, it appears to be necessary
      to free struct hwmon_device *, allocated with kzalloc(), in that
      situation. This is incorrect, since the data structure will be freed
      automatically in hwmon_dev_release() when device_unregister() is called.
      This used to result in a double free, which was found and fixed with
      commit 74e35127 ("hwmon: (core) Fix double-free in
      __hwmon_device_register()"). This is, however, not obvious; any reader
      may erroneously conclude that the data structure is not freed.
      
      Add comment explaining why kfree() is not necessary in this situation.
      Reported-by: NEduardo Valentin <eduval@amazon.com>
      Cc: Eduardo Valentin <eduval@amazon.com>
      Signed-off-by: NGuenter Roeck <linux@roeck-us.net>
      792eac18
  2. 06 6月, 2019 1 次提交
    • E
      hwmon: (core) add thermal sensors only if dev->of_node is present · c41dd48e
      Eduardo Valentin 提交于
      Drivers may register to hwmon and request for also registering
      with the thermal subsystem (HWMON_C_REGISTER_TZ). However,
      some of these driver, e.g. marvell phy, may be probed from
      Device Tree or being dynamically allocated, and in the later
      case, it will not have a dev->of_node entry.
      
      Registering with hwmon without the dev->of_node may result in
      different outcomes depending on the device tree, which may
      be a bit misleading. If the device tree blob has no 'thermal-zones'
      node, the *hwmon_device_register*() family functions are going
      to gracefully succeed, because of-thermal,
      *thermal_zone_of_sensor_register() return -ENODEV in this case,
      and the hwmon error path handles this error code as success to
      cover for the case where CONFIG_THERMAL_OF is not set.
      However, if the device tree blob has the 'thermal-zones'
      entry, the *hwmon_device_register*() will always fail on callers
      with no dev->of_node, propagating -EINVAL.
      
      If dev->of_node is not present, calling of-thermal does not
      make sense. For this reason, this patch checks first if the
      device has a of_node before going over the process of registering
      with the thermal subsystem of-thermal interface. And in this case,
      when a caller of *hwmon_device_register*() with HWMON_C_REGISTER_TZ
      and no dev->of_node will still register with hwmon, but not with
      the thermal subsystem. If all the hwmon part bits are in place,
      the registration will succeed.
      
      Fixes: d560168b ("hwmon: (core) New hwmon registration API")
      Cc: Jean Delvare <jdelvare@suse.com>
      Cc: Guenter Roeck <linux@roeck-us.net>
      Cc: linux-hwmon@vger.kernel.org
      Cc: linux-kernel@vger.kernel.org
      Signed-off-by: NEduardo Valentin <eduval@amazon.com>
      Signed-off-by: NGuenter Roeck <linux@roeck-us.net>
      c41dd48e
  3. 05 6月, 2019 1 次提交
  4. 06 5月, 2019 1 次提交
    • D
      hwmon/drivers/core: Simplify complex dependency · f3735332
      Daniel Lezcano 提交于
      As the thermal framework does not longer compile as a module, we can
      simplify this condition below:
      
       if IS_REACHABLE(CONFIG_THERMAL) && defined(CONFIG_THERMAL_OF) && \
             (!defined(CONFIG_THERMAL_HWMON) || \
              !(defined(MODULE) && IS_MODULE(CONFIG_THERMAL)))
      
       if IS_REACHABLE(CONFIG_THERMAL) && defined(CONFIG_THERMAL_OF) && \
             (!defined(CONFIG_THERMAL_HWMON) || \
              !(defined(MODULE) && 0))
      
      => (whatever && 0) = 0
      
       if IS_REACHABLE(CONFIG_THERMAL) && defined(CONFIG_THERMAL_OF) && \
             (!defined(CONFIG_THERMAL_HWMON) || !(0))
      
       if IS_REACHABLE(CONFIG_THERMAL) && defined(CONFIG_THERMAL_OF) && \
             (!defined(CONFIG_THERMAL_HWMON) || 1)
      
      => (whatever || 1) = 1
      
       if IS_REACHABLE(CONFIG_THERMAL) && defined(CONFIG_THERMAL_OF) && \
             (1)
      
      => (whatever && 1) = whatever
      
       if IS_REACHABLE(CONFIG_THERMAL) && defined(CONFIG_THERMAL_OF)
      
      CONFIG_THERMAL can not be a module anymore, then:
      
       if defined(CONFIG_THERMAL) && defined(CONFIG_THERMAL_OF)
      
      And CONFIG_THERMAL_OF already depends on CONFIG_THERMAL, so:
      
       if defined(CONFIG_THERMAL_OF)
      
      Thus,
      
       ifdef CONFIG_THERMAL_OF
      Signed-off-by: NDaniel Lezcano <daniel.lezcano@linaro.org>
      Acked-by: NGuenter Roeck <linux@roeck-us.net>
      Signed-off-by: NZhang Rui <rui.zhang@intel.com>
      f3735332
  5. 16 4月, 2019 1 次提交
  6. 19 2月, 2019 1 次提交
  7. 03 12月, 2018 1 次提交
  8. 05 11月, 2018 1 次提交
    • D
      hwmon: (core) Fix double-free in __hwmon_device_register() · 74e35127
      Dmitry Osipenko 提交于
      Fix double-free that happens when thermal zone setup fails, see KASAN log
      below.
      
      ==================================================================
      BUG: KASAN: double-free or invalid-free in __hwmon_device_register+0x5dc/0xa7c
      
      CPU: 0 PID: 132 Comm: kworker/0:2 Tainted: G    B             4.19.0-rc8-next-20181016-00042-gb52cd80401e9-dirty #41
      Hardware name: NVIDIA Tegra SoC (Flattened Device Tree)
      Workqueue: events deferred_probe_work_func
      Backtrace:
      [<c0110540>] (dump_backtrace) from [<c0110944>] (show_stack+0x20/0x24)
      [<c0110924>] (show_stack) from [<c105cb08>] (dump_stack+0x9c/0xb0)
      [<c105ca6c>] (dump_stack) from [<c02fdaec>] (print_address_description+0x68/0x250)
      [<c02fda84>] (print_address_description) from [<c02fd4ac>] (kasan_report_invalid_free+0x68/0x88)
      [<c02fd444>] (kasan_report_invalid_free) from [<c02fc85c>] (__kasan_slab_free+0x1f4/0x200)
      [<c02fc668>] (__kasan_slab_free) from [<c02fd0c0>] (kasan_slab_free+0x14/0x18)
      [<c02fd0ac>] (kasan_slab_free) from [<c02f9c6c>] (kfree+0x90/0x294)
      [<c02f9bdc>] (kfree) from [<c0b41bbc>] (__hwmon_device_register+0x5dc/0xa7c)
      [<c0b415e0>] (__hwmon_device_register) from [<c0b421e8>] (hwmon_device_register_with_info+0xa0/0xa8)
      [<c0b42148>] (hwmon_device_register_with_info) from [<c0b42324>] (devm_hwmon_device_register_with_info+0x74/0xb4)
      [<c0b422b0>] (devm_hwmon_device_register_with_info) from [<c0b4481c>] (lm90_probe+0x414/0x578)
      [<c0b44408>] (lm90_probe) from [<c0aeeff4>] (i2c_device_probe+0x35c/0x384)
      [<c0aeec98>] (i2c_device_probe) from [<c08776cc>] (really_probe+0x290/0x3e4)
      [<c087743c>] (really_probe) from [<c0877a2c>] (driver_probe_device+0x80/0x1c4)
      [<c08779ac>] (driver_probe_device) from [<c0877da8>] (__device_attach_driver+0x104/0x11c)
      [<c0877ca4>] (__device_attach_driver) from [<c0874dd8>] (bus_for_each_drv+0xa4/0xc8)
      [<c0874d34>] (bus_for_each_drv) from [<c08773b0>] (__device_attach+0xf0/0x15c)
      [<c08772c0>] (__device_attach) from [<c0877e24>] (device_initial_probe+0x1c/0x20)
      [<c0877e08>] (device_initial_probe) from [<c08762f4>] (bus_probe_device+0xdc/0xec)
      [<c0876218>] (bus_probe_device) from [<c0876a08>] (deferred_probe_work_func+0xa8/0xd4)
      [<c0876960>] (deferred_probe_work_func) from [<c01527c4>] (process_one_work+0x3dc/0x96c)
      [<c01523e8>] (process_one_work) from [<c01541e0>] (worker_thread+0x4ec/0x8bc)
      [<c0153cf4>] (worker_thread) from [<c015b238>] (kthread+0x230/0x240)
      [<c015b008>] (kthread) from [<c01010bc>] (ret_from_fork+0x14/0x38)
      Exception stack(0xcf743fb0 to 0xcf743ff8)
      3fa0:                                     00000000 00000000 00000000 00000000
      3fc0: 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
      3fe0: 00000000 00000000 00000000 00000000 00000013 00000000
      
      Allocated by task 132:
       kasan_kmalloc.part.1+0x58/0xf4
       kasan_kmalloc+0x90/0xa4
       kmem_cache_alloc_trace+0x90/0x2a0
       __hwmon_device_register+0xbc/0xa7c
       hwmon_device_register_with_info+0xa0/0xa8
       devm_hwmon_device_register_with_info+0x74/0xb4
       lm90_probe+0x414/0x578
       i2c_device_probe+0x35c/0x384
       really_probe+0x290/0x3e4
       driver_probe_device+0x80/0x1c4
       __device_attach_driver+0x104/0x11c
       bus_for_each_drv+0xa4/0xc8
       __device_attach+0xf0/0x15c
       device_initial_probe+0x1c/0x20
       bus_probe_device+0xdc/0xec
       deferred_probe_work_func+0xa8/0xd4
       process_one_work+0x3dc/0x96c
       worker_thread+0x4ec/0x8bc
       kthread+0x230/0x240
       ret_from_fork+0x14/0x38
         (null)
      
      Freed by task 132:
       __kasan_slab_free+0x12c/0x200
       kasan_slab_free+0x14/0x18
       kfree+0x90/0x294
       hwmon_dev_release+0x1c/0x20
       device_release+0x4c/0xe8
       kobject_put+0xac/0x11c
       device_unregister+0x2c/0x30
       __hwmon_device_register+0xa58/0xa7c
       hwmon_device_register_with_info+0xa0/0xa8
       devm_hwmon_device_register_with_info+0x74/0xb4
       lm90_probe+0x414/0x578
       i2c_device_probe+0x35c/0x384
       really_probe+0x290/0x3e4
       driver_probe_device+0x80/0x1c4
       __device_attach_driver+0x104/0x11c
       bus_for_each_drv+0xa4/0xc8
       __device_attach+0xf0/0x15c
       device_initial_probe+0x1c/0x20
       bus_probe_device+0xdc/0xec
       deferred_probe_work_func+0xa8/0xd4
       process_one_work+0x3dc/0x96c
       worker_thread+0x4ec/0x8bc
       kthread+0x230/0x240
       ret_from_fork+0x14/0x38
         (null)
      
      Cc: <stable@vger.kernel.org> # v4.15+
      Fixes: 47c332de ("hwmon: Deal with errors from the thermal subsystem")
      Signed-off-by: NDmitry Osipenko <digetx@gmail.com>
      Signed-off-by: NGuenter Roeck <linux@roeck-us.net>
      74e35127
  9. 12 10月, 2018 1 次提交
    • N
      hwmon: (core) Add trace events to _attr_show/store functions · 61b8ab2c
      Nicolin Chen 提交于
      Trace events are useful for people who collect data from the
      Ftrace outputs. There're people who analyse the relationship
      of cpufreq, thermal and hwmon (power/voltage/current) using
      the convenient and timestamped Ftrace outputs, while unlike
      cpufreq and thermal subsystems the hwmon does not have trace
      events supported yet.
      
      So this patch adds initial trace events for the hwmon core.
      To call hwmon_attr_base() for aligned attr index numbers, it
      also moves the function upward.
      
      Ftrace outputs:
       ...: hwmon_attr_show_string: index=2, attr_name=in2_label, val=VDD_5V
       ...: hwmon_attr_show: index=2, attr_name=in2_input, val=5112
       ...: hwmon_attr_show: index=2, attr_name=curr2_input, val=440
      
      Note that the _attr_show and _attr_store functions are tied
      to the _with_info API. So a hwmon driver requiring the trace
      events feature should use _with_info API to register a hwmon
      device.
      Signed-off-by: NNicolin Chen <nicoleotsuka@gmail.com>
      Signed-off-by: NGuenter Roeck <linux@roeck-us.net>
      61b8ab2c
  10. 11 10月, 2018 1 次提交
  11. 18 7月, 2018 1 次提交
  12. 21 5月, 2018 1 次提交
  13. 03 1月, 2018 1 次提交
    • G
      hwmon: Fix parameter documentation · 3870945a
      Guenter Roeck 提交于
      sparse reports:
      
      drivers/hwmon/hwmon.c:681: warning:
      	No description found for parameter 'chip'
      drivers/hwmon/hwmon.c:681: warning:
      	Excess function parameter 'info' description in
      	'hwmon_device_register_with_info'
      drivers/hwmon/hwmon.c:789: warning:
      	No description found for parameter 'chip'
      drivers/hwmon/hwmon.c:789: warning:
      	No description found for parameter 'groups'
      drivers/hwmon/hwmon.c:789: warning:
      	Excess function parameter 'info' description in
      	'devm_hwmon_device_register_with_info'
      Signed-off-by: NGuenter Roeck <linux@roeck-us.net>
      3870945a
  14. 27 12月, 2017 1 次提交
    • L
      hwmon: Deal with errors from the thermal subsystem · 47c332de
      Linus Walleij 提交于
      If the thermal subsystem returne -EPROBE_DEFER or any other error
      when hwmon calls devm_thermal_zone_of_sensor_register(), this is
      silently ignored.
      
      I ran into this with an incorrectly defined thermal zone, making
      it non-existing and thus this call failed with -EPROBE_DEFER
      assuming it would appear later. The sensor was still added
      which is incorrect: sensors must strictly be added after the
      thermal zones, so deferred probe must be respected.
      
      Fixes: d560168b ("hwmon: (core) New hwmon registration API")
      Signed-off-by: NLinus Walleij <linus.walleij@linaro.org>
      Signed-off-by: NGuenter Roeck <linux@roeck-us.net>
      47c332de
  15. 13 8月, 2017 2 次提交
  16. 02 4月, 2017 1 次提交
  17. 31 1月, 2017 2 次提交
  18. 25 1月, 2017 1 次提交
  19. 03 1月, 2017 1 次提交
  20. 10 12月, 2016 7 次提交
  21. 24 10月, 2016 1 次提交
  22. 09 9月, 2016 9 次提交
  23. 04 3月, 2014 1 次提交
  24. 14 10月, 2013 1 次提交
    • G
      hwmon: Provide managed hwmon registration · 74188cba
      Guenter Roeck 提交于
      Drivers using the new hwmon_device_register_with_groups API often have a
      remove function which consists solely of a call hwmon_device_unregister().
      
      Provide support for devm_hwmon_device_register_with_groups and
      devm_hwmon_device_unregister to allow this repeated code to be removed
      and help eliminate error handling code.
      Signed-off-by: NGuenter Roeck <linux@roeck-us.net>
      74188cba