Skip to content
This repository has been archived by the owner on Nov 8, 2023. It is now read-only.

Commit

Permalink
autosuspend_inited flag set even if initialization fails
Browse files Browse the repository at this point in the history
Prevents possible SIGSEGV on second autosuspend_enable attempt when
first intialization attempt fails.  autosuspend_inited should only
be set once autosuspend_ops has been assigned.

Consider the first call to autosuspend_enable().
autosuspend_init() sets its inited flag to true, and attempts to
set autosuspend_ops.  If all the other autosuspend_*_init() attempts
fail, autosuspend_init() returns -1, which autosuspend_enable()
will return as a failure.  A second call to autosuspend_enable()
will check autosuspend_init() and see that autosuspend has already
been initialized.  It will attempt to access autosuspend_ops, which
were not set in the first initialization attempt, causing a SIGSEGV.

Change-Id: Ib2d3ee62fee4c3b6d0323e5b7f3709a23c6b923f
  • Loading branch information
bkylerussell committed Nov 20, 2012
1 parent 3ddc005 commit a26b4ca
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions libsuspend/autosuspend.c
Expand Up @@ -33,8 +33,6 @@ static int autosuspend_init(void)
return 0;
}

autosuspend_inited = true;

autosuspend_ops = autosuspend_earlysuspend_init();
if (autosuspend_ops) {
goto out;
Expand All @@ -56,6 +54,8 @@ static int autosuspend_init(void)
}

out:
autosuspend_inited = true;

ALOGV("autosuspend initialized\n");
return 0;
}
Expand Down

0 comments on commit a26b4ca

Please sign in to comment.