From 50711dde4c97b237e3c82e5f830fe4b6d8fb69b2 Mon Sep 17 00:00:00 2001 From: Philippe De Swert Date: Tue, 5 Aug 2014 17:32:50 +0300 Subject: [PATCH] [usb setting logic] Do not check for mode_to_set_twice Fixes: CID#1230272 In case we compile without devicelock support the old code already checked for a mode to set. However this meant the secondary part of the loop got never reached. Now we check in one place. No more dead code. Also we cleaned-up a minor mem leak at the same time, as the mode_to_set did not get cleaned-up in case it matched the current mode. Signed-off-by: Philippe De Swert --- src/usb_moded.c | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/src/usb_moded.c b/src/usb_moded.c index 5438f90..28d942b 100644 --- a/src/usb_moded.c +++ b/src/usb_moded.c @@ -236,17 +236,6 @@ void set_usb_connected_state(void) } mode_to_set = get_mode_setting(); - if(!mode_to_set) - { - set_usb_mode(MODE_CHARGING); - return; - } - - /* This is safe to do here as the starting condition is - MODE_UNDEFINED, and having a devicelock being activated when - a mode is set will not interrupt it */ - if(!strcmp(mode_to_set, current_mode.mode)) - return; #ifdef MEEGOLOCK /* check if we are allowed to export system contents 0 is unlocked */ @@ -258,6 +247,12 @@ void set_usb_connected_state(void) if(mode_to_set) #endif /* MEEGOLOCK */ { + /* This is safe to do here as the starting condition is + MODE_UNDEFINED, and having a devicelock being activated when + a mode is set will not interrupt it */ + if(!strcmp(mode_to_set, current_mode.mode)) + goto end; + #ifdef NOKIA /* If we switch to another mode than the one that is still set before the clean-up timeout expired we need to clean up */ @@ -292,6 +287,7 @@ void set_usb_connected_state(void) */ set_usb_mode(MODE_CHARGING); } +end: free((void *)mode_to_set); }