thermal: Fail object registration if thermal class is not registered
authorRafael J. Wysocki <rafael.j.wysocki@intel.com>
Mon, 23 Jan 2023 20:44:03 +0000 (21:44 +0100)
committerRafael J. Wysocki <rafael.j.wysocki@intel.com>
Wed, 25 Jan 2023 15:51:19 +0000 (16:51 +0100)
commit9e0a9be24bdd61a160631227ee995b579be566a5
treef50e89f0baff57015e23a4e0af154bfb254b5abe
parent5b8de18ee9027c647db4c1905f7fd0550d17d67a
thermal: Fail object registration if thermal class is not registered

If thermal_class is not registered with the driver core, there is no way
to expose the interfaces used by the thermal control framework, so
prevent thermal zones and cooling devices from being registered in
that case by returning an error from object registration functions.

For this purpose, use a thermal_class pointer that will be NULL if the
class is not registered.  To avoid wasting memory in that case, allocate
the thermal class object dynamically and if it fails to register, free
it and clear the thermal_class pointer to NULL.

Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Acked-by: Daniel Lezcano <daniel.lezcano@linaro.org>
Reviewed-by: Zhang Rui <rui.zhang@intel.com>
Reviewed-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/thermal/thermal_core.c