thermal: sysfs: Fix cooling_device_stats_setup() error code path
authorRafael J. Wysocki <rafael.j.wysocki@intel.com>
Fri, 29 Jul 2022 15:39:07 +0000 (17:39 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 17 Aug 2022 12:22:50 +0000 (14:22 +0200)
commit06d6eb948e5323cbb9d90429cad098f964a1193c
tree5d2d97800f7c41dacc97757ffe0298c244109bd1
parentcd28cf0f69b4a81e19b542d88ad89141700b025d
thermal: sysfs: Fix cooling_device_stats_setup() error code path

commit d5a8aa5d7d80d21ab6b266f1bed4194b61746199 upstream.

If cooling_device_stats_setup() fails to create the stats object, it
must clear the last slot in cooling_device_attr_groups that was
initially empty (so as to make it possible to add stats attributes to
the cooling device attribute groups).

Failing to do so may cause the stats attributes to be created by
mistake for a device that doesn't have a stats object, because the
slot in question might be populated previously during the registration
of another cooling device.

Fixes: 8ea229511e06 ("thermal: Add cooling device's statistics in sysfs")
Reported-by: Di Shen <di.shen@unisoc.com>
Tested-by: Di Shen <di.shen@unisoc.com>
Cc: 4.17+ <stable@vger.kernel.org> # 4.17+
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/thermal/thermal_sysfs.c