Skip to content

Commit 27ddcc6

Browse files
committed
PM / sleep: Add state field to pm_states[] entries
To allow sleep states corresponding to the "mem", "standby" and "freeze" lables to be different from the pm_states[] indexes of those strings, introduce struct pm_sleep_state, consisting of a string label and a state number, and turn pm_states[] into an array of objects of that type. This modification should not lead to any functional changes. Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
1 parent f71495f commit 27ddcc6

File tree

4 files changed

+30
-27
lines changed

4 files changed

+30
-27
lines changed

kernel/power/main.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -293,12 +293,12 @@ static ssize_t state_show(struct kobject *kobj, struct kobj_attribute *attr,
293293
{
294294
char *s = buf;
295295
#ifdef CONFIG_SUSPEND
296-
int i;
296+
suspend_state_t i;
297+
298+
for (i = PM_SUSPEND_MIN; i < PM_SUSPEND_MAX; i++)
299+
if (valid_state(i))
300+
s += sprintf(s,"%s ", pm_states[i].label);
297301

298-
for (i = 0; i < PM_SUSPEND_MAX; i++) {
299-
if (pm_states[i] && valid_state(i))
300-
s += sprintf(s,"%s ", pm_states[i]);
301-
}
302302
#endif
303303
#ifdef CONFIG_HIBERNATION
304304
s += sprintf(s, "%s\n", "disk");
@@ -314,7 +314,7 @@ static suspend_state_t decode_state(const char *buf, size_t n)
314314
{
315315
#ifdef CONFIG_SUSPEND
316316
suspend_state_t state = PM_SUSPEND_MIN;
317-
const char * const *s;
317+
struct pm_sleep_state *s;
318318
#endif
319319
char *p;
320320
int len;
@@ -328,7 +328,7 @@ static suspend_state_t decode_state(const char *buf, size_t n)
328328

329329
#ifdef CONFIG_SUSPEND
330330
for (s = &pm_states[state]; state < PM_SUSPEND_MAX; s++, state++)
331-
if (*s && len == strlen(*s) && !strncmp(buf, *s, len))
331+
if (len == strlen(s->label) && !strncmp(buf, s->label, len))
332332
return state;
333333
#endif
334334

@@ -448,7 +448,7 @@ static ssize_t autosleep_show(struct kobject *kobj,
448448
#ifdef CONFIG_SUSPEND
449449
if (state < PM_SUSPEND_MAX)
450450
return sprintf(buf, "%s\n", valid_state(state) ?
451-
pm_states[state] : "error");
451+
pm_states[state].label : "error");
452452
#endif
453453
#ifdef CONFIG_HIBERNATION
454454
return sprintf(buf, "disk\n");

kernel/power/power.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,8 +178,13 @@ extern void swsusp_show_speed(struct timeval *, struct timeval *,
178178
unsigned int, char *);
179179

180180
#ifdef CONFIG_SUSPEND
181+
struct pm_sleep_state {
182+
const char *label;
183+
suspend_state_t state;
184+
};
185+
181186
/* kernel/power/suspend.c */
182-
extern const char *const pm_states[];
187+
extern struct pm_sleep_state pm_states[];
183188

184189
extern bool valid_state(suspend_state_t state);
185190
extern int suspend_devices_and_enter(suspend_state_t state);

kernel/power/suspend.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,10 @@
3131

3232
#include "power.h"
3333

34-
const char *const pm_states[PM_SUSPEND_MAX] = {
35-
[PM_SUSPEND_FREEZE] = "freeze",
36-
[PM_SUSPEND_STANDBY] = "standby",
37-
[PM_SUSPEND_MEM] = "mem",
34+
struct pm_sleep_state pm_states[PM_SUSPEND_MAX] = {
35+
[PM_SUSPEND_FREEZE] = { "freeze", PM_SUSPEND_FREEZE },
36+
[PM_SUSPEND_STANDBY] = { "standby", PM_SUSPEND_STANDBY },
37+
[PM_SUSPEND_MEM] = { "mem", PM_SUSPEND_MEM },
3838
};
3939

4040
static const struct platform_suspend_ops *suspend_ops;
@@ -343,15 +343,15 @@ static int enter_state(suspend_state_t state)
343343
sys_sync();
344344
printk("done.\n");
345345

346-
pr_debug("PM: Preparing system for %s sleep\n", pm_states[state]);
346+
pr_debug("PM: Preparing system for %s sleep\n", pm_states[state].label);
347347
error = suspend_prepare(state);
348348
if (error)
349349
goto Unlock;
350350

351351
if (suspend_test(TEST_FREEZER))
352352
goto Finish;
353353

354-
pr_debug("PM: Entering %s sleep\n", pm_states[state]);
354+
pr_debug("PM: Entering %s sleep\n", pm_states[state].label);
355355
pm_restrict_gfp_mask();
356356
error = suspend_devices_and_enter(state);
357357
pm_restore_gfp_mask();

kernel/power/suspend_test.c

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -92,13 +92,13 @@ static void __init test_wakealarm(struct rtc_device *rtc, suspend_state_t state)
9292
}
9393

9494
if (state == PM_SUSPEND_MEM) {
95-
printk(info_test, pm_states[state]);
95+
printk(info_test, pm_states[state].label);
9696
status = pm_suspend(state);
9797
if (status == -ENODEV)
9898
state = PM_SUSPEND_STANDBY;
9999
}
100100
if (state == PM_SUSPEND_STANDBY) {
101-
printk(info_test, pm_states[state]);
101+
printk(info_test, pm_states[state].label);
102102
status = pm_suspend(state);
103103
}
104104
if (status < 0)
@@ -136,18 +136,16 @@ static char warn_bad_state[] __initdata =
136136

137137
static int __init setup_test_suspend(char *value)
138138
{
139-
unsigned i;
139+
suspend_state_t i;
140140

141141
/* "=mem" ==> "mem" */
142142
value++;
143-
for (i = 0; i < PM_SUSPEND_MAX; i++) {
144-
if (!pm_states[i])
145-
continue;
146-
if (strcmp(pm_states[i], value) != 0)
147-
continue;
148-
test_state = (__force suspend_state_t) i;
149-
return 0;
150-
}
143+
for (i = PM_SUSPEND_MIN; i < PM_SUSPEND_MAX; i++)
144+
if (!strcmp(pm_states[i].label, value)) {
145+
test_state = pm_states[i].state;
146+
return 0;
147+
}
148+
151149
printk(warn_bad_state, value);
152150
return 0;
153151
}
@@ -165,7 +163,7 @@ static int __init test_suspend(void)
165163
if (test_state == PM_SUSPEND_ON)
166164
goto done;
167165
if (!valid_state(test_state)) {
168-
printk(warn_bad_state, pm_states[test_state]);
166+
printk(warn_bad_state, pm_states[test_state].label);
169167
goto done;
170168
}
171169

0 commit comments

Comments
 (0)