diff options
author | Kyle Russell | 2012-11-19 15:29:58 -0600 |
---|---|---|
committer | Kyle Russell | 2012-11-20 08:12:39 -0600 |
commit | a26b4caf4cf5241e5c2145f53ec7170200ab4bb9 (patch) | |
tree | e9d17cc3f45fa420eb14c014a05e42ce9e228eea /libsuspend/autosuspend.c | |
parent | 3ddc0059bb897c4d7d2e0c6d9812d590388480d1 (diff) | |
download | platform-system-core-a26b4caf4cf5241e5c2145f53ec7170200ab4bb9.tar.gz platform-system-core-a26b4caf4cf5241e5c2145f53ec7170200ab4bb9.tar.xz platform-system-core-a26b4caf4cf5241e5c2145f53ec7170200ab4bb9.zip |
autosuspend_inited flag set even if initialization fails
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
Diffstat (limited to 'libsuspend/autosuspend.c')
-rw-r--r-- | libsuspend/autosuspend.c | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/libsuspend/autosuspend.c b/libsuspend/autosuspend.c index 7d1d97333..eb1f66e37 100644 --- a/libsuspend/autosuspend.c +++ b/libsuspend/autosuspend.c | |||
@@ -33,8 +33,6 @@ static int autosuspend_init(void) | |||
33 | return 0; | 33 | return 0; |
34 | } | 34 | } |
35 | 35 | ||
36 | autosuspend_inited = true; | ||
37 | |||
38 | autosuspend_ops = autosuspend_earlysuspend_init(); | 36 | autosuspend_ops = autosuspend_earlysuspend_init(); |
39 | if (autosuspend_ops) { | 37 | if (autosuspend_ops) { |
40 | goto out; | 38 | goto out; |
@@ -56,6 +54,8 @@ static int autosuspend_init(void) | |||
56 | } | 54 | } |
57 | 55 | ||
58 | out: | 56 | out: |
57 | autosuspend_inited = true; | ||
58 | |||
59 | ALOGV("autosuspend initialized\n"); | 59 | ALOGV("autosuspend initialized\n"); |
60 | return 0; | 60 | return 0; |
61 | } | 61 | } |