From c7a8b9d91642cb858862de613652aad5d21632be Mon Sep 17 00:00:00 2001 From: Eduardo Valentin Date: Tue, 23 Apr 2013 21:48:12 +0000 Subject: [PATCH 1/9] thermal: use strlcpy instead of strcpy For memory boundaries safety, use strlcpy instead of strcpy. Signed-off-by: Eduardo Valentin Signed-off-by: Zhang Rui --- drivers/thermal/thermal_core.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/thermal/thermal_core.c b/drivers/thermal/thermal_core.c index c0779adb2459..768ad312ba29 100644 --- a/drivers/thermal/thermal_core.c +++ b/drivers/thermal/thermal_core.c @@ -1301,7 +1301,7 @@ thermal_cooling_device_register(char *type, void *devdata, return ERR_PTR(result); } - strcpy(cdev->type, type ? : ""); + strlcpy(cdev->type, type ? : "", sizeof(cdev->type)); mutex_init(&cdev->lock); INIT_LIST_HEAD(&cdev->thermal_instances); cdev->ops = ops; @@ -1606,7 +1606,7 @@ struct thermal_zone_device *thermal_zone_device_register(const char *type, return ERR_PTR(result); } - strcpy(tz->type, type ? : ""); + strlcpy(tz->type, type ? : "", sizeof(tz->type)); tz->ops = ops; tz->tzp = tzp; tz->device.class = &thermal_class; From 6d8d4974a25db8b2c9be6ccc765765824e4781bd Mon Sep 17 00:00:00 2001 From: Eduardo Valentin Date: Tue, 23 Apr 2013 21:48:13 +0000 Subject: [PATCH 2/9] thermal: update driver license As per the comment at the top of this file, this is a GPLv2 driver. This patch updates the driver license accordingly. Signed-off-by: Eduardo Valentin Signed-off-by: Zhang Rui --- drivers/thermal/thermal_core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/thermal/thermal_core.c b/drivers/thermal/thermal_core.c index 768ad312ba29..a579c622f1a7 100644 --- a/drivers/thermal/thermal_core.c +++ b/drivers/thermal/thermal_core.c @@ -40,7 +40,7 @@ MODULE_AUTHOR("Zhang Rui"); MODULE_DESCRIPTION("Generic thermal management sysfs support"); -MODULE_LICENSE("GPL"); +MODULE_LICENSE("GPL v2"); static DEFINE_IDR(thermal_tz_idr); static DEFINE_IDR(thermal_cdev_idr); From 7b73c993776b9f7d833dde7d09fd861508c54777 Mon Sep 17 00:00:00 2001 From: Eduardo Valentin Date: Tue, 23 Apr 2013 21:48:14 +0000 Subject: [PATCH 3/9] thermal: rename notify_thermal_framework to thermal_notify_framework To follow the prefix names used by the thermal functions, this patch renames notify_thermal_framework to thermal_notify_framework. Signed-off-by: Eduardo Valentin Signed-off-by: Zhang Rui --- Documentation/thermal/sysfs-api.txt | 2 +- drivers/thermal/thermal_core.c | 6 +++--- include/linux/thermal.h | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Documentation/thermal/sysfs-api.txt b/Documentation/thermal/sysfs-api.txt index b2ffe98cf469..bb42266afc66 100644 --- a/Documentation/thermal/sysfs-api.txt +++ b/Documentation/thermal/sysfs-api.txt @@ -367,7 +367,7 @@ This function returns the thermal_instance corresponding to a given {thermal_zone, cooling_device, trip_point} combination. Returns NULL if such an instance does not exist. -5.3:notify_thermal_framework: +5.3:thermal_notify_framework: This function handles the trip events from sensor drivers. It starts throttling the cooling devices according to the policy configured. For CRITICAL and HOT trip points, this notifies the respective drivers, diff --git a/drivers/thermal/thermal_core.c b/drivers/thermal/thermal_core.c index a579c622f1a7..fb22ae51aac2 100644 --- a/drivers/thermal/thermal_core.c +++ b/drivers/thermal/thermal_core.c @@ -1432,7 +1432,7 @@ void thermal_cdev_update(struct thermal_cooling_device *cdev) EXPORT_SYMBOL(thermal_cdev_update); /** - * notify_thermal_framework - Sensor drivers use this API to notify framework + * thermal_notify_framework - Sensor drivers use this API to notify framework * @tz: thermal zone device * @trip: indicates which trip point has been crossed * @@ -1443,11 +1443,11 @@ EXPORT_SYMBOL(thermal_cdev_update); * The throttling policy is based on the configured platform data; if no * platform data is provided, this uses the step_wise throttling policy. */ -void notify_thermal_framework(struct thermal_zone_device *tz, int trip) +void thermal_notify_framework(struct thermal_zone_device *tz, int trip) { handle_thermal_trip(tz, trip); } -EXPORT_SYMBOL(notify_thermal_framework); +EXPORT_SYMBOL(thermal_notify_framework); /** * create_trip_attrs - create attributes for trip points diff --git a/include/linux/thermal.h b/include/linux/thermal.h index ec2b886f9d96..d7272ab20ebc 100644 --- a/include/linux/thermal.h +++ b/include/linux/thermal.h @@ -246,7 +246,7 @@ int get_tz_trend(struct thermal_zone_device *, int); struct thermal_instance *get_thermal_instance(struct thermal_zone_device *, struct thermal_cooling_device *, int); void thermal_cdev_update(struct thermal_cooling_device *); -void notify_thermal_framework(struct thermal_zone_device *, int); +void thermal_notify_framework(struct thermal_zone_device *, int); #ifdef CONFIG_NET extern int thermal_generate_netlink_event(struct thermal_zone_device *tz, From 910cb1e34d2fb8f9b5669a9fb452cbe1012251fe Mon Sep 17 00:00:00 2001 From: Eduardo Valentin Date: Tue, 23 Apr 2013 21:48:15 +0000 Subject: [PATCH 4/9] thermal: use EXPORT_SYMBOL_GPL Restrict usage of GPL modules. Signed-off-by: Eduardo Valentin Signed-off-by: Zhang Rui --- drivers/thermal/thermal_core.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/drivers/thermal/thermal_core.c b/drivers/thermal/thermal_core.c index fb22ae51aac2..eb3385edeacc 100644 --- a/drivers/thermal/thermal_core.c +++ b/drivers/thermal/thermal_core.c @@ -446,7 +446,7 @@ void thermal_zone_device_update(struct thermal_zone_device *tz) for (count = 0; count < tz->trips; count++) handle_thermal_trip(tz, count); } -EXPORT_SYMBOL(thermal_zone_device_update); +EXPORT_SYMBOL_GPL(thermal_zone_device_update); static void thermal_zone_device_check(struct work_struct *work) { @@ -1209,7 +1209,7 @@ free_mem: kfree(dev); return result; } -EXPORT_SYMBOL(thermal_zone_bind_cooling_device); +EXPORT_SYMBOL_GPL(thermal_zone_bind_cooling_device); /** * thermal_zone_unbind_cooling_device - unbind a cooling device from a thermal zone @@ -1249,7 +1249,7 @@ unbind: kfree(pos); return 0; } -EXPORT_SYMBOL(thermal_zone_unbind_cooling_device); +EXPORT_SYMBOL_GPL(thermal_zone_unbind_cooling_device); static void thermal_release(struct device *dev) { @@ -1346,7 +1346,7 @@ unregister: device_unregister(&cdev->device); return ERR_PTR(result); } -EXPORT_SYMBOL(thermal_cooling_device_register); +EXPORT_SYMBOL_GPL(thermal_cooling_device_register); /** * thermal_cooling_device_unregister - removes the registered thermal cooling device @@ -1406,7 +1406,7 @@ void thermal_cooling_device_unregister(struct thermal_cooling_device *cdev) device_unregister(&cdev->device); return; } -EXPORT_SYMBOL(thermal_cooling_device_unregister); +EXPORT_SYMBOL_GPL(thermal_cooling_device_unregister); void thermal_cdev_update(struct thermal_cooling_device *cdev) { @@ -1447,7 +1447,7 @@ void thermal_notify_framework(struct thermal_zone_device *tz, int trip) { handle_thermal_trip(tz, trip); } -EXPORT_SYMBOL(thermal_notify_framework); +EXPORT_SYMBOL_GPL(thermal_notify_framework); /** * create_trip_attrs - create attributes for trip points @@ -1699,7 +1699,7 @@ unregister: device_unregister(&tz->device); return ERR_PTR(result); } -EXPORT_SYMBOL(thermal_zone_device_register); +EXPORT_SYMBOL_GPL(thermal_zone_device_register); /** * thermal_device_unregister - removes the registered thermal zone device @@ -1766,7 +1766,7 @@ void thermal_zone_device_unregister(struct thermal_zone_device *tz) device_unregister(&tz->device); return; } -EXPORT_SYMBOL(thermal_zone_device_unregister); +EXPORT_SYMBOL_GPL(thermal_zone_device_unregister); /** * thermal_zone_get_zone_by_name() - search for a zone and returns its ref @@ -1882,7 +1882,7 @@ int thermal_generate_netlink_event(struct thermal_zone_device *tz, return result; } -EXPORT_SYMBOL(thermal_generate_netlink_event); +EXPORT_SYMBOL_GPL(thermal_generate_netlink_event); static int genetlink_init(void) { From d2e4eb83e7523c5b673ce3004d514c1d1ec32618 Mon Sep 17 00:00:00 2001 From: Eduardo Valentin Date: Tue, 23 Apr 2013 21:48:16 +0000 Subject: [PATCH 5/9] thermal: update kernel-doc for thermal_zone_bind_cooling_device This patch updates the documentation for thermal_zone_bind_cooling_device and removes the warnings generated by scripts/kernel-doc -v. Signed-off-by: Eduardo Valentin Signed-off-by: Zhang Rui --- drivers/thermal/thermal_core.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/drivers/thermal/thermal_core.c b/drivers/thermal/thermal_core.c index eb3385edeacc..5f6af8ade324 100644 --- a/drivers/thermal/thermal_core.c +++ b/drivers/thermal/thermal_core.c @@ -1109,13 +1109,23 @@ thermal_remove_hwmon_sysfs(struct thermal_zone_device *tz) #endif /** - * thermal_zone_bind_cooling_device - bind a cooling device to a thermal zone - * @tz: thermal zone device + * thermal_zone_bind_cooling_device() - bind a cooling device to a thermal zone + * @tz: pointer to struct thermal_zone_device * @trip: indicates which trip point the cooling devices is * associated with in this thermal zone. - * @cdev: thermal cooling device + * @cdev: pointer to struct thermal_cooling_device + * @upper: the Maximum cooling state for this trip point. + * THERMAL_NO_LIMIT means no upper limit, + * and the cooling device can be in max_state. + * @lower: the Minimum cooling state can be used for this trip point. + * THERMAL_NO_LIMIT means no lower limit, + * and the cooling device can be in cooling state 0. * + * This interface function bind a thermal cooling device to the certain trip + * point of a thermal zone device. * This function is usually called in the thermal zone device .bind callback. + * + * Return: 0 on success, the proper error value otherwise. */ int thermal_zone_bind_cooling_device(struct thermal_zone_device *tz, int trip, From 9892e5dc56f185d104e6dddd1e2d0f6ae8f4f211 Mon Sep 17 00:00:00 2001 From: Eduardo Valentin Date: Tue, 23 Apr 2013 21:48:17 +0000 Subject: [PATCH 6/9] thermal: update kernel-doc for thermal_zone_unbind_cooling_device This patch updates the documentation for thermal_zone_unbind_cooling_device and removes the warnings generated by scripts/kernel-doc -v. Signed-off-by: Eduardo Valentin Signed-off-by: Zhang Rui --- drivers/thermal/thermal_core.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/drivers/thermal/thermal_core.c b/drivers/thermal/thermal_core.c index 5f6af8ade324..9550e6897114 100644 --- a/drivers/thermal/thermal_core.c +++ b/drivers/thermal/thermal_core.c @@ -1222,13 +1222,18 @@ free_mem: EXPORT_SYMBOL_GPL(thermal_zone_bind_cooling_device); /** - * thermal_zone_unbind_cooling_device - unbind a cooling device from a thermal zone - * @tz: thermal zone device + * thermal_zone_unbind_cooling_device() - unbind a cooling device from a + * thermal zone. + * @tz: pointer to a struct thermal_zone_device. * @trip: indicates which trip point the cooling devices is * associated with in this thermal zone. - * @cdev: thermal cooling device + * @cdev: pointer to a struct thermal_cooling_device. * + * This interface function unbind a thermal cooling device from the certain + * trip point of a thermal zone device. * This function is usually called in the thermal zone device .unbind callback. + * + * Return: 0 on success, the proper error value otherwise. */ int thermal_zone_unbind_cooling_device(struct thermal_zone_device *tz, int trip, From 3a6eccb35219a7cfa7c7bbac16aa344d4a336fd4 Mon Sep 17 00:00:00 2001 From: Eduardo Valentin Date: Tue, 23 Apr 2013 21:48:18 +0000 Subject: [PATCH 7/9] thermal: update kernel-doc for thermal_cooling_device_register This patch updates the documentation for thermal_cooling_device_register and removes the warnings generated by scripts/kernel-doc -v. Signed-off-by: Eduardo Valentin Signed-off-by: Zhang Rui --- drivers/thermal/thermal_core.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/drivers/thermal/thermal_core.c b/drivers/thermal/thermal_core.c index 9550e6897114..15220f9c849f 100644 --- a/drivers/thermal/thermal_core.c +++ b/drivers/thermal/thermal_core.c @@ -1287,10 +1287,17 @@ static struct class thermal_class = { }; /** - * thermal_cooling_device_register - register a new thermal cooling device + * thermal_cooling_device_register() - register a new thermal cooling device * @type: the thermal cooling device type. * @devdata: device private data. * @ops: standard thermal cooling devices callbacks. + * + * This interface function adds a new thermal cooling device (fan/processor/...) + * to /sys/class/thermal/ folder as cooling_device[0-*]. It tries to bind itself + * to all the thermal zone devices registered at the same time. + * + * Return: a pointer to the created struct thermal_cooling_device or an + * ERR_PTR. Caller must check return value with IS_ERR*() helpers. */ struct thermal_cooling_device * thermal_cooling_device_register(char *type, void *devdata, From 269c174f27d2753ae809b86c9fbf5a8743a1c065 Mon Sep 17 00:00:00 2001 From: Eduardo Valentin Date: Tue, 23 Apr 2013 21:48:19 +0000 Subject: [PATCH 8/9] thermal: update kernel-doc for create_trip_attrs This patch updates the documentation for create_trip_attrs and removes the warnings generated by scripts/kernel-doc -v. Signed-off-by: Eduardo Valentin Signed-off-by: Zhang Rui --- drivers/thermal/thermal_core.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/drivers/thermal/thermal_core.c b/drivers/thermal/thermal_core.c index 15220f9c849f..9c653c607b2a 100644 --- a/drivers/thermal/thermal_core.c +++ b/drivers/thermal/thermal_core.c @@ -1472,9 +1472,14 @@ void thermal_notify_framework(struct thermal_zone_device *tz, int trip) EXPORT_SYMBOL_GPL(thermal_notify_framework); /** - * create_trip_attrs - create attributes for trip points + * create_trip_attrs() - create attributes for trip points * @tz: the thermal zone device * @mask: Writeable trip point bitmap. + * + * helper function to instantiate sysfs entries for every trip + * point and its properties of a struct thermal_zone_device. + * + * Return: 0 on success, the proper error value otherwise. */ static int create_trip_attrs(struct thermal_zone_device *tz, int mask) { From a00e55f9c8c06e2bba5db5f2e7dec16b86d560ec Mon Sep 17 00:00:00 2001 From: Eduardo Valentin Date: Tue, 23 Apr 2013 21:48:20 +0000 Subject: [PATCH 9/9] thermal: update kernel-doc for thermal_zone_device_register This patch updates the documentation for thermal_zone_device_register and removes the warnings generated by scripts/kernel-doc -v. Signed-off-by: Eduardo Valentin Signed-off-by: Zhang Rui --- drivers/thermal/thermal_core.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/drivers/thermal/thermal_core.c b/drivers/thermal/thermal_core.c index 9c653c607b2a..f36cd44816d8 100644 --- a/drivers/thermal/thermal_core.c +++ b/drivers/thermal/thermal_core.c @@ -1580,7 +1580,7 @@ static void remove_trip_attrs(struct thermal_zone_device *tz) } /** - * thermal_zone_device_register - register a new thermal zone device + * thermal_zone_device_register() - register a new thermal zone device * @type: the thermal zone device type * @trips: the number of trip points the thermal zone support * @mask: a bit string indicating the writeablility of trip points @@ -1593,8 +1593,15 @@ static void remove_trip_attrs(struct thermal_zone_device *tz) * whether trip points have been crossed (0 for interrupt * driven systems) * + * This interface function adds a new thermal zone device (sensor) to + * /sys/class/thermal folder as thermal_zone[0-*]. It tries to bind all the + * thermal cooling devices registered at the same time. * thermal_zone_device_unregister() must be called when the device is no * longer needed. The passive cooling depends on the .get_trend() return value. + * + * Return: a pointer to the created struct thermal_zone_device or an + * in case of error, an ERR_PTR. Caller must check return value with + * IS_ERR*() helpers. */ struct thermal_zone_device *thermal_zone_device_register(const char *type, int trips, int mask, void *devdata,