Blame SOURCES/0002-port-serial-un-schedule-flash-operation-as-soon-as-i.patch

0ff092
From 21e5b1d68336ec5a19f71e36c035e19d29623ca2 Mon Sep 17 00:00:00 2001
0ff092
From: Aleksander Morgado <aleksander@aleksander.es>
0ff092
Date: Tue, 31 Dec 2019 15:40:13 +0100
0ff092
Subject: [PATCH] port-serial: un-schedule flash operation as soon as it's
0ff092
 cancelled
0ff092
0ff092
When a flash operation is started, it is always scheduled in an idle.
0ff092
If this operation is cancelled, we should right away un-schedule it,
0ff092
otherwise we may end up calling flash_do() with the GTask in the
0ff092
private info already gone.
0ff092
0ff092
See https://gitlab.freedesktop.org/mobile-broadband/ModemManager/merge_requests/178#note_330017
0ff092
---
0ff092
 src/mm-port-serial.c | 18 ++++++++++++++----
0ff092
 1 file changed, 14 insertions(+), 4 deletions(-)
0ff092
0ff092
diff --git a/src/mm-port-serial.c b/src/mm-port-serial.c
0ff092
index 3101ce6e..6d5ee1b1 100644
0ff092
--- a/src/mm-port-serial.c
0ff092
+++ b/src/mm-port-serial.c
0ff092
@@ -1744,18 +1744,28 @@ flash_cancel_cb (GTask *task)
0ff092
 void
0ff092
 mm_port_serial_flash_cancel (MMPortSerial *self)
0ff092
 {
0ff092
-    GTask *task;
0ff092
+    FlashContext *ctx;
0ff092
+    GTask        *task;
0ff092
 
0ff092
     /* Do nothing if there is no flash task */
0ff092
     if (!self->priv->flash_task)
0ff092
         return;
0ff092
 
0ff092
-    /* Recover task and schedule it to be cancelled in an idle.
0ff092
+    /* Recover task */
0ff092
+    task = self->priv->flash_task;
0ff092
+    self->priv->flash_task = NULL;
0ff092
+
0ff092
+    /* If flash operation is scheduled, unschedule it */
0ff092
+    ctx = g_task_get_task_data (task);
0ff092
+    if (ctx->flash_id) {
0ff092
+        g_source_remove (ctx->flash_id);
0ff092
+        ctx->flash_id = 0;
0ff092
+    }
0ff092
+
0ff092
+    /* Schedule task to be cancelled in an idle.
0ff092
      * We do NOT want this cancellation to happen right away,
0ff092
      * because the object reference in the flashing task may
0ff092
      * be the last one valid. */
0ff092
-    task = self->priv->flash_task;
0ff092
-    self->priv->flash_task = NULL;
0ff092
     g_idle_add ((GSourceFunc)flash_cancel_cb, task);
0ff092
 }
0ff092
 
0ff092
-- 
0ff092
2.24.1
0ff092