free(config->strs);
}
- /*
- * Each function will be free later,
- * for now we cleanup only pointers.
- */
if (config->funcs)
free(config->funcs);
free(gadget->configs);
}
- if (gadget->funcs) {
- for (i = 0; gadget->funcs[i]; ++i)
- gadget->funcs[i]->free_func(gadget->funcs[i]);
-
+ if (gadget->funcs)
free(gadget->funcs);
- }
free(gadget);
}
if (!(gadget_id->function_mask & func_id))
continue;
- ret = _available_funcs[i]->clone(_available_funcs[i],
- gadget->funcs + idx);
- if (ret)
- goto free_functions;
+ gadget->funcs[idx] = _available_funcs[i];
++idx;
}
return 0;
free_configs:
-free_functions:
free_gadget:
simple_cleanup_gadget(gadget);
out:
(void)systemd_stop_unit_wait_stopped("rndis.service", NULL, -1);
}
-static void free_simple_func(struct usb_function *func)
-{
- if (func) {
- free((void *)func->name);
- free((void *)func->instance);
- free((void *)func->service);
- free(func);
- }
-}
-
-static int clone_simple_func(struct usb_function *func,
- struct usb_function **clone)
-{
- struct usb_function *other;
-
- if (!func || !clone)
- return -EINVAL;
-
- other = (struct usb_function *)calloc(1, sizeof(struct usb_function));
- if (!other)
- return -ENOMEM;
-
- *other = *func;
-
- other->name = strdup(func->name);
- other->instance = strdup(func->instance);
- if (!other->name || !other->instance)
- goto out_nomem;
-
- if (func->service) {
- other->service = strdup(func->service);
- if (!other->service)
- goto out_nomem;
- }
-
- *clone = other;
- return 0;
-
-out_nomem:
- free_simple_func(other);
- return -ENOMEM;
-}
-
#define DEFINE_USB_FUNCTION(_id, _name, _is_functionfs, _service, _handler) \
static struct usb_function _##_name##_function = { \
.id = _id, \
.is_functionfs = _is_functionfs, \
.service = _service, \
.handler = _handler, \
- .clone = clone_simple_func, \
- .free_func = free_simple_func, \
}
DEFINE_USB_FUNCTION(USB_FUNCTION_MTP, mtp, 1, "mtp-responder", NULL);