summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAleksander Morgado <aleksander@aleksander.es>2019-12-31 15:40:13 +0100
committerAleksander Morgado <aleksander@aleksander.es>2019-12-31 16:15:37 +0100
commit45d3f05f3dea14e348cb43dea67ee56b0e80a77f (patch)
treec45fb60153940bc9910c59a224c53f2ddc70d92d
parente252f08e7f0a8d524e69c93182c2c027668b76b7 (diff)
downloadModemManager-45d3f05f3dea14e348cb43dea67ee56b0e80a77f.tar.gz
port-serial: un-schedule flash operation as soon as it's cancelled
When a flash operation is started, it is always scheduled in an idle. If this operation is cancelled, we should right away un-schedule it, otherwise we may end up calling flash_do() with the GTask in the private info already gone. See https://gitlab.freedesktop.org/mobile-broadband/ModemManager/merge_requests/178#note_330017 (cherry picked from commit 21e5b1d68336ec5a19f71e36c035e19d29623ca2)
-rw-r--r--src/mm-port-serial.c18
1 files changed, 14 insertions, 4 deletions
diff --git a/src/mm-port-serial.c b/src/mm-port-serial.c
index 052d0dd82..4762daf5f 100644
--- a/src/mm-port-serial.c
+++ b/src/mm-port-serial.c
@@ -1748,18 +1748,28 @@ flash_cancel_cb (GTask *task)
void
mm_port_serial_flash_cancel (MMPortSerial *self)
{
- GTask *task;
+ FlashContext *ctx;
+ GTask *task;
/* Do nothing if there is no flash task */
if (!self->priv->flash_task)
return;
- /* Recover task and schedule it to be cancelled in an idle.
+ /* Recover task */
+ task = self->priv->flash_task;
+ self->priv->flash_task = NULL;
+
+ /* If flash operation is scheduled, unschedule it */
+ ctx = g_task_get_task_data (task);
+ if (ctx->flash_id) {
+ g_source_remove (ctx->flash_id);
+ ctx->flash_id = 0;
+ }
+
+ /* Schedule task to be cancelled in an idle.
* We do NOT want this cancellation to happen right away,
* because the object reference in the flashing task may
* be the last one valid. */
- task = self->priv->flash_task;
- self->priv->flash_task = NULL;
g_idle_add ((GSourceFunc)flash_cancel_cb, task);
}