Skip to content

Commit

Permalink
PM / sleep: Fix test_suspend= command line option
Browse files Browse the repository at this point in the history
After commit d431cbc (PM / sleep: Simplify sleep states sysfs
interface code) the pm_states[] array is not populated initially,
which causes setup_test_suspend() to always fail and the suspend
testing during boot doesn't work any more.

Fix the problem by using pm_labels[] instead of pm_states[] in
setup_test_suspend() and storing a pointer to the label of the
sleep state to test rather than the number representing it,
because the connection between the state numbers and labels is
only established by suspend_set_ops().

Fixes: d431cbc (PM / sleep: Simplify sleep states sysfs interface code)
Reported-by: Srinivas Pandruvada <[email protected]>
Signed-off-by: Rafael J. Wysocki <[email protected]>
  • Loading branch information
rafaeljw committed Sep 2, 2014
1 parent 69e273c commit 62109b4
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 13 deletions.
1 change: 1 addition & 0 deletions kernel/power/power.h
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ extern void swsusp_show_speed(struct timeval *, struct timeval *,

#ifdef CONFIG_SUSPEND
/* kernel/power/suspend.c */
extern const char *pm_labels[];
extern const char *pm_states[];

extern int suspend_devices_and_enter(suspend_state_t state);
Expand Down
2 changes: 1 addition & 1 deletion kernel/power/suspend.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@

#include "power.h"

static const char *pm_labels[] = { "mem", "standby", "freeze", };
const char *pm_labels[] = { "mem", "standby", "freeze", NULL };
const char *pm_states[PM_SUSPEND_MAX];

static const struct platform_suspend_ops *suspend_ops;
Expand Down
31 changes: 19 additions & 12 deletions kernel/power/suspend_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -129,20 +129,20 @@ static int __init has_wakealarm(struct device *dev, const void *data)
* at startup time. They're normally disabled, for faster boot and because
* we can't know which states really work on this particular system.
*/
static suspend_state_t test_state __initdata = PM_SUSPEND_ON;
static const char *test_state_label __initdata;

static char warn_bad_state[] __initdata =
KERN_WARNING "PM: can't test '%s' suspend state\n";

static int __init setup_test_suspend(char *value)
{
suspend_state_t i;
int i;

/* "=mem" ==> "mem" */
value++;
for (i = PM_SUSPEND_MIN; i < PM_SUSPEND_MAX; i++)
if (!strcmp(pm_states[i], value)) {
test_state = i;
for (i = 0; pm_labels[i]; i++)
if (!strcmp(pm_labels[i], value)) {
test_state_label = pm_labels[i];
return 0;
}

Expand All @@ -158,13 +158,21 @@ static int __init test_suspend(void)

struct rtc_device *rtc = NULL;
struct device *dev;
suspend_state_t test_state;

/* PM is initialized by now; is that state testable? */
if (test_state == PM_SUSPEND_ON)
goto done;
if (!pm_states[test_state]) {
printk(warn_bad_state, pm_states[test_state]);
goto done;
if (!test_state_label)
return 0;

for (test_state = PM_SUSPEND_MIN; test_state < PM_SUSPEND_MAX; test_state++) {
const char *state_label = pm_states[test_state];

if (state_label && !strcmp(test_state_label, state_label))
break;
}
if (test_state == PM_SUSPEND_MAX) {
printk(warn_bad_state, test_state_label);
return 0;
}

/* RTCs have initialized by now too ... can we use one? */
Expand All @@ -173,13 +181,12 @@ static int __init test_suspend(void)
rtc = rtc_class_open(dev_name(dev));
if (!rtc) {
printk(warn_no_rtc);
goto done;
return 0;
}

/* go for it */
test_wakealarm(rtc, test_state);
rtc_class_close(rtc);
done:
return 0;
}
late_initcall(test_suspend);

0 comments on commit 62109b4

Please sign in to comment.