Skip to content

Commit 483d557

Browse files
committed
PM / devfreq: Clean up the devfreq instance name in sysfs attr
The sysfs attr interface used eithere 'df' or 'devfreq' for devfreq instance name. In order to keep the consistency and to improve the readabilty, unify the instance name as 'df'. Add add the missing conditional statement to prevent the fault. Signed-off-by: Chanwoo Choi <[email protected]>
1 parent 4fc9a04 commit 483d557

File tree

1 file changed

+60
-34
lines changed

1 file changed

+60
-34
lines changed

drivers/devfreq/devfreq.c

Lines changed: 60 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1280,18 +1280,20 @@ EXPORT_SYMBOL(devfreq_remove_governor);
12801280
static ssize_t name_show(struct device *dev,
12811281
struct device_attribute *attr, char *buf)
12821282
{
1283-
struct devfreq *devfreq = to_devfreq(dev);
1284-
return sprintf(buf, "%s\n", dev_name(devfreq->dev.parent));
1283+
struct devfreq *df = to_devfreq(dev);
1284+
return sprintf(buf, "%s\n", dev_name(df->dev.parent));
12851285
}
12861286
static DEVICE_ATTR_RO(name);
12871287

12881288
static ssize_t governor_show(struct device *dev,
12891289
struct device_attribute *attr, char *buf)
12901290
{
1291-
if (!to_devfreq(dev)->governor)
1291+
struct devfreq *df = to_devfreq(dev);
1292+
1293+
if (!df->governor)
12921294
return -EINVAL;
12931295

1294-
return sprintf(buf, "%s\n", to_devfreq(dev)->governor->name);
1296+
return sprintf(buf, "%s\n", df->governor->name);
12951297
}
12961298

12971299
static ssize_t governor_store(struct device *dev, struct device_attribute *attr,
@@ -1302,6 +1304,9 @@ static ssize_t governor_store(struct device *dev, struct device_attribute *attr,
13021304
char str_governor[DEVFREQ_NAME_LEN + 1];
13031305
const struct devfreq_governor *governor, *prev_governor;
13041306

1307+
if (!df->governor)
1308+
return -EINVAL;
1309+
13051310
ret = sscanf(buf, "%" __stringify(DEVFREQ_NAME_LEN) "s", str_governor);
13061311
if (ret != 1)
13071312
return -EINVAL;
@@ -1315,20 +1320,18 @@ static ssize_t governor_store(struct device *dev, struct device_attribute *attr,
13151320
if (df->governor == governor) {
13161321
ret = 0;
13171322
goto out;
1318-
} else if ((df->governor && df->governor->immutable) ||
1319-
governor->immutable) {
1323+
} else if (df->governor->immutable || governor->immutable) {
13201324
ret = -EINVAL;
13211325
goto out;
13221326
}
13231327

1324-
if (df->governor) {
1325-
ret = df->governor->event_handler(df, DEVFREQ_GOV_STOP, NULL);
1326-
if (ret) {
1327-
dev_warn(dev, "%s: Governor %s not stopped(%d)\n",
1328-
__func__, df->governor->name, ret);
1329-
goto out;
1330-
}
1328+
ret = df->governor->event_handler(df, DEVFREQ_GOV_STOP, NULL);
1329+
if (ret) {
1330+
dev_warn(dev, "%s: Governor %s not stopped(%d)\n",
1331+
__func__, df->governor->name, ret);
1332+
goto out;
13311333
}
1334+
13321335
prev_governor = df->governor;
13331336
df->governor = governor;
13341337
strncpy(df->governor_name, governor->name, DEVFREQ_NAME_LEN);
@@ -1363,13 +1366,16 @@ static ssize_t available_governors_show(struct device *d,
13631366
struct devfreq *df = to_devfreq(d);
13641367
ssize_t count = 0;
13651368

1369+
if (!df->governor)
1370+
return -EINVAL;
1371+
13661372
mutex_lock(&devfreq_list_lock);
13671373

13681374
/*
13691375
* The devfreq with immutable governor (e.g., passive) shows
13701376
* only own governor.
13711377
*/
1372-
if (df->governor && df->governor->immutable) {
1378+
if (df->governor->immutable) {
13731379
count = scnprintf(&buf[count], DEVFREQ_NAME_LEN,
13741380
"%s ", df->governor_name);
13751381
/*
@@ -1403,27 +1409,37 @@ static ssize_t cur_freq_show(struct device *dev, struct device_attribute *attr,
14031409
char *buf)
14041410
{
14051411
unsigned long freq;
1406-
struct devfreq *devfreq = to_devfreq(dev);
1412+
struct devfreq *df = to_devfreq(dev);
14071413

1408-
if (devfreq->profile->get_cur_freq &&
1409-
!devfreq->profile->get_cur_freq(devfreq->dev.parent, &freq))
1414+
if (!df->profile)
1415+
return -EINVAL;
1416+
1417+
if (df->profile->get_cur_freq &&
1418+
!df->profile->get_cur_freq(df->dev.parent, &freq))
14101419
return sprintf(buf, "%lu\n", freq);
14111420

1412-
return sprintf(buf, "%lu\n", devfreq->previous_freq);
1421+
return sprintf(buf, "%lu\n", df->previous_freq);
14131422
}
14141423
static DEVICE_ATTR_RO(cur_freq);
14151424

14161425
static ssize_t target_freq_show(struct device *dev,
14171426
struct device_attribute *attr, char *buf)
14181427
{
1419-
return sprintf(buf, "%lu\n", to_devfreq(dev)->previous_freq);
1428+
struct devfreq *df = to_devfreq(dev);
1429+
1430+
return sprintf(buf, "%lu\n", df->previous_freq);
14201431
}
14211432
static DEVICE_ATTR_RO(target_freq);
14221433

14231434
static ssize_t polling_interval_show(struct device *dev,
14241435
struct device_attribute *attr, char *buf)
14251436
{
1426-
return sprintf(buf, "%d\n", to_devfreq(dev)->profile->polling_ms);
1437+
struct devfreq *df = to_devfreq(dev);
1438+
1439+
if (!df->profile)
1440+
return -EINVAL;
1441+
1442+
return sprintf(buf, "%d\n", df->profile->polling_ms);
14271443
}
14281444

14291445
static ssize_t polling_interval_store(struct device *dev,
@@ -1551,6 +1567,9 @@ static ssize_t available_frequencies_show(struct device *d,
15511567
ssize_t count = 0;
15521568
int i;
15531569

1570+
if (!df->profile)
1571+
return -EINVAL;
1572+
15541573
mutex_lock(&df->lock);
15551574

15561575
for (i = 0; i < df->profile->max_state; i++)
@@ -1571,49 +1590,53 @@ static DEVICE_ATTR_RO(available_frequencies);
15711590
static ssize_t trans_stat_show(struct device *dev,
15721591
struct device_attribute *attr, char *buf)
15731592
{
1574-
struct devfreq *devfreq = to_devfreq(dev);
1593+
struct devfreq *df = to_devfreq(dev);
15751594
ssize_t len;
15761595
int i, j;
1577-
unsigned int max_state = devfreq->profile->max_state;
1596+
unsigned int max_state;
1597+
1598+
if (!df->profile)
1599+
return -EINVAL;
1600+
max_state = df->profile->max_state;
15781601

15791602
if (max_state == 0)
15801603
return sprintf(buf, "Not Supported.\n");
15811604

1582-
mutex_lock(&devfreq->lock);
1583-
if (!devfreq->stop_polling &&
1584-
devfreq_update_status(devfreq, devfreq->previous_freq)) {
1585-
mutex_unlock(&devfreq->lock);
1605+
mutex_lock(&df->lock);
1606+
if (!df->stop_polling &&
1607+
devfreq_update_status(df, df->previous_freq)) {
1608+
mutex_unlock(&df->lock);
15861609
return 0;
15871610
}
1588-
mutex_unlock(&devfreq->lock);
1611+
mutex_unlock(&df->lock);
15891612

15901613
len = sprintf(buf, " From : To\n");
15911614
len += sprintf(buf + len, " :");
15921615
for (i = 0; i < max_state; i++)
15931616
len += sprintf(buf + len, "%10lu",
1594-
devfreq->profile->freq_table[i]);
1617+
df->profile->freq_table[i]);
15951618

15961619
len += sprintf(buf + len, " time(ms)\n");
15971620

15981621
for (i = 0; i < max_state; i++) {
1599-
if (devfreq->profile->freq_table[i]
1600-
== devfreq->previous_freq) {
1622+
if (df->profile->freq_table[i]
1623+
== df->previous_freq) {
16011624
len += sprintf(buf + len, "*");
16021625
} else {
16031626
len += sprintf(buf + len, " ");
16041627
}
16051628
len += sprintf(buf + len, "%10lu:",
1606-
devfreq->profile->freq_table[i]);
1629+
df->profile->freq_table[i]);
16071630
for (j = 0; j < max_state; j++)
16081631
len += sprintf(buf + len, "%10u",
1609-
devfreq->stats.trans_table[(i * max_state) + j]);
1632+
df->stats.trans_table[(i * max_state) + j]);
16101633

16111634
len += sprintf(buf + len, "%10llu\n", (u64)
1612-
jiffies64_to_msecs(devfreq->stats.time_in_state[i]));
1635+
jiffies64_to_msecs(df->stats.time_in_state[i]));
16131636
}
16141637

16151638
len += sprintf(buf + len, "Total transition : %u\n",
1616-
devfreq->stats.total_trans);
1639+
df->stats.total_trans);
16171640
return len;
16181641
}
16191642

@@ -1624,6 +1647,9 @@ static ssize_t trans_stat_store(struct device *dev,
16241647
struct devfreq *df = to_devfreq(dev);
16251648
int err, value;
16261649

1650+
if (!df->profile)
1651+
return -EINVAL;
1652+
16271653
if (df->profile->max_state == 0)
16281654
return count;
16291655

0 commit comments

Comments
 (0)