aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLaxman Dewangan <ldewangan@nvidia.com>2016-03-09 08:10:06 -0500
committerEduardo Valentin <edubezval@gmail.com>2016-03-09 13:31:20 -0500
commite498b4984db82b4ba3ceea7dba813222a31e9c2e (patch)
tree5ce061bc5e4c485d6b9aa1a9ce47144fec68e986
parent3a7fd9c737e2c124d20c351529316d71962cf6ca (diff)
thermal: of-thermal: Add devm version of thermal_zone_of_sensor_register
Add resource managed version of thermal_zone_of_sensor_register() and thermal_zone_of_sensor_unregister(). This helps in reducing the code size in error path, remove of driver remove callbacks and making proper sequence for deallocations. Signed-off-by: Laxman Dewangan <ldewangan@nvidia.com> Signed-off-by: Eduardo Valentin <edubezval@gmail.com>
-rw-r--r--drivers/thermal/of-thermal.c81
-rw-r--r--include/linux/thermal.h18
2 files changed, 99 insertions, 0 deletions
diff --git a/drivers/thermal/of-thermal.c b/drivers/thermal/of-thermal.c
index 9043f8f91852..49ac23d3e776 100644
--- a/drivers/thermal/of-thermal.c
+++ b/drivers/thermal/of-thermal.c
@@ -555,6 +555,87 @@ void thermal_zone_of_sensor_unregister(struct device *dev,
555} 555}
556EXPORT_SYMBOL_GPL(thermal_zone_of_sensor_unregister); 556EXPORT_SYMBOL_GPL(thermal_zone_of_sensor_unregister);
557 557
558static void devm_thermal_zone_of_sensor_release(struct device *dev, void *res)
559{
560 thermal_zone_of_sensor_unregister(dev,
561 *(struct thermal_zone_device **)res);
562}
563
564static int devm_thermal_zone_of_sensor_match(struct device *dev, void *res,
565 void *data)
566{
567 struct thermal_zone_device **r = res;
568
569 if (WARN_ON(!r || !*r))
570 return 0;
571
572 return *r == data;
573}
574
575/**
576 * devm_thermal_zone_of_sensor_register - Resource managed version of
577 * thermal_zone_of_sensor_register()
578 * @dev: a valid struct device pointer of a sensor device. Must contain
579 * a valid .of_node, for the sensor node.
580 * @sensor_id: a sensor identifier, in case the sensor IP has more
581 * than one sensors
582 * @data: a private pointer (owned by the caller) that will be passed
583 * back, when a temperature reading is needed.
584 * @ops: struct thermal_zone_of_device_ops *. Must contain at least .get_temp.
585 *
586 * Refer thermal_zone_of_sensor_register() for more details.
587 *
588 * Return: On success returns a valid struct thermal_zone_device,
589 * otherwise, it returns a corresponding ERR_PTR(). Caller must
590 * check the return value with help of IS_ERR() helper.
591 * Registered hermal_zone_device device will automatically be
592 * released when device is unbounded.
593 */
594struct thermal_zone_device *devm_thermal_zone_of_sensor_register(
595 struct device *dev, int sensor_id,
596 void *data, const struct thermal_zone_of_device_ops *ops)
597{
598 struct thermal_zone_device **ptr, *tzd;
599
600 ptr = devres_alloc(devm_thermal_zone_of_sensor_release, sizeof(*ptr),
601 GFP_KERNEL);
602 if (!ptr)
603 return ERR_PTR(-ENOMEM);
604
605 tzd = thermal_zone_of_sensor_register(dev, sensor_id, data, ops);
606 if (IS_ERR(tzd)) {
607 devres_free(ptr);
608 return tzd;
609 }
610
611 *ptr = tzd;
612 devres_add(dev, ptr);
613
614 return tzd;
615}
616EXPORT_SYMBOL_GPL(devm_thermal_zone_of_sensor_register);
617
618/**
619 * devm_thermal_zone_of_sensor_unregister - Resource managed version of
620 * thermal_zone_of_sensor_unregister().
621 * @dev: Device for which which resource was allocated.
622 * @tzd: a pointer to struct thermal_zone_device where the sensor is registered.
623 *
624 * This function removes the sensor callbacks and private data from the
625 * thermal zone device registered with devm_thermal_zone_of_sensor_register()
626 * API. It will also silent the zone by remove the .get_temp() and .get_trend()
627 * thermal zone device callbacks.
628 * Normally this function will not need to be called and the resource
629 * management code will ensure that the resource is freed.
630 */
631void devm_thermal_zone_of_sensor_unregister(struct device *dev,
632 struct thermal_zone_device *tzd)
633{
634 WARN_ON(devres_release(dev, devm_thermal_zone_of_sensor_release,
635 devm_thermal_zone_of_sensor_match, tzd));
636}
637EXPORT_SYMBOL_GPL(devm_thermal_zone_of_sensor_unregister);
638
558/*** functions parsing device tree nodes ***/ 639/*** functions parsing device tree nodes ***/
559 640
560/** 641/**
diff --git a/include/linux/thermal.h b/include/linux/thermal.h
index e13a1ace50e9..9c481991fdc7 100644
--- a/include/linux/thermal.h
+++ b/include/linux/thermal.h
@@ -362,6 +362,11 @@ thermal_zone_of_sensor_register(struct device *dev, int id, void *data,
362 const struct thermal_zone_of_device_ops *ops); 362 const struct thermal_zone_of_device_ops *ops);
363void thermal_zone_of_sensor_unregister(struct device *dev, 363void thermal_zone_of_sensor_unregister(struct device *dev,
364 struct thermal_zone_device *tz); 364 struct thermal_zone_device *tz);
365struct thermal_zone_device *devm_thermal_zone_of_sensor_register(
366 struct device *dev, int id, void *data,
367 const struct thermal_zone_of_device_ops *ops);
368void devm_thermal_zone_of_sensor_unregister(struct device *dev,
369 struct thermal_zone_device *tz);
365#else 370#else
366static inline struct thermal_zone_device * 371static inline struct thermal_zone_device *
367thermal_zone_of_sensor_register(struct device *dev, int id, void *data, 372thermal_zone_of_sensor_register(struct device *dev, int id, void *data,
@@ -376,6 +381,19 @@ void thermal_zone_of_sensor_unregister(struct device *dev,
376{ 381{
377} 382}
378 383
384static inline struct thermal_zone_device *devm_thermal_zone_of_sensor_register(
385 struct device *dev, int id, void *data,
386 const struct thermal_zone_of_device_ops *ops)
387{
388 return ERR_PTR(-ENODEV);
389}
390
391static inline
392void devm_thermal_zone_of_sensor_unregister(struct device *dev,
393 struct thermal_zone_device *tz)
394{
395}
396
379#endif 397#endif
380 398
381#if IS_ENABLED(CONFIG_THERMAL) 399#if IS_ENABLED(CONFIG_THERMAL)