Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

thermal_hwmon: Add devres wrapper for thermal_add_hwmon_sysfs()

Add devres wrapper for thermal_add_hwmon_sysfs() to simplify driver
code.

Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
Reviewed-by: Daniel Lezcano <daniel.lezcano@linaro.org>
Tested-by: Lucas Stach <l.stach@pengutronix.de>
Cc: Chris Healy <cphealy@gmail.com>
Cc: Lucas Stach <l.stach@pengutronix.de>
Cc: Eduardo Valentin <edubezval@gmail.com>
Cc: Daniel Lezcano <daniel.lezcano@linaro.org>
Cc: Angus Ainslie (Purism) <angus@akkea.ca>
Cc: linux-imx@nxp.com
Cc: linux-pm@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org>
Link: https://lore.kernel.org/r/20191210164153.10463-12-andrew.smirnov@gmail.com

authored by

Andrey Smirnov and committed by
Daniel Lezcano
c7fc403e 36564d7e

+35
+28
drivers/thermal/thermal_hwmon.c
··· 248 248 kfree(hwmon); 249 249 } 250 250 EXPORT_SYMBOL_GPL(thermal_remove_hwmon_sysfs); 251 + 252 + static void devm_thermal_hwmon_release(struct device *dev, void *res) 253 + { 254 + thermal_remove_hwmon_sysfs(*(struct thermal_zone_device **)res); 255 + } 256 + 257 + int devm_thermal_add_hwmon_sysfs(struct thermal_zone_device *tz) 258 + { 259 + struct thermal_zone_device **ptr; 260 + int ret; 261 + 262 + ptr = devres_alloc(devm_thermal_hwmon_release, sizeof(*ptr), 263 + GFP_KERNEL); 264 + if (!ptr) 265 + return -ENOMEM; 266 + 267 + ret = thermal_add_hwmon_sysfs(tz); 268 + if (ret) { 269 + devres_free(ptr); 270 + return ret; 271 + } 272 + 273 + *ptr = tz; 274 + devres_add(&tz->device, ptr); 275 + 276 + return ret; 277 + } 278 + EXPORT_SYMBOL_GPL(devm_thermal_add_hwmon_sysfs);
+7
drivers/thermal/thermal_hwmon.h
··· 17 17 18 18 #ifdef CONFIG_THERMAL_HWMON 19 19 int thermal_add_hwmon_sysfs(struct thermal_zone_device *tz); 20 + int devm_thermal_add_hwmon_sysfs(struct thermal_zone_device *tz); 20 21 void thermal_remove_hwmon_sysfs(struct thermal_zone_device *tz); 21 22 #else 22 23 static inline int 23 24 thermal_add_hwmon_sysfs(struct thermal_zone_device *tz) 25 + { 26 + return 0; 27 + } 28 + 29 + static inline int 30 + devm_thermal_add_hwmon_sysfs(struct thermal_zone_device *tz) 24 31 { 25 32 return 0; 26 33 }