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);