broadband-modem-mbim: cleanup the subscriber info setup if enabling fails

If enabling the subscriber info notifications fails, we should no
longer have the setup for those notifications, so make sure it's
cleaned up on error.
This commit is contained in:
Aleksander Morgado
2020-09-18 11:26:03 +02:00
parent 5285720c48
commit 20176767ad

View File

@@ -3791,6 +3791,17 @@ modem_3gpp_enable_unsolicited_registration_events (MMIfaceModem3gpp *_self,
/*****************************************************************************/ /*****************************************************************************/
/* Setup SIM hot swap */ /* Setup SIM hot swap */
typedef struct {
MbimDevice *device;
} SetupSimHotSwapContext;
static void
setup_sim_hot_swap_context_free (SetupSimHotSwapContext *ctx)
{
g_clear_object (&ctx->device);
g_slice_free (SetupSimHotSwapContext, ctx);
}
static gboolean static gboolean
modem_setup_sim_hot_swap_finish (MMIfaceModem *self, modem_setup_sim_hot_swap_finish (MMIfaceModem *self,
GAsyncResult *res, GAsyncResult *res,
@@ -3801,13 +3812,19 @@ modem_setup_sim_hot_swap_finish (MMIfaceModem *self,
static void static void
enable_subscriber_info_unsolicited_events_ready (MMBroadbandModemMbim *self, enable_subscriber_info_unsolicited_events_ready (MMBroadbandModemMbim *self,
GAsyncResult *res, GAsyncResult *res,
GTask *task) GTask *task)
{ {
GError *error = NULL; GError *error = NULL;
SetupSimHotSwapContext *ctx;
ctx = g_task_get_task_data (task);
if (!common_enable_disable_unsolicited_events_finish (self, res, &error)) { if (!common_enable_disable_unsolicited_events_finish (self, res, &error)) {
mm_obj_dbg (self, "failed to enable subscriber info events: %s", error->message); mm_obj_dbg (self, "failed to enable subscriber info events: %s", error->message);
/* reset setup flags if enabling failed */
self->priv->setup_flags &= ~PROCESS_NOTIFICATION_FLAG_SUBSCRIBER_INFO;
common_setup_cleanup_unsolicited_events_sync (self, ctx->device, FALSE);
g_task_return_error (task, error); g_task_return_error (task, error);
g_object_unref (task); g_object_unref (task);
return; return;
@@ -3818,42 +3835,34 @@ enable_subscriber_info_unsolicited_events_ready (MMBroadbandModemMbim *self,
} }
static void static void
setup_subscriber_info_unsolicited_events_ready (MMBroadbandModemMbim *self, modem_setup_sim_hot_swap (MMIfaceModem *_self,
GAsyncResult *res, GAsyncReadyCallback callback,
GTask *task) gpointer user_data)
{ {
GError *error = NULL; MMBroadbandModemMbim *self = MM_BROADBAND_MODEM_MBIM (_self);
MbimDevice *device;
GTask *task;
SetupSimHotSwapContext *ctx;
if (!common_setup_cleanup_unsolicited_events_finish (self, res, &error)) { if (!peek_device (self, &device, callback, user_data))
mm_obj_dbg (self, "failed to set up subscriber info events: %s", error->message);
g_task_return_error (task, error);
g_object_unref (task);
return; return;
}
task = g_task_new (self, NULL, callback, user_data);
ctx = g_slice_new0 (SetupSimHotSwapContext);
ctx->device = g_object_ref (device);
g_task_set_task_data (task, ctx, (GDestroyNotify)setup_sim_hot_swap_context_free);
/* Setup flags synchronously, which never fails */
self->priv->setup_flags |= PROCESS_NOTIFICATION_FLAG_SUBSCRIBER_INFO;
common_setup_cleanup_unsolicited_events_sync (self, ctx->device, TRUE);
/* Enable flags asynchronously, which may fail */
self->priv->enable_flags |= PROCESS_NOTIFICATION_FLAG_SUBSCRIBER_INFO; self->priv->enable_flags |= PROCESS_NOTIFICATION_FLAG_SUBSCRIBER_INFO;
common_enable_disable_unsolicited_events (self, common_enable_disable_unsolicited_events (self,
(GAsyncReadyCallback)enable_subscriber_info_unsolicited_events_ready, (GAsyncReadyCallback)enable_subscriber_info_unsolicited_events_ready,
task); task);
} }
static void
modem_setup_sim_hot_swap (MMIfaceModem *_self,
GAsyncReadyCallback callback,
gpointer user_data)
{
MMBroadbandModemMbim *self = MM_BROADBAND_MODEM_MBIM (_self);
GTask *task;
task = g_task_new (self, NULL, callback, user_data);
self->priv->setup_flags |= PROCESS_NOTIFICATION_FLAG_SUBSCRIBER_INFO;
common_setup_cleanup_unsolicited_events (self,
TRUE,
(GAsyncReadyCallback)setup_subscriber_info_unsolicited_events_ready,
task);
}
/*****************************************************************************/ /*****************************************************************************/
/* Enable/Disable unsolicited events (3GPP interface) */ /* Enable/Disable unsolicited events (3GPP interface) */