Merge tag 'devfreq-next-for-6.8' of git://git.kernel.org/pub/scm/linux/kernel/git/chanwoo/linux into pm-devfreq
Merge devfreq updates for v6.8 from Chanwoo Choi:
"1. Fix buffer overflow of trans_stat_show sysfs node on devfreq core
- Fix buffer overflow of trans_stat_show sysfs node to replace
sprintf with scnprintf and then replace it with sysfs_emit
according to the syfs guide.
2. Fix the timer list corruption when frequent switching of governor
by synchronizing the devfreq_moniotr_start and _stop function."
* tag 'devfreq-next-for-6.8' of git://git.kernel.org/pub/scm/linux/kernel/git/chanwoo/linux:
PM / devfreq: Synchronize devfreq_monitor_[start/stop]
PM / devfreq: Convert to use sysfs_emit_at() API
PM / devfreq: Fix buffer overflow in trans_stat_show
This commit is contained in:
@@ -52,6 +52,9 @@ Description:
|
||||
|
||||
echo 0 > /sys/class/devfreq/.../trans_stat
|
||||
|
||||
If the transition table is bigger than PAGE_SIZE, reading
|
||||
this will return an -EFBIG error.
|
||||
|
||||
What: /sys/class/devfreq/.../available_frequencies
|
||||
Date: October 2012
|
||||
Contact: Nishanth Menon <nm@ti.com>
|
||||
|
||||
+64
-26
@@ -461,10 +461,14 @@ static void devfreq_monitor(struct work_struct *work)
|
||||
if (err)
|
||||
dev_err(&devfreq->dev, "dvfs failed with (%d) error\n", err);
|
||||
|
||||
if (devfreq->stop_polling)
|
||||
goto out;
|
||||
|
||||
queue_delayed_work(devfreq_wq, &devfreq->work,
|
||||
msecs_to_jiffies(devfreq->profile->polling_ms));
|
||||
mutex_unlock(&devfreq->lock);
|
||||
|
||||
out:
|
||||
mutex_unlock(&devfreq->lock);
|
||||
trace_devfreq_monitor(devfreq);
|
||||
}
|
||||
|
||||
@@ -483,6 +487,10 @@ void devfreq_monitor_start(struct devfreq *devfreq)
|
||||
if (IS_SUPPORTED_FLAG(devfreq->governor->flags, IRQ_DRIVEN))
|
||||
return;
|
||||
|
||||
mutex_lock(&devfreq->lock);
|
||||
if (delayed_work_pending(&devfreq->work))
|
||||
goto out;
|
||||
|
||||
switch (devfreq->profile->timer) {
|
||||
case DEVFREQ_TIMER_DEFERRABLE:
|
||||
INIT_DEFERRABLE_WORK(&devfreq->work, devfreq_monitor);
|
||||
@@ -491,12 +499,16 @@ void devfreq_monitor_start(struct devfreq *devfreq)
|
||||
INIT_DELAYED_WORK(&devfreq->work, devfreq_monitor);
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
goto out;
|
||||
}
|
||||
|
||||
if (devfreq->profile->polling_ms)
|
||||
queue_delayed_work(devfreq_wq, &devfreq->work,
|
||||
msecs_to_jiffies(devfreq->profile->polling_ms));
|
||||
|
||||
out:
|
||||
devfreq->stop_polling = false;
|
||||
mutex_unlock(&devfreq->lock);
|
||||
}
|
||||
EXPORT_SYMBOL(devfreq_monitor_start);
|
||||
|
||||
@@ -513,6 +525,14 @@ void devfreq_monitor_stop(struct devfreq *devfreq)
|
||||
if (IS_SUPPORTED_FLAG(devfreq->governor->flags, IRQ_DRIVEN))
|
||||
return;
|
||||
|
||||
mutex_lock(&devfreq->lock);
|
||||
if (devfreq->stop_polling) {
|
||||
mutex_unlock(&devfreq->lock);
|
||||
return;
|
||||
}
|
||||
|
||||
devfreq->stop_polling = true;
|
||||
mutex_unlock(&devfreq->lock);
|
||||
cancel_delayed_work_sync(&devfreq->work);
|
||||
}
|
||||
EXPORT_SYMBOL(devfreq_monitor_stop);
|
||||
@@ -1688,7 +1708,7 @@ static ssize_t trans_stat_show(struct device *dev,
|
||||
struct device_attribute *attr, char *buf)
|
||||
{
|
||||
struct devfreq *df = to_devfreq(dev);
|
||||
ssize_t len;
|
||||
ssize_t len = 0;
|
||||
int i, j;
|
||||
unsigned int max_state;
|
||||
|
||||
@@ -1697,7 +1717,7 @@ static ssize_t trans_stat_show(struct device *dev,
|
||||
max_state = df->max_state;
|
||||
|
||||
if (max_state == 0)
|
||||
return sprintf(buf, "Not Supported.\n");
|
||||
return sysfs_emit(buf, "Not Supported.\n");
|
||||
|
||||
mutex_lock(&df->lock);
|
||||
if (!df->stop_polling &&
|
||||
@@ -1707,31 +1727,49 @@ static ssize_t trans_stat_show(struct device *dev,
|
||||
}
|
||||
mutex_unlock(&df->lock);
|
||||
|
||||
len = sprintf(buf, " From : To\n");
|
||||
len += sprintf(buf + len, " :");
|
||||
for (i = 0; i < max_state; i++)
|
||||
len += sprintf(buf + len, "%10lu",
|
||||
df->freq_table[i]);
|
||||
|
||||
len += sprintf(buf + len, " time(ms)\n");
|
||||
|
||||
len += sysfs_emit_at(buf, len, " From : To\n");
|
||||
len += sysfs_emit_at(buf, len, " :");
|
||||
for (i = 0; i < max_state; i++) {
|
||||
if (df->freq_table[i] == df->previous_freq)
|
||||
len += sprintf(buf + len, "*");
|
||||
else
|
||||
len += sprintf(buf + len, " ");
|
||||
|
||||
len += sprintf(buf + len, "%10lu:", df->freq_table[i]);
|
||||
for (j = 0; j < max_state; j++)
|
||||
len += sprintf(buf + len, "%10u",
|
||||
df->stats.trans_table[(i * max_state) + j]);
|
||||
|
||||
len += sprintf(buf + len, "%10llu\n", (u64)
|
||||
jiffies64_to_msecs(df->stats.time_in_state[i]));
|
||||
if (len >= PAGE_SIZE - 1)
|
||||
break;
|
||||
len += sysfs_emit_at(buf, len, "%10lu",
|
||||
df->freq_table[i]);
|
||||
}
|
||||
|
||||
if (len >= PAGE_SIZE - 1)
|
||||
return PAGE_SIZE - 1;
|
||||
len += sysfs_emit_at(buf, len, " time(ms)\n");
|
||||
|
||||
for (i = 0; i < max_state; i++) {
|
||||
if (len >= PAGE_SIZE - 1)
|
||||
break;
|
||||
if (df->freq_table[2] == df->previous_freq)
|
||||
len += sysfs_emit_at(buf, len, "*");
|
||||
else
|
||||
len += sysfs_emit_at(buf, len, " ");
|
||||
if (len >= PAGE_SIZE - 1)
|
||||
break;
|
||||
len += sysfs_emit_at(buf, len, "%10lu:", df->freq_table[i]);
|
||||
for (j = 0; j < max_state; j++) {
|
||||
if (len >= PAGE_SIZE - 1)
|
||||
break;
|
||||
len += sysfs_emit_at(buf, len, "%10u",
|
||||
df->stats.trans_table[(i * max_state) + j]);
|
||||
}
|
||||
if (len >= PAGE_SIZE - 1)
|
||||
break;
|
||||
len += sysfs_emit_at(buf, len, "%10llu\n", (u64)
|
||||
jiffies64_to_msecs(df->stats.time_in_state[i]));
|
||||
}
|
||||
|
||||
if (len < PAGE_SIZE - 1)
|
||||
len += sysfs_emit_at(buf, len, "Total transition : %u\n",
|
||||
df->stats.total_trans);
|
||||
if (len >= PAGE_SIZE - 1) {
|
||||
pr_warn_once("devfreq transition table exceeds PAGE_SIZE. Disabling\n");
|
||||
return -EFBIG;
|
||||
}
|
||||
|
||||
len += sprintf(buf + len, "Total transition : %u\n",
|
||||
df->stats.total_trans);
|
||||
return len;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user