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

PM/devfreq: governor: Add a private governor_data for governor

The member void *data in the structure devfreq can be overwrite
by governor_userspace. For example:
1. The device driver assigned the devfreq governor to simple_ondemand
by the function devfreq_add_device() and init the devfreq member
void *data to a pointer of a static structure devfreq_simple_ondemand_data
by the function devfreq_add_device().
2. The user changed the devfreq governor to userspace by the command
"echo userspace > /sys/class/devfreq/.../governor".
3. The governor userspace alloced a dynamic memory for the struct
userspace_data and assigend the member void *data of devfreq to
this memory by the function userspace_init().
4. The user changed the devfreq governor back to simple_ondemand
by the command "echo simple_ondemand > /sys/class/devfreq/.../governor".
5. The governor userspace exited and assigned the member void *data
in the structure devfreq to NULL by the function userspace_exit().
6. The governor simple_ondemand fetched the static information of
devfreq_simple_ondemand_data in the function
devfreq_simple_ondemand_func() but the member void *data of devfreq was
assigned to NULL by the function userspace_exit().
7. The information of upthreshold and downdifferential is lost
and the governor simple_ondemand can't work correctly.

The member void *data in the structure devfreq is designed for
a static pointer used in a governor and inited by the function
devfreq_add_device(). This patch add an element named governor_data
in the devfreq structure which can be used by a governor(E.g userspace)
who want to assign a private data to do some private things.

Fixes: ce26c5bb9569 ("PM / devfreq: Add basic governors")
Cc: stable@vger.kernel.org # 5.10+
Reviewed-by: Chanwoo Choi <cwchoi00@gmail.com>
Acked-by: MyungJoo Ham <myungjoo.ham@samsung.com>
Signed-off-by: Kant Fan <kant@allwinnertech.com>
Signed-off-by: Chanwoo Choi <cw00.choi@samsung.com>

authored by

Kant Fan and committed by
Chanwoo Choi
5fdded84 094226ad

+12 -13
+2 -4
drivers/devfreq/devfreq.c
··· 776 776 * @dev: the device to add devfreq feature. 777 777 * @profile: device-specific profile to run devfreq. 778 778 * @governor_name: name of the policy to choose frequency. 779 - * @data: private data for the governor. The devfreq framework does not 780 - * touch this value. 779 + * @data: devfreq driver pass to governors, governor should not change it. 781 780 */ 782 781 struct devfreq *devfreq_add_device(struct device *dev, 783 782 struct devfreq_dev_profile *profile, ··· 1010 1011 * @dev: the device to add devfreq feature. 1011 1012 * @profile: device-specific profile to run devfreq. 1012 1013 * @governor_name: name of the policy to choose frequency. 1013 - * @data: private data for the governor. The devfreq framework does not 1014 - * touch this value. 1014 + * @data: devfreq driver pass to governors, governor should not change it. 1015 1015 * 1016 1016 * This function manages automatically the memory of devfreq device using device 1017 1017 * resource management and simplify the free operation for memory of devfreq
+6 -6
drivers/devfreq/governor_userspace.c
··· 21 21 22 22 static int devfreq_userspace_func(struct devfreq *df, unsigned long *freq) 23 23 { 24 - struct userspace_data *data = df->data; 24 + struct userspace_data *data = df->governor_data; 25 25 26 26 if (data->valid) 27 27 *freq = data->user_frequency; ··· 40 40 int err = 0; 41 41 42 42 mutex_lock(&devfreq->lock); 43 - data = devfreq->data; 43 + data = devfreq->governor_data; 44 44 45 45 sscanf(buf, "%lu", &wanted); 46 46 data->user_frequency = wanted; ··· 60 60 int err = 0; 61 61 62 62 mutex_lock(&devfreq->lock); 63 - data = devfreq->data; 63 + data = devfreq->governor_data; 64 64 65 65 if (data->valid) 66 66 err = sprintf(buf, "%lu\n", data->user_frequency); ··· 91 91 goto out; 92 92 } 93 93 data->valid = false; 94 - devfreq->data = data; 94 + devfreq->governor_data = data; 95 95 96 96 err = sysfs_create_group(&devfreq->dev.kobj, &dev_attr_group); 97 97 out: ··· 107 107 if (devfreq->dev.kobj.sd) 108 108 sysfs_remove_group(&devfreq->dev.kobj, &dev_attr_group); 109 109 110 - kfree(devfreq->data); 111 - devfreq->data = NULL; 110 + kfree(devfreq->governor_data); 111 + devfreq->governor_data = NULL; 112 112 } 113 113 114 114 static int devfreq_userspace_handler(struct devfreq *devfreq,
+4 -3
include/linux/devfreq.h
··· 152 152 * @max_state: count of entry present in the frequency table. 153 153 * @previous_freq: previously configured frequency value. 154 154 * @last_status: devfreq user device info, performance statistics 155 - * @data: Private data of the governor. The devfreq framework does not 156 - * touch this. 155 + * @data: devfreq driver pass to governors, governor should not change it. 156 + * @governor_data: private data for governors, devfreq core doesn't touch it. 157 157 * @user_min_freq_req: PM QoS minimum frequency request from user (via sysfs) 158 158 * @user_max_freq_req: PM QoS maximum frequency request from user (via sysfs) 159 159 * @scaling_min_freq: Limit minimum frequency requested by OPP interface ··· 193 193 unsigned long previous_freq; 194 194 struct devfreq_dev_status last_status; 195 195 196 - void *data; /* private data for governors */ 196 + void *data; 197 + void *governor_data; 197 198 198 199 struct dev_pm_qos_request user_min_freq_req; 199 200 struct dev_pm_qos_request user_max_freq_req;