1. 02 Jan, 2024 4 commits
    • Neil Armstrong's avatar
    • Binbin Zhou's avatar
      drivers/thermal/loongson2_thermal: Fix incorrect PTR_ERR() judgment · 15ef92e9
      Binbin Zhou authored
      PTR_ERR() returns -ENODEV when thermal-zones are undefined, and we need
      -ENODEV as the right value for comparison.
      
      Otherwise, tz->type is NULL when thermal-zones is undefined, resulting
      in the following error:
      
      [   12.290030] CPU 1 Unable to handle kernel paging request at virtual address fffffffffffffff1, era == 900000000355f410, ra == 90000000031579b8
      [   12.302877] Oops[#1]:
      [   12.305190] CPU: 1 PID: 181 Comm: systemd-udevd Not tainted 6.6.0-rc7+ #5385
      [   12.312304] pc 900000000355f410 ra 90000000031579b8 tp 90000001069e8000 sp 90000001069eba10
      [   12.320739] a0 0000000000000000 a1 fffffffffffffff1 a2 0000000000000014 a3 0000000000000001
      [   12.329173] a4 90000001069eb990 a5 0000000000000001 a6 0000000000001001 a7 900000010003431c
      [   12.337606] t0 fffffffffffffff1 t1 54567fd5da9b4fd4 t2 900000010614ec40 t3 00000000000dc901
      [   12.346041] t4 0000000000000000 t5 0000000000000004 t6 900000010614ee20 t7 900000000d00b790
      [   12.354472] t8 00000000000dc901 u0 54567fd5da9b4fd4 s9 900000000402ae10 s0 900000010614ec40
      [   12.362916] s1 90000000039fced0 s2 ffffffffffffffed s3 ffffffffffffffed s4 9000000003acc000
      [   12.362931] s5 0000000000000004 s6 fffffffffffff000 s7 0000000000000490 s8 90000001028b2ec8
      [   12.362938]    ra: 90000000031579b8 thermal_add_hwmon_sysfs+0x258/0x300
      [   12.386411]   ERA: 900000000355f410 strscpy+0xf0/0x160
      [   12.391626]  CRMD: 000000b0 (PLV0 -IE -DA +PG DACF=CC DACM=CC -WE)
      [   12.397898]  PRMD: 00000004 (PPLV0 +PIE -PWE)
      [   12.403678]  EUEN: 00000000 (-FPE -SXE -ASXE -BTE)
      [   12.409859]  ECFG: 00071c1c (LIE=2-4,10-12 VS=7)
      [   12.415882] ESTAT: 00010000 [PIL] (IS= ECode=1 EsubCode=0)
      [   12.415907]  BADV: fffffffffffffff1
      [   12.415911]  PRID: 0014a000 (Loongson-64bit, Loongson-2K1000)
      [   12.415917] Modules linked in: loongson2_thermal(+) vfat fat uio_pdrv_genirq uio fuse zram zsmalloc
      [   12.415950] Process systemd-udevd (pid: 181, threadinfo=00000000358b9718, task=00000000ace72fe3)
      [   12.415961] Stack : 0000000000000dc0 54567fd5da9b4fd4 900000000402ae10 9000000002df9358
      [   12.415982]         ffffffffffffffed 0000000000000004 9000000107a10aa8 90000001002a3410
      [   12.415999]         ffffffffffffffed ffffffffffffffed 9000000107a11268 9000000003157ab0
      [   12.416016]         9000000107a10aa8 ffffff80020fc0c8 90000001002a3410 ffffffffffffffed
      [   12.416032]         0000000000000024 ffffff80020cc1e8 900000000402b2a0 9000000003acc000
      [   12.416048]         90000001002a3410 0000000000000000 ffffff80020f4030 90000001002a3410
      [   12.416065]         0000000000000000 9000000002df6808 90000001002a3410 0000000000000000
      [   12.416081]         ffffff80020f4030 0000000000000000 90000001002a3410 9000000002df2ba8
      [   12.416097]         00000000000000b4 90000001002a34f4 90000001002a3410 0000000000000002
      [   12.416114]         ffffff80020f4030 fffffffffffffff0 90000001002a3410 9000000002df2f30
      [   12.416131]         ...
      [   12.416138] Call Trace:
      [   12.416142] [<900000000355f410>] strscpy+0xf0/0x160
      [   12.416167] [<90000000031579b8>] thermal_add_hwmon_sysfs+0x258/0x300
      [   12.416183] [<9000000003157ab0>] devm_thermal_add_hwmon_sysfs+0x50/0xe0
      [   12.416200] [<ffffff80020cc1e8>] loongson2_thermal_probe+0x128/0x200 [loongson2_thermal]
      [   12.416232] [<9000000002df6808>] platform_probe+0x68/0x140
      [   12.416249] [<9000000002df2ba8>] really_probe+0xc8/0x3c0
      [   12.416269] [<9000000002df2f30>] __driver_probe_device+0x90/0x180
      [   12.416286] [<9000000002df3058>] driver_probe_device+0x38/0x160
      [   12.416302] [<9000000002df33a8>] __driver_attach+0xa8/0x200
      [   12.416314] [<9000000002deffec>] bus_for_each_dev+0x8c/0x120
      [   12.416330] [<9000000002df198c>] bus_add_driver+0x10c/0x2a0
      [   12.416346] [<9000000002df46b4>] driver_register+0x74/0x160
      [   12.416358] [<90000000022201a4>] do_one_initcall+0x84/0x220
      [   12.416372] [<90000000022f3ab8>] do_init_module+0x58/0x2c0
      [   12.416386] [<90000000022f6538>] init_module_from_file+0x98/0x100
      [   12.416399] [<90000000022f67f0>] sys_finit_module+0x230/0x3c0
      [   12.416412] [<900000000358f7c8>] do_syscall+0x88/0xc0
      [   12.416431] [<900000000222137c>] handle_syscall+0xbc/0x158
      
      Fixes: e7e3a7c3 ("thermal/drivers/loongson-2: Add thermal management support")
      Cc: Yinbo Zhu <zhuyinbo@loongson.cn>
      Signed-off-by: default avatarBinbin Zhou <zhoubinbin@loongson.cn>
      Signed-off-by: default avatarDaniel Lezcano <daniel.lezcano@linaro.org>
      Link: https://lore.kernel.org/r/343c14de98216636a47b43e8bfd47b70d0a8e068.1700817227.git.zhoubinbin@loongson.cn
      15ef92e9
    • Binbin Zhou's avatar
      dt-bindings: thermal: loongson,ls2k-thermal: Fix binding check issues · 88071e31
      Binbin Zhou authored
      Add the missing 'thermal-sensor-cells' property which is required for
      every thermal sensor as it's used when using phandles.
      And add the thermal-sensor.yaml reference.
      
      In fact, it was a careless mistake when submitting the driver that
      caused it to not work properly. So the fix is necessary, although it
      will result in the ABI break.
      
      Fixes: 72684d99 ("thermal: dt-bindings: add loongson-2 thermal")
      Cc: Yinbo Zhu <zhuyinbo@loongson.cn>
      Signed-off-by: default avatarBinbin Zhou <zhoubinbin@loongson.cn>
      Reviewed-by: default avatarConor Dooley <conor.dooley@microchip.com>
      Signed-off-by: default avatarDaniel Lezcano <daniel.lezcano@linaro.org>
      Link: https://lore.kernel.org/r/6d69362632271ab0af9a5fbfa3bc46a0894f1d54.1700817227.git.zhoubinbin@loongson.cn
      88071e31
    • Rafał Miłecki's avatar
      dt-bindings: thermal: convert Mediatek Thermal to the json-schema · 788494ba
      Rafał Miłecki authored
      This helps validating DTS files. Introduced changes:
      1. Improved title
      2. Simplified description (dropped "This describes the device tree...")
      3. Dropped undocumented "reset-names" from example
      Signed-off-by: default avatarRafał Miłecki <rafal@milecki.pl>
      Reviewed-by: default avatarRob Herring <robh@kernel.org>
      Reviewed-by: default avatarAngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
      Signed-off-by: default avatarDaniel Lezcano <daniel.lezcano@linaro.org>
      Link: https://lore.kernel.org/r/20231117052214.24554-1-zajec5@gmail.com
      788494ba
  2. 21 Dec, 2023 1 commit
  3. 15 Dec, 2023 1 commit
    • Rafael J. Wysocki's avatar
      thermal: core: Fix NULL pointer dereference in zone registration error path · 04e6ccfc
      Rafael J. Wysocki authored
      If device_register() in thermal_zone_device_register_with_trips()
      returns an error, the tz variable is set to NULL and subsequently
      dereferenced in kfree(tz->tzp).
      
      Commit adc8749b ("thermal/drivers/core: Use put_device() if
      device_register() fails") added the tz = NULL assignment in question to
      avoid a possible double-free after dropping the reference to the zone
      device.  However, after commit 4649620d ("thermal: core: Make
      thermal_zone_device_unregister() return after freeing the zone"), that
      assignment has become redundant, because dropping the reference to the
      zone device does not cause the zone object to be freed any more.
      
      Drop it to address the NULL pointer dereference.
      
      Fixes: 3d439b1a ("thermal/core: Alloc-copy-free the thermal zone parameters structure")
      Signed-off-by: default avatarRafael J. Wysocki <rafael.j.wysocki@intel.com>
      Reviewed-by: default avatarLukasz Luba <lukasz.luba@arm.com>
      04e6ccfc
  4. 13 Dec, 2023 6 commits
  5. 12 Dec, 2023 2 commits
    • Rafael J. Wysocki's avatar
      thermal: core: Rework thermal zone availability check · b38aa87f
      Rafael J. Wysocki authored
      In order to avoid running __thermal_zone_device_update() for thermal
      zones going away, the thermal zone lock is held around device_del()
      in thermal_zone_device_unregister() and thermal_zone_device_update()
      passes the given thermal zone device to device_is_registered().
      This allows thermal_zone_device_update() to skip the
      __thermal_zone_device_update() if device_del() has already run for
      the thermal zone at hand.
      
      However, instead of looking at driver core internals, the thermal
      subsystem may as well rely on its own data structures for this
      purpose.  Namely, if the thermal zone is not present in
      thermal_tz_list, it can be regarded as unavailable, which in fact is
      already the case in thermal_zone_device_unregister().  Accordingly,
      the device_is_registered() check in thermal_zone_device_update() can
      be replaced with checking whether or not the node list_head in struct
      thermal_zone_device is empty, in which case it is not there in
      thermal_tz_list.
      
      To make this work, though, it is necessary to initialize tz->node
      in thermal_zone_device_register_with_trips() before registering the
      thermal zone device and it needs to be added to thermal_tz_list and
      deleted from it under its zone lock.
      
      After the above modifications, the zone lock does not need to be
      held around device_del() in thermal_zone_device_unregister() any more.
      Signed-off-by: default avatarRafael J. Wysocki <rafael.j.wysocki@intel.com>
      Reviewed-and-tested-by: default avatarLukasz Luba <lukasz.luba@arm.com>
      Acked-by: default avatarDaniel Lezcano <daniel.lezcano@linaro.org>
      b38aa87f
    • Rafael J. Wysocki's avatar
      thermal: Drop redundant and confusing device_is_registered() checks · c3ffdfff
      Rafael J. Wysocki authored
      Multiple places in the thermal subsystem (most importantly, sysfs
      attribute callback functions) check if the given thermal zone device is
      still registered in order to return early in case the device_del() in
      thermal_zone_device_unregister() has run already.
      
      However, after thermal_zone_device_unregister() has been made wait for
      all of the zone-related activity to complete before returning, it is
      not necessary to do that any more, because all of the code holding a
      reference to the thermal zone device object will be waited for even if
      it does not do anything special to enforce this.
      
      Accordingly, drop all of the device_is_registered() checks that are now
      redundant and get rid of the zone locking that is not necessary any more
      after dropping them.
      Signed-off-by: default avatarRafael J. Wysocki <rafael.j.wysocki@intel.com>
      Reviewed-and-tested-by: default avatarLukasz Luba <lukasz.luba@arm.com>
      Acked-by: default avatarDaniel Lezcano <daniel.lezcano@linaro.org>
      c3ffdfff
  6. 11 Dec, 2023 1 commit
  7. 06 Dec, 2023 2 commits
    • Rafael J. Wysocki's avatar
      thermal: sysfs: Rework the reading of trip point attributes · 18dfb0e4
      Rafael J. Wysocki authored
      Rework the _show() callback functions for the trip point temperature,
      hysteresis and type attributes to avoid copying the values of struct
      thermal_trip fields that they do not use and make them carry out the
      same validation checks as the corresponding _store() callback functions.
      
      No intentional functional impact.
      Signed-off-by: default avatarRafael J. Wysocki <rafael.j.wysocki@intel.com>
      Reviewed-by: default avatarDaniel Lezcano <daniel.lezcano@linaro.org>
      18dfb0e4
    • Rafael J. Wysocki's avatar
      thermal: sysfs: Rework the handling of trip point updates · be0a3600
      Rafael J. Wysocki authored
      Both trip_point_temp_store() and trip_point_hyst_store() use
      thermal_zone_set_trip() to update a given trip point, but none of them
      actually needs to change more than one field in struct thermal_trip
      representing it.  However, each of them effectively calls
      __thermal_zone_get_trip() twice in a row for the same trip index value,
      once directly and once via thermal_zone_set_trip(), which is not
      particularly efficient, and the way in which thermal_zone_set_trip()
      carries out the update is not particularly straightforward.
      
      Moreover, input processing need not be done under the thermal zone lock
      in any of these functions.
      
      Rework trip_point_temp_store() and trip_point_hyst_store() to address
      the above, move the part of thermal_zone_set_trip() that is still
      useful to a new function called thermal_zone_trip_updated() and drop
      the rest of it.
      
      While at it, make trip_point_hyst_store() reject negative hysteresis
      values.
      Signed-off-by: default avatarRafael J. Wysocki <rafael.j.wysocki@intel.com>
      Reviewed-by: default avatarDaniel Lezcano <daniel.lezcano@linaro.org>
      be0a3600
  8. 30 Nov, 2023 1 commit
  9. 28 Nov, 2023 7 commits
  10. 20 Nov, 2023 1 commit
    • Rafael J. Wysocki's avatar
      thermal: core: Add trip thresholds for trip crossing detection · 44844db9
      Rafael J. Wysocki authored
      The trip crossing detection in handle_thermal_trip() does not work
      correctly in the cases when a trip point is crossed on the way up and
      then the zone temperature stays above its low temperature (that is, its
      temperature decreased by its hysteresis).  The trip temperature may
      be passed by the zone temperature subsequently in that case, even
      multiple times, but that does not count as the trip crossing as long as
      the zone temperature does not fall below the trip's low temperature or,
      in other words, until the trip is crossed on the way down.
      
      |-----------low--------high------------|
                   |<--------->|
                   |    hyst   |
                   |           |
                   |          -|--> crossed on the way up
                   |
               <---|-- crossed on the way down
      
      However, handle_thermal_trip() will invoke thermal_notify_tz_trip_up()
      every time the trip temperature is passed by the zone temperature on
      the way up regardless of whether or not the trip has been crossed on
      the way down yet.  Moreover, it will not call thermal_notify_tz_trip_down()
      if the last zone temperature was between the trip's temperature and its
      low temperature, so some "trip crossed on the way down" events may not
      be reported.
      
      To address this issue, introduce trip thresholds equal to either the
      temperature of the given trip, or its low temperature, such that if
      the trip's threshold is passed by the zone temperature on the way up,
      its value will be set to the trip's low temperature and
      thermal_notify_tz_trip_up() will be called, and if the trip's threshold
      is passed by the zone temperature on the way down, its value will be set
      to the trip's temperature (high) and thermal_notify_tz_trip_down() will
      be called.  Accordingly, if the threshold is passed on the way up, it
      cannot be passed on the way up again until its passed on the way down
      and if it is passed on the way down, it cannot be passed on the way down
      again until it is passed on the way up which guarantees correct
      triggering of trip crossing notifications.
      
      If the last temperature of the zone is invalid, the trip's threshold
      will be set depending of the zone's current temperature: If that
      temperature is above the trip's temperature, its threshold will be
      set to its low temperature or otherwise its threshold will be set to
      its (high) temperature.  Because the zone temperature is initially
      set to invalid and tz->last_temperature is only updated by
      update_temperature(), this is sufficient to set the correct initial
      threshold values for all trips.
      
      Link: https://lore.kernel.org/all/20220718145038.1114379-4-daniel.lezcano@linaro.orgSigned-off-by: default avatarRafael J. Wysocki <rafael.j.wysocki@intel.com>
      44844db9
  11. 19 Nov, 2023 8 commits
  12. 18 Nov, 2023 6 commits