iface-modem: don't fail enabling if modem_power_up() isn't implemented

There are modems (e.g. Nokia, Thuraya, Iridium) which don't require or
don't support power management, and therefore there is no way to
either load or update the power status.

In those modems we just assume ON is the current and only value (set
in the skeleton during initialization) and so when we attempt to
update the power state to ON during enabling, the logic should not
break.

Fix the logic by making sure the requested_power_setup() function
pointers are only checked for validity after ensuring we're not
already in the desired power state.

Fixes https://gitlab.freedesktop.org/mobile-broadband/ModemManager/-/issues/398
This commit is contained in:
Aleksander Morgado
2021-07-09 10:45:09 +02:00
parent 681d5d29d5
commit 63f3dcb2fe
+9 -8
View File
@@ -3872,6 +3872,15 @@ set_power_state_step (GTask *task)
case SET_POWER_STATE_STEP_UPDATE:
mm_obj_dbg (self, "updating power state: '%s'...", mm_modem_power_state_get_string (ctx->requested_power_state));
/* Error if unsupported */
if (!ctx->requested_power_setup || !ctx->requested_power_setup_finish) {
g_task_return_new_error (task, MM_CORE_ERROR, MM_CORE_ERROR_UNSUPPORTED,
"Requested power transition is not supported by this modem");
g_object_unref (task);
return;
}
ctx->requested_power_setup (self, (GAsyncReadyCallback)requested_power_setup_ready, task);
return;
@@ -3972,14 +3981,6 @@ mm_iface_modem_set_power_state (MMIfaceModem *self,
g_assert_not_reached ();
}
/* Error if unsupported */
if (!ctx->requested_power_setup || !ctx->requested_power_setup_finish) {
g_task_return_new_error (task, MM_CORE_ERROR, MM_CORE_ERROR_UNSUPPORTED,
"Requested power transition is not supported by this modem");
g_object_unref (task);
return;
}
set_power_state_step (task);
}