From 6848228a98e3237ff3a47ead1451dc5a67c585a4 Mon Sep 17 00:00:00 2001 From: Simo Piiroinen Date: Mon, 20 Aug 2018 15:00:45 +0300 Subject: [PATCH] [dyn-config] Drop unused syfs_path and sysfs_reset_value attributes All "normal" modes ignore syfs_path and sysfs_reset_value configuration values. Remove redundant lines from sample configuration files and adjust configuration file sanity checking rules. Also fix a GKeyFile leak on error path in dynconfig_read_mode_file(). Signed-off-by: Simo Piiroinen --- config/diag/qa_diagnostic_mode.ini | 3 +- config/dyn-modes/adb_mode.ini | 3 +- config/dyn-modes/android_acm.ini | 3 +- config/dyn-modes/android_at.ini | 3 +- .../connection_sharing-android-connman.ini | 3 +- config/dyn-modes/connection_sharing.ini | 3 +- config/dyn-modes/developer_mode-android.ini | 3 +- config/dyn-modes/diag_mode.ini | 3 +- config/dyn-modes/diag_mode_old.ini | 3 +- config/dyn-modes/mtp_mode-android-ffs.ini | 3 +- config/dyn-modes/mtp_mode-android.ini | 3 +- config/dyn-modes/pc_suite-android.ini | 3 +- config/dyn-modes/vfat_android.ini | 3 +- docs/usb_moded-doc.txt | 3 +- src/usb_moded-dyn-config.c | 105 +++++++++++------- 15 files changed, 76 insertions(+), 71 deletions(-) diff --git a/config/diag/qa_diagnostic_mode.ini b/config/diag/qa_diagnostic_mode.ini index 929030b..2a5ea00 100644 --- a/config/diag/qa_diagnostic_mode.ini +++ b/config/diag/qa_diagnostic_mode.ini @@ -5,9 +5,8 @@ appsync = 1 network = 0 [options] -sysfs_path = /sys/class/android_usb/android0/functions +# sysfs_value = comma separated list of functions to enable in this mode sysfs_value = adb,diag -sysfs_reset_value = none android_extra_sysfs_path = /sys/class/android_usb/android0/f_diag/clients android_extra_sysfs_value = diag idProduct = 0A05 diff --git a/config/dyn-modes/adb_mode.ini b/config/dyn-modes/adb_mode.ini index 94d4316..620cafa 100644 --- a/config/dyn-modes/adb_mode.ini +++ b/config/dyn-modes/adb_mode.ini @@ -6,10 +6,9 @@ network = 1 network_interface = rndis0 [options] -sysfs_path = /sys/class/android_usb/android0/functions +# sysfs_value = comma separated list of functions to enable in this mode sysfs_value = rndis,adb android_extra_sysfs_path = /sys/class/android_usb/android0/f_ffs/aliases android_extra_sysfs_value = adb -sysfs_reset_value = none idProduct = 0A03 dhcp_server = 1 diff --git a/config/dyn-modes/android_acm.ini b/config/dyn-modes/android_acm.ini index eaef243..2f47867 100644 --- a/config/dyn-modes/android_acm.ini +++ b/config/dyn-modes/android_acm.ini @@ -3,8 +3,7 @@ name = acm_mode module = none [options] -sysfs_path = /sys/class/android_usb/android0/functions +# sysfs_value = comma separated list of functions to enable in this mode sysfs_value = acm -sysfs_reset_value = none android_extra_sysfs_path = /sys/class/android_usb/android/f_acm/acm_transports android_extra_sysfs_value = tty diff --git a/config/dyn-modes/android_at.ini b/config/dyn-modes/android_at.ini index 5491354..cd4c069 100644 --- a/config/dyn-modes/android_at.ini +++ b/config/dyn-modes/android_at.ini @@ -3,8 +3,7 @@ name = at_mode module = none [options] -sysfs_path = /sys/class/android_usb/android0/functions +# sysfs_value = comma separated list of functions to enable in this mode sysfs_value = serial -sysfs_reset_value = none android_extra_sysfs_path = /sys/class/android_usb/android0/f_serial/transports android_extra_sysfs_value = smd,tty diff --git a/config/dyn-modes/connection_sharing-android-connman.ini b/config/dyn-modes/connection_sharing-android-connman.ini index 705f0f7..7c18409 100644 --- a/config/dyn-modes/connection_sharing-android-connman.ini +++ b/config/dyn-modes/connection_sharing-android-connman.ini @@ -3,8 +3,7 @@ name = connection_sharing module = none [options] -sysfs_path = /sys/class/android_usb/android0/functions +# sysfs_value = comma separated list of functions to enable in this mode sysfs_value = rndis -sysfs_reset_value = none idProduct = 0A02 connman_tethering = /net/connman/technology/gadget diff --git a/config/dyn-modes/connection_sharing.ini b/config/dyn-modes/connection_sharing.ini index 558dd2f..6e2cdca 100644 --- a/config/dyn-modes/connection_sharing.ini +++ b/config/dyn-modes/connection_sharing.ini @@ -6,8 +6,7 @@ network_interface = rndis0 appsync = 1 [options] -sysfs_path = /sys/class/android_usb/android0/functions +# sysfs_value = comma separated list of functions to enable in this mode sysfs_value = rndis -sysfs_reset_value = none idProduct = 0A02 nat = 1 diff --git a/config/dyn-modes/developer_mode-android.ini b/config/dyn-modes/developer_mode-android.ini index 8945545..11684ac 100644 --- a/config/dyn-modes/developer_mode-android.ini +++ b/config/dyn-modes/developer_mode-android.ini @@ -6,8 +6,7 @@ network_interface = rndis0 appsync = 1 [options] -sysfs_path = /sys/class/android_usb/android0/functions +# sysfs_value = comma separated list of functions to enable in this mode sysfs_value = rndis -sysfs_reset_value = none idProduct = 0A02 dhcp_server = 1 diff --git a/config/dyn-modes/diag_mode.ini b/config/dyn-modes/diag_mode.ini index 99c44d1..b2ed446 100644 --- a/config/dyn-modes/diag_mode.ini +++ b/config/dyn-modes/diag_mode.ini @@ -6,9 +6,8 @@ network = 1 network_interface = rndis0 [options] -sysfs_path = /sys/class/android_usb/android0/functions +# sysfs_value = comma separated list of functions to enable in this mode sysfs_value = diag,serial,rmnet,qdss,adb,rndis -sysfs_reset_value = none android_extra_sysfs_path = /sys/class/android_usb/android0/f_diag/clients android_extra_sysfs_value = diag android_extra_sysfs_path2 = /sys/class/android_usb/android0/f_serial/transports diff --git a/config/dyn-modes/diag_mode_old.ini b/config/dyn-modes/diag_mode_old.ini index f896108..e5f3759 100644 --- a/config/dyn-modes/diag_mode_old.ini +++ b/config/dyn-modes/diag_mode_old.ini @@ -6,9 +6,8 @@ network = 1 network_interface = rndis0 [options] -sysfs_path = /sys/class/android_usb/android0/functions +# sysfs_value = comma separated list of functions to enable in this mode sysfs_value = rndis,adb,diag,serial -sysfs_reset_value = none android_extra_sysfs_path = /sys/class/android_usb/android0/f_diag/clients android_extra_sysfs_value = diag android_extra_sysfs_path2 = /sys/class/android_usb/android0/f_serial/transports diff --git a/config/dyn-modes/mtp_mode-android-ffs.ini b/config/dyn-modes/mtp_mode-android-ffs.ini index 222fe85..67cc683 100644 --- a/config/dyn-modes/mtp_mode-android-ffs.ini +++ b/config/dyn-modes/mtp_mode-android-ffs.ini @@ -3,7 +3,6 @@ name = mtp_mode module = none [options] -sysfs_path = /sys/class/android_usb/android0/functions +# sysfs_value = comma separated list of functions to enable in this mode sysfs_value = ffs -sysfs_reset_value = none idProduct = 0A07 diff --git a/config/dyn-modes/mtp_mode-android.ini b/config/dyn-modes/mtp_mode-android.ini index 585c272..91f0e89 100644 --- a/config/dyn-modes/mtp_mode-android.ini +++ b/config/dyn-modes/mtp_mode-android.ini @@ -3,6 +3,5 @@ name = mtp_mode module = none [options] -sysfs_path = /sys/class/android_usb/android0/functions +# sysfs_value = comma separated list of functions to enable in this mode sysfs_value = mtp -sysfs_reset_value = none diff --git a/config/dyn-modes/pc_suite-android.ini b/config/dyn-modes/pc_suite-android.ini index 28a7ca2..fec9745 100644 --- a/config/dyn-modes/pc_suite-android.ini +++ b/config/dyn-modes/pc_suite-android.ini @@ -3,7 +3,6 @@ name = pc_suite module = none [options] -sysfs_path = /sys/class/android_usb/android0/functions +# sysfs_value = comma separated list of functions to enable in this mode sysfs_value = ffs -sysfs_reset_value = none idProduct = 0A07 diff --git a/config/dyn-modes/vfat_android.ini b/config/dyn-modes/vfat_android.ini index 4c3f2f7..095ef90 100644 --- a/config/dyn-modes/vfat_android.ini +++ b/config/dyn-modes/vfat_android.ini @@ -4,7 +4,6 @@ module = none appsync = 1 [options] -sysfs_path = /sys/class/android_usb/android0/functions +# sysfs_value = comma separated list of functions to enable in this mode sysfs_value = mass_storage -sysfs_reset_value = none idProduct = 55AA diff --git a/docs/usb_moded-doc.txt b/docs/usb_moded-doc.txt index fb7243f..33d9c5c 100644 --- a/docs/usb_moded-doc.txt +++ b/docs/usb_moded-doc.txt @@ -323,9 +323,8 @@ network = 1 network_interface = rndis0 [options] -sysfs_path = /sys/class/android_usb/android0/functions +# sysfs_value = comma separated list of functions to enable in this mode sysfs_value = rndis -sysfs_reset_value = none idProduct = 0002 diff --git a/src/usb_moded-dyn-config.c b/src/usb_moded-dyn-config.c index f0e80f0..2380257 100644 --- a/src/usb_moded-dyn-config.c +++ b/src/usb_moded-dyn-config.c @@ -55,26 +55,28 @@ static struct mode_list_elem *dynconfig_read_mode_file(const gchar *filename); void dynconfig_free_list_item(mode_list_elem *list_item) { - free(list_item->mode_name); - free(list_item->mode_module); - free(list_item->network_interface); - free(list_item->sysfs_path); - free(list_item->sysfs_value); - free(list_item->sysfs_reset_value); - free(list_item->android_extra_sysfs_path); - free(list_item->android_extra_sysfs_value); - free(list_item->android_extra_sysfs_path2); - free(list_item->android_extra_sysfs_value2); - free(list_item->android_extra_sysfs_path3); - free(list_item->android_extra_sysfs_value3); - free(list_item->android_extra_sysfs_path4); - free(list_item->android_extra_sysfs_value4); - free(list_item->idProduct); - free(list_item->idVendorOverride); + if( list_item ) { + free(list_item->mode_name); + free(list_item->mode_module); + free(list_item->network_interface); + free(list_item->sysfs_path); + free(list_item->sysfs_value); + free(list_item->sysfs_reset_value); + free(list_item->android_extra_sysfs_path); + free(list_item->android_extra_sysfs_value); + free(list_item->android_extra_sysfs_path2); + free(list_item->android_extra_sysfs_value2); + free(list_item->android_extra_sysfs_path3); + free(list_item->android_extra_sysfs_value3); + free(list_item->android_extra_sysfs_path4); + free(list_item->android_extra_sysfs_value4); + free(list_item->idProduct); + free(list_item->idVendorOverride); #ifdef CONNMAN - free(list_item->connman_tethering); + free(list_item->connman_tethering); #endif - free(list_item); + free(list_item); + } } void dynconfig_free_mode_list(GList *modelist) @@ -133,17 +135,16 @@ GList *dynconfig_read_mode_list(int diag) static struct mode_list_elem *dynconfig_read_mode_file(const gchar *filename) { - GKeyFile *settingsfile; - gboolean test = FALSE; + bool success = false; + GKeyFile *settingsfile = g_key_file_new(); struct mode_list_elem *list_item = NULL; - settingsfile = g_key_file_new(); - test = g_key_file_load_from_file(settingsfile, filename, G_KEY_FILE_NONE, NULL); - if(!test) - { - return(NULL); + if( !g_key_file_load_from_file(settingsfile, filename, G_KEY_FILE_NONE, NULL) ) { + log_err("%s: can't read mode configuration file", filename); + goto EXIT; } - list_item = malloc(sizeof(struct mode_list_elem)); + + list_item = calloc(1, sizeof *list_item); // [MODE_ENTRY = "mode"] list_item->mode_name = g_key_file_get_string(settingsfile, MODE_ENTRY, MODE_NAME_KEY, NULL); @@ -161,6 +162,7 @@ static struct mode_list_elem *dynconfig_read_mode_file(const gchar *filename) list_item->sysfs_path = g_key_file_get_string(settingsfile, MODE_OPTIONS_ENTRY, MODE_SYSFS_PATH, NULL); list_item->sysfs_value = g_key_file_get_string(settingsfile, MODE_OPTIONS_ENTRY, MODE_SYSFS_VALUE, NULL); list_item->sysfs_reset_value = g_key_file_get_string(settingsfile, MODE_OPTIONS_ENTRY, MODE_SYSFS_RESET_VALUE, NULL); + list_item->android_extra_sysfs_path = g_key_file_get_string(settingsfile, MODE_OPTIONS_ENTRY, MODE_ANDROID_EXTRA_SYSFS_PATH, NULL); list_item->android_extra_sysfs_path2 = g_key_file_get_string(settingsfile, MODE_OPTIONS_ENTRY, MODE_ANDROID_EXTRA_SYSFS_PATH2, NULL); list_item->android_extra_sysfs_path3 = g_key_file_get_string(settingsfile, MODE_OPTIONS_ENTRY, MODE_ANDROID_EXTRA_SYSFS_PATH3, NULL); @@ -169,6 +171,7 @@ static struct mode_list_elem *dynconfig_read_mode_file(const gchar *filename) list_item->android_extra_sysfs_value2 = g_key_file_get_string(settingsfile, MODE_OPTIONS_ENTRY, MODE_ANDROID_EXTRA_SYSFS_VALUE2, NULL); list_item->android_extra_sysfs_value3 = g_key_file_get_string(settingsfile, MODE_OPTIONS_ENTRY, MODE_ANDROID_EXTRA_SYSFS_VALUE3, NULL); list_item->android_extra_sysfs_value4 = g_key_file_get_string(settingsfile, MODE_OPTIONS_ENTRY, MODE_ANDROID_EXTRA_SYSFS_VALUE4, NULL); + list_item->idProduct = g_key_file_get_string(settingsfile, MODE_OPTIONS_ENTRY, MODE_IDPRODUCT, NULL); list_item->idVendorOverride = g_key_file_get_string(settingsfile, MODE_OPTIONS_ENTRY, MODE_IDVENDOROVERRIDE, NULL); list_item->nat = g_key_file_get_integer(settingsfile, MODE_OPTIONS_ENTRY, MODE_HAS_NAT, NULL); @@ -182,24 +185,40 @@ static struct mode_list_elem *dynconfig_read_mode_file(const gchar *filename) //log_debug("Android extra mode sysfs path2 = %s\n", list_item->android_extra_sysfs_path2); //log_debug("Android extra value2 = %s\n", list_item->android_extra_sysfs_value2); - g_key_file_free(settingsfile); - if(list_item->mode_name == NULL || list_item->mode_module == NULL) - { - /* free list_item as it will not be used */ - dynconfig_free_list_item(list_item); - return NULL; + if( list_item->mode_name == NULL || list_item->mode_module == NULL ) { + log_err("%s: mode_name or mode_module not defined", filename); + goto EXIT; } - if(list_item->network && list_item->network_interface == NULL) - { - /* free list_item as it will not be used */ - dynconfig_free_list_item(list_item); - return NULL; + + if( list_item->network && list_item->network_interface == NULL) { + log_err("%s: network not fully defined", filename); + goto EXIT; } - if(list_item->sysfs_path && list_item->sysfs_value == NULL) - { - /* free list_item as it will not be used */ - dynconfig_free_list_item(list_item); - return NULL; + + if( (list_item->sysfs_path && !list_item->sysfs_value) || + (list_item->sysfs_reset_value && !list_item->sysfs_path) ) { + /* In theory all of this is optional. + * + * In most cases 'sysfs_value' holds a list of functions to enable, + * and 'sysfs_path' or 'sysfs_reset_value' values are simply ignored. + * + * However, for the benefit of existing special configuration files + * like the one for host mode: + * - having sysfs_path implies that sysfs_value should be set too + * - having sysfs_reset_value implies that sysfs_path should be set + */ + log_err("%s: sysfs_value not fully defined", filename); + goto EXIT; } - return(list_item); + + log_debug("%s: successfully loaded", filename); + success = true; + +EXIT: + g_key_file_free(settingsfile); + + if( !success ) + dynconfig_free_list_item(list_item), list_item = 0; + + return list_item; }