Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 5be60417 authored by Pavlin Radoslavov's avatar Pavlin Radoslavov
Browse files

Fix a crash triggered when firmware config takes too long

Fix a crash condition that is triggered when the firmware
configuration takes too long:
 1. The startup_timer expires, and it resets startup_future to NULL
 2. The delayed firmware_config_callback is received, and it
    tries to use the startup_future pointer (already set to NULL).

[Cherry-pick from AOSP]

Bug: 27336555
Change-Id: I4b04ca08a32c947f6f1eaabec7c4b099f96aab59
parent f6886e82
Loading
Loading
Loading
Loading
+15 −1
Original line number Diff line number Diff line
@@ -416,17 +416,31 @@ static void event_finish_startup(UNUSED_ATTR void *context) {

static void firmware_config_callback(UNUSED_ATTR bool success) {
  LOG_INFO(LOG_TAG, "%s", __func__);
  firmware_is_configured = true;

  alarm_cancel(startup_timer);

  pthread_mutex_lock(&commands_pending_response_lock);

  if (startup_future == NULL) {
    // The firmware configuration took too long - ignore the callback
    pthread_mutex_unlock(&commands_pending_response_lock);
    return;
  }

  firmware_is_configured = true;
  future_ready(startup_future, FUTURE_SUCCESS);
  startup_future = NULL;

  pthread_mutex_unlock(&commands_pending_response_lock);
}

static void startup_timer_expired(UNUSED_ATTR void *context) {
  LOG_ERROR(LOG_TAG, "%s", __func__);

  pthread_mutex_lock(&commands_pending_response_lock);
  future_ready(startup_future, FUTURE_FAIL);
  startup_future = NULL;
  pthread_mutex_unlock(&commands_pending_response_lock);
}

// Postload functions