hwmon: (core) Do not use device managed functions for memory allocations
The hwmon core uses device managed functions, tied to the hwmon parent
device, for various internal memory allocations. This is problematic
since hwmon device lifetime does not necessarily match its parent's
device lifetime. If there is a mismatch, memory leaks will accumulate
until the parent device is released.
Fix the problem by managing all memory allocations internally. The only
exception is memory allocation for thermal device registration, which
can be tied to the hwmon device, along with thermal device registration
itself.
Fixes: 1a69ed7c8631 ("hwmon: (core) New hwmon registration API") Cc: stable@vger.kernel.org # v4.14.x: 918304a122d7: hwmon: Deal with errors from the thermal subsystem Cc: stable@vger.kernel.org # v4.14.x: fc8621573cc1: hwmon: (core) Fix double-free in __hwmon_device_register() Cc: stable@vger.kernel.org # v4.9.x: bdbde54066bf: hwmon: (core) Simplify sysfs attribute name allocation Cc: stable@vger.kernel.org # v4.9.x: 918304a122d7: hwmon: Deal with errors from the thermal subsystem Cc: stable@vger.kernel.org # v4.9.x: fc8621573cc1: hwmon: (core) Fix double-free in __hwmon_device_register() Cc: stable@vger.kernel.org # v4.9+ Cc: Martin K. Petersen <martin.petersen@oracle.com> Signed-off-by: Guenter Roeck <linux@roeck-us.net>