hwmon: (pwm-fan) Use devm_thermal_of_cooling_device_register
authorGuenter Roeck <linux@roeck-us.net>
Thu, 18 Apr 2019 19:58:20 +0000 (12:58 -0700)
committerEduardo Valentin <edubezval@gmail.com>
Tue, 14 May 2019 14:00:47 +0000 (07:00 -0700)
commit37bcec5d9f71bd13142a97d2196b293c9ac23823
tree0350c5a1d8edcee93c0e48b8d204d361d7547300
parent0b2a785db8797db08181f71395a412c8eedbc614
hwmon: (pwm-fan) Use devm_thermal_of_cooling_device_register

Use devm_thermal_of_cooling_device_register() to register the cooling
device. Also use devm_add_action_or_reset() to stop the fan on device
removal, and to disable the pwm. Introduce a local 'dev' variable in
the probe function to make the code easier to read.

As a side effect, this fixes a bug seen if pwm_fan_of_get_cooling_data()
returned an error. In that situation, the pwm was not disabled, and
the fan was not stopped. Using devm functions also ensures that the
pwm is disabled and that the fan is stopped only after the hwmon device
has been unregistered.

Cc: Lukasz Majewski <l.majewski@samsung.com>
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Eduardo Valentin <edubezval@gmail.com>
drivers/hwmon/pwm-fan.c