From 2ad2f4736ed033be3f34f7a7674aab1b15ffa5d5 Mon Sep 17 00:00:00 2001 From: Simo Piiroinen Date: Wed, 28 Mar 2018 12:21:14 +0300 Subject: [PATCH] [config] Do not switch from undefined mode to charging fallback. JB#41302 USB mode white-list configuration can get applied via D-Bus during bootup. This requires re-evaluation of the currently active usb mode - which misfires when nothing is connected to usb port and usb mode gets changed from undefined to charging fallback (= charging from pc). Add explicit check for undefined usb mode. Signed-off-by: Simo Piiroinen --- src/usb_moded-config.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/usb_moded-config.c b/src/usb_moded-config.c index d6c0513..26a74e5 100644 --- a/src/usb_moded-config.c +++ b/src/usb_moded-config.c @@ -528,7 +528,12 @@ set_config_result_t set_mode_whitelist(const char *whitelist) g_free(mode_setting); current_mode = get_usb_mode(); - if (strcmp(current_mode, MODE_CHARGING_FALLBACK) && strcmp(current_mode, MODE_ASK) && valid_mode(current_mode)) { + if (!strcmp(current_mode, MODE_UNDEFINED)) { + /* Disconnected -> do nothing */ + } + else if (strcmp(current_mode, MODE_CHARGING_FALLBACK) && strcmp(current_mode, MODE_ASK) && valid_mode(current_mode)) { + /* Invalid mode that is not MODE_ASK or MODE_CHARGING_FALLBACK + * -> switch to MODE_CHARGING_FALLBACK */ usb_moded_mode_cleanup(get_usb_module()); set_usb_mode(MODE_CHARGING_FALLBACK); }