thermal: intel: intel_soc_dts_iosf: Fix thermal_zone removal
Zhang Rui
reviewerPATCH 1/1 thermal: intel: intel_soc_dts_iosf: Fix thermal_zone removal
All of the existing callers of remove_dts_thermal_zone() pass a valid pointer as the argument, so checking for the NULL pointer is redundant.
Plus, when calling remove_dts_thermal_zone() from intel_soc_dts_iosf_init(), it is possible that
1. dts->tzone is an error pointer, when the sensor fails to be registered as a valid thermal zone
2. dts->tzone is unregistered in add_dts_thermal_zone(), when some failure occurs after thermal zone registered
In both cases, there is no need to unregister dts->tzone in remove_dts_thermal_zone().
Clear dst->tzone when add_dts_thermal_zone() fails. And do thermal zone removal in remove_dts_thermal_zone() only when dts->tzone is set.
--- drivers/thermal/intel/intel_soc_dts_iosf.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/thermal/intel/intel_soc_dts_iosf.c +2 -1
@@ -212,7 +212,7 @@ static int soc_dts_enable(int id)static void remove_dts_thermal_zone (struct intel_soc_dts_sensor_entry *dts) { -if (dts) { +if (dts->tzone) {iosf_mbi_write (BT_MBI_UNIT_PMC ,MBI_REG_WRITE ,SOC_DTS_OFFSET_ENABLE , dts->store_status);thermal_zone_device_unregister (dts->tzone);
@@ -277,6 +277,7 @@ static int add_dts_thermal_zone(int id, struct intel_soc_dts_sensor_entry *dts, err_enable:thermal_zone_device_unregister (dts->tzone); err_ret: + dts->tzone =NULL ;return ret; }
Signature · 1 line
2.34.1
Rafael J. Wysocki
maintainerQuoted 3 lines · Zhang Rui
All of the existing callers of
remove_dts_thermal_zone()pass a valid pointer as the argument, so checking for the NULL pointer is redundant.
True.
Quoted 11 lines
Plus, when calling
remove_dts_thermal_zone()fromintel_soc_dts_iosf_init(), it is possible that
1.dts->tzoneis an error pointer, when the sensor fails to be registered as a valid thermal zone
2.dts->tzoneis unregistered inadd_dts_thermal_zone(), when some failure occurs after thermal zone registered
In both cases, there is no need to unregisterdts->tzoneinremove_dts_thermal_zone().Clear
dst->tzonewhenadd_dts_thermal_zone()fails. And do thermal zone removal inremove_dts_thermal_zone()only whendts->tzoneis set.
Well, I'm not sure.
thermal_zone_device_unregister() will do nothing if the thermal zone is not really registered AFAICS and it is prudent to restore SOC_DTS_OFFSET_ENABLE on failure IMO.
Quoted 29 lines
Signed-off-by Zhang Rui <[email protected]>--- drivers/thermal/intel/intel_soc_dts_iosf.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)drivers/thermal/intel/intel_soc_dts_iosf.c +2
-2@@ -212,7 +212,7 @@ static int soc_dts_enable(int id)static void remove_dts_thermal_zone (struct intel_soc_dts_sensor_entry *dts) { -if (dts) { +if (dts->tzone) {iosf_mbi_write (BT_MBI_UNIT_PMC ,MBI_REG_WRITE ,SOC_DTS_OFFSET_ENABLE , dts->store_status);thermal_zone_device_unregister (dts->tzone);@@ -277,6 +277,7 @@ static int add_dts_thermal_zone(int id, struct intel_soc_dts_sensor_entry *dts, err_enable:thermal_zone_device_unregister (dts->tzone); err_ret: + dts->tzone =NULL ;return ret; } --2.34.1
Zhang, Rui
reviewerQuoted 19 lines · Rafael J. Wysocki
Quoted 5 lines · Zhang Rui
All of the existing callers of
remove_dts_thermal_zone()pass a valid
pointer as the argument, so checking for the NULL pointer is redundant.True.
Quoted 9 lines
Plus, when calling
remove_dts_thermal_zone()fromintel_soc_dts_iosf_init(), it is possible that
1.dts->tzoneis an error pointer, when the sensor fails to be registered as a valid thermal zone
2.dts->tzoneis unregistered inadd_dts_thermal_zone(), when some failure occurs after thermal zone registered
In both cases, there is no need to unregisterdts->tzoneinremove_dts_thermal_zone().
Quoted 8 lines
Quoted 3 lines
Clear
dst->tzonewhenadd_dts_thermal_zone()fails. And do thermal zone
removal inremove_dts_thermal_zone()only whendts->tzoneis set.Well, I'm not sure.
thermal_zone_device_unregister()will do nothing if the thermal zone is not really registered AFAICS
yes.
Quoted 2 lines
and it is prudent to restore
SOC_DTS_OFFSET_ENABLEon failure IMO.
agreed. Refreshed patch sent.
As this becomes really trivial, feel free to apply it or drop it.
thanks,
rui