Skip to content

Commit 5fdded8

Browse files
Kant Fanchanwoochoi
authored andcommitted
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: ce26c5b ("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>
1 parent 094226a commit 5fdded8

3 files changed

Lines changed: 12 additions & 13 deletions

File tree

drivers/devfreq/devfreq.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -776,8 +776,7 @@ static void remove_sysfs_files(struct devfreq *devfreq,
776776
* @dev: the device to add devfreq feature.
777777
* @profile: device-specific profile to run devfreq.
778778
* @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.
781780
*/
782781
struct devfreq *devfreq_add_device(struct device *dev,
783782
struct devfreq_dev_profile *profile,
@@ -1011,8 +1010,7 @@ static void devm_devfreq_dev_release(struct device *dev, void *res)
10111010
* @dev: the device to add devfreq feature.
10121011
* @profile: device-specific profile to run devfreq.
10131012
* @governor_name: name of the policy to choose frequency.
1014-
* @data: private data for the governor. The devfreq framework does not
1015-
* touch this value.
1013+
* @data: devfreq driver pass to governors, governor should not change it.
10161014
*
10171015
* This function manages automatically the memory of devfreq device using device
10181016
* resource management and simplify the free operation for memory of devfreq

drivers/devfreq/governor_userspace.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ struct userspace_data {
2121

2222
static int devfreq_userspace_func(struct devfreq *df, unsigned long *freq)
2323
{
24-
struct userspace_data *data = df->data;
24+
struct userspace_data *data = df->governor_data;
2525

2626
if (data->valid)
2727
*freq = data->user_frequency;
@@ -40,7 +40,7 @@ static ssize_t set_freq_store(struct device *dev, struct device_attribute *attr,
4040
int err = 0;
4141

4242
mutex_lock(&devfreq->lock);
43-
data = devfreq->data;
43+
data = devfreq->governor_data;
4444

4545
sscanf(buf, "%lu", &wanted);
4646
data->user_frequency = wanted;
@@ -60,7 +60,7 @@ static ssize_t set_freq_show(struct device *dev,
6060
int err = 0;
6161

6262
mutex_lock(&devfreq->lock);
63-
data = devfreq->data;
63+
data = devfreq->governor_data;
6464

6565
if (data->valid)
6666
err = sprintf(buf, "%lu\n", data->user_frequency);
@@ -91,7 +91,7 @@ static int userspace_init(struct devfreq *devfreq)
9191
goto out;
9292
}
9393
data->valid = false;
94-
devfreq->data = data;
94+
devfreq->governor_data = data;
9595

9696
err = sysfs_create_group(&devfreq->dev.kobj, &dev_attr_group);
9797
out:
@@ -107,8 +107,8 @@ static void userspace_exit(struct devfreq *devfreq)
107107
if (devfreq->dev.kobj.sd)
108108
sysfs_remove_group(&devfreq->dev.kobj, &dev_attr_group);
109109

110-
kfree(devfreq->data);
111-
devfreq->data = NULL;
110+
kfree(devfreq->governor_data);
111+
devfreq->governor_data = NULL;
112112
}
113113

114114
static int devfreq_userspace_handler(struct devfreq *devfreq,

include/linux/devfreq.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -152,8 +152,8 @@ struct devfreq_stats {
152152
* @max_state: count of entry present in the frequency table.
153153
* @previous_freq: previously configured frequency value.
154154
* @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.
157157
* @user_min_freq_req: PM QoS minimum frequency request from user (via sysfs)
158158
* @user_max_freq_req: PM QoS maximum frequency request from user (via sysfs)
159159
* @scaling_min_freq: Limit minimum frequency requested by OPP interface
@@ -193,7 +193,8 @@ struct devfreq {
193193
unsigned long previous_freq;
194194
struct devfreq_dev_status last_status;
195195

196-
void *data; /* private data for governors */
196+
void *data;
197+
void *governor_data;
197198

198199
struct dev_pm_qos_request user_min_freq_req;
199200
struct dev_pm_qos_request user_max_freq_req;

0 commit comments

Comments
 (0)