diff options
author | Dominik Laskowski <domlaskowski@google.com> | 2022-11-22 13:59:53 -0500 |
---|---|---|
committer | Dominik Laskowski <domlaskowski@google.com> | 2022-12-09 16:18:19 -0500 |
commit | e63a592135f918583489ab1dbb6861f8f6c93956 (patch) | |
tree | e9ef34386a48e9da47320d3867f293eed071d702 | |
parent | 383832ff5b2390f3dcd44592db071d504268787d (diff) | |
download | native-e63a592135f918583489ab1dbb6861f8f6c93956.tar.gz |
SF: Do not deref empty std::optional<PowerMode>
In I3a2eae4efc4a5c6113700a9ca9e9b261e364a878, a display's power mode is
std::nullopt (unknown) until the first setPowerMode. The condition to
power on the display from that state relies on undefined behavior, as
it dereferences std::nullopt. It only works because PowerMode::OFF is
0 and the memory happens to be zeroed.
Bug: 250421145
Test: Boot
Change-Id: I0db8970b37da6eb308043157cd2ac7a9f6764294
Merged-In: I0db8970b37da6eb308043157cd2ac7a9f6764294
-rw-r--r-- | services/surfaceflinger/SurfaceFlinger.cpp | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/services/surfaceflinger/SurfaceFlinger.cpp b/services/surfaceflinger/SurfaceFlinger.cpp index 4486e33166..a701fe3475 100644 --- a/services/surfaceflinger/SurfaceFlinger.cpp +++ b/services/surfaceflinger/SurfaceFlinger.cpp @@ -4888,7 +4888,7 @@ void SurfaceFlinger::setPowerModeInternal(const sp<DisplayDevice>& display, hal: mInterceptor->savePowerModeUpdate(display->getSequenceId(), static_cast<int32_t>(mode)); } const auto refreshRate = display->refreshRateConfigs().getActiveMode()->getFps(); - if (*currentMode == hal::PowerMode::OFF) { + if (!currentMode || *currentMode == hal::PowerMode::OFF) { // Turn on the display if (display->isInternal() && (!activeDisplay || !activeDisplay->isPoweredOn())) { onActiveDisplayChangedLocked(display); |