From f03caba1dffef266dc744d8d7372202d6c00dd78 Mon Sep 17 00:00:00 2001 From: INSUN PYO Date: Thu, 19 Mar 2020 17:16:09 +0900 Subject: Remove unnecessary functions to clone/fee usb_function Change-Id: Ib6fcc7bd7ec2ed060e68a11b3837a0e2cd3f881b (cherry picked from commit b55a1f3108990c4dbeb6d11963487b55a659f963) --- hw/usb_gadget.h | 3 --- hw/usb_gadget_common.c | 61 ++------------------------------------------------ 2 files changed, 2 insertions(+), 62 deletions(-) diff --git a/hw/usb_gadget.h b/hw/usb_gadget.h index fedd8e7..c6a97e9 100644 --- a/hw/usb_gadget.h +++ b/hw/usb_gadget.h @@ -80,9 +80,6 @@ struct usb_function { const char *service; void (*handler)(int enable); - - int (*clone)(struct usb_function *func, struct usb_function **_clone); - void (*free_func)(struct usb_function *func); }; struct usb_configuration_attributes { diff --git a/hw/usb_gadget_common.c b/hw/usb_gadget_common.c index 08fe8a4..09d724c 100644 --- a/hw/usb_gadget_common.c +++ b/hw/usb_gadget_common.c @@ -59,10 +59,6 @@ static void simple_cleanup_config(struct usb_configuration *config) free(config->strs); } - /* - * Each function will be free later, - * for now we cleanup only pointers. - */ if (config->funcs) free(config->funcs); @@ -92,12 +88,8 @@ static void simple_cleanup_gadget(struct usb_gadget *gadget) 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); } @@ -328,10 +320,7 @@ static int simple_id_to_gadget(struct usb_gadget_id *gadget_id, 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; } @@ -360,7 +349,6 @@ static int simple_id_to_gadget(struct usb_gadget_id *gadget_id, return 0; free_configs: -free_functions: free_gadget: simple_cleanup_gadget(gadget); out: @@ -375,49 +363,6 @@ void rndis_handler(int enable) (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, \ @@ -426,8 +371,6 @@ out_nomem: .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); -- cgit v1.2.3