In the Linux kernel, the following vulnerability has been resolved:
thermal: core: call putdevice() only after deviceregister() fails
putdevice() shouldn't be called before a prior call to deviceregister(). _thermalcoolingdeviceregister() doesn't follow that properly and needs fixing. Also thermalcoolingdevicedestroysysfs() is getting called unnecessarily on few error paths.
Fix all this by placing the calls at the right place.
Based on initial work done by Caleb Connolly.