usb-gadget: fix usb-gadget configuration parsing 59/274759/1
authorYoungjae Cho <y0.cho@samsung.com>
Mon, 9 May 2022 04:56:22 +0000 (13:56 +0900)
committerYoungjae Cho <y0.cho@samsung.com>
Mon, 9 May 2022 04:56:54 +0000 (13:56 +0900)
The section [SystemdUnit] is now properly applied.

Change-Id: I204d2fb7bee19b0dfac1feebe0c2876051b0937c
Signed-off-by: Youngjae Cho <y0.cho@samsung.com>
src/usb-gadget/usb-gadget-ops.c

index ededc18..6d7872c 100644 (file)
@@ -34,7 +34,6 @@ struct service_config {
        char name[128];
        int remain_after_disable; /* do not stop the service on disabling usb-gadget function */
 };
-static GList *service_config_list;
 
 static char board_serial[128] = "01234TEST";
 
@@ -128,6 +127,20 @@ struct usb_function *find_usb_function_by_name_instance(const char *name, const
        return NULL;
 }
 
+static struct usb_function *find_usb_function_by_service_name(const char *service)
+{
+       int i;
+
+       if(!service || !service[0])
+               return NULL;
+
+       for (i = 0; available_funcs[i]; ++i)
+               if (!strcmp(service, available_funcs[i]->service))
+                       return available_funcs[i];
+
+       return NULL;
+}
+
 static void simple_cleanup_config(struct usb_configuration *config)
 {
        if (!config)
@@ -439,20 +452,16 @@ static int load_usb_gadget_config(const struct parse_result *result, void *data)
 {
        if (MATCH(result->section, "SystemdUnit")) {
                struct service_config svc = { 0, };
-               void *entry = NULL;
+               struct usb_function *func;
 
                g_list_foreach(result->props, parse_property_systemd_unit, &svc);
 
-               entry = malloc(sizeof(struct service_config));
-               if (!entry) {
-                       _E("Failed to alloc service config");
-                       return 0;
+               func = find_usb_function_by_service_name(svc.name);
+               if (func) {
+                       _I("usb-gadget service config: name=%s, remain_after_disable=%d",
+                               svc.name, svc.remain_after_disable);
+                       func->remain_after_disable = svc.remain_after_disable;
                }
-
-               _I("usb-gadget service config: name=%s, remain_after_disable=%d",
-                       svc.name, svc.remain_after_disable);
-               service_config_list = g_list_prepend(service_config_list, memcpy(entry, &svc, sizeof(svc)));
-
        } else if (MATCH(result->section, "Attribute")) {
                struct usb_gadget_config gc = { 0, };
                void *entry = NULL;