Fixed configfs not supporting multi-configuration 12/228512/2
authorINSUN PYO <insun.pyo@samsung.com>
Mon, 23 Mar 2020 10:46:18 +0000 (19:46 +0900)
committerHyotaek Shim <hyotaek.shim@samsung.com>
Wed, 25 Mar 2020 03:41:28 +0000 (03:41 +0000)
One usb function can be used in multiple config in configfs.
So when you create a usb function, you have to check if it exists.

Change-Id: I8f16fe4c542b277c12022d1c96d8ccb0aee32237

hw/usb_cfs_client_common.c

index 029988b..0a1990b 100644 (file)
@@ -425,20 +425,23 @@ static int cfs_set_gadget_config(struct cfs_client *cfs_client, int config_id, s
                        instance[sizeof(instance) - 1] = '\0';
                }
 
-               ret = usbg_create_function(cfs_client->gadget, function_type, instance, NULL, &function);
-               if (ret)
-                       return ret;
-
-               /* Setting rndis mac address. This should be done at this point,
-                * since the node host_addr changes to read only after the function
-                * is added to config. */
-               if (usbg_get_function_type(function) == USBG_F_RNDIS)
-                       (void)cfs_set_rndis_mac_addr(cfs_client->gadget, function); /* A random value is used if fails */
-
-               if (usbg_get_function_type(function) == USBG_F_FFS) {
-                       ret = cfs_prep_ffs_service(usb_func, function);
+               function = usbg_get_function(cfs_client->gadget, function_type, instance);
+               if (!function) {
+                       ret = usbg_create_function(cfs_client->gadget, function_type, instance, NULL, &function);
                        if (ret)
                                return ret;
+
+                       /* Setting rndis mac address. This should be done at this point,
+                        * since the node host_addr changes to read only after the function
+                        * is added to config. */
+                       if (usbg_get_function_type(function) == USBG_F_RNDIS)
+                               (void)cfs_set_rndis_mac_addr(cfs_client->gadget, function); /* A random value is used if fails */
+
+                       if (usbg_get_function_type(function) == USBG_F_FFS) {
+                               ret = cfs_prep_ffs_service(usb_func, function);
+                               if (ret)
+                                       return ret;
+                       }
                }
 
                ret = usbg_add_config_function(config, NULL, function);