Fix bug - move _available_funcs to source code form header. 00/223500/1 accepted/tizen/5.5/unified/20200205.014419 submit/tizen_5.5/20200131.024742 submit/tizen_5.5/20200204.002631
authorINSUN PYO <insun.pyo@samsung.com>
Thu, 30 Jan 2020 08:50:09 +0000 (17:50 +0900)
committerHyotaek Shim <hyotaek.shim@samsung.com>
Thu, 30 Jan 2020 09:08:00 +0000 (09:08 +0000)
The _available_funcs is in header and static type.
So, _Available_funcs variables are created for all sources that include the header.
In this case, usb_cfs_clinet-common.c, usb_client_common.c and usb_gadget_common.c make its own static variable.

Change-Id: I29d2bb9d8543dafd049bbb9145fc9e4e14c13394
(cherry picked from commit 9a571b90e16b68fdbe2cdcb7ec3ca6e14a1b8b3b)

hw/usb_gadget.h
hw/usb_gadget_common.c
unittest/device_haltests.cpp

index a3e5d58..fe909ed 100644 (file)
  */
 #define USB_GADGET_DEVICE_VERSION      MAKE_VERSION(0,1)
 
+typedef enum {
+       USB_FUNCTION_IDX_MTP         = 0,
+       USB_FUNCTION_IDX_ACM         = 1,
+       USB_FUNCTION_IDX_SDB         = 2,
+       USB_FUNCTION_IDX_RNDIS       = 3,
+       USB_FUNCTION_IDX_DIAG        = 4,
+       USB_FUNCTION_IDX_CONN_GADGET = 5,
+       USB_FUNCTION_IDX_DM          = 6,
+       USB_FUNCTION_IDX_RMNET       = 7,
+       USB_FUNCTION_IDX_MAX         = USB_FUNCTION_IDX_RMNET + 1
+} usb_function_idx_e;
+
+typedef enum {
+       USB_FUNCTION_NONE        = 0,
+       USB_FUNCTION_MTP         = 1 << USB_FUNCTION_IDX_MTP,
+       USB_FUNCTION_ACM         = 1 << USB_FUNCTION_IDX_ACM,
+       USB_FUNCTION_SDB         = 1 << USB_FUNCTION_IDX_SDB,
+       USB_FUNCTION_RNDIS       = 1 << USB_FUNCTION_IDX_RNDIS,
+       USB_FUNCTION_DIAG        = 1 << USB_FUNCTION_IDX_DIAG,
+       USB_FUNCTION_CONN_GADGET = 1 << USB_FUNCTION_IDX_CONN_GADGET,
+       USB_FUNCTION_DM          = 1 << USB_FUNCTION_IDX_DM,
+       USB_FUNCTION_RMNET       = 1 << USB_FUNCTION_IDX_RMNET
+} usb_function_e;
+
+
 /*
  * legacy enable(usb plug)    : enable gadget -> handler(1) -> ffs_service start -> service start
  * legacy disable(usb unplug) : service stop -> ffs_service stop -> handler(0) -> disable gadget
@@ -98,117 +123,6 @@ struct usb_gadget {
        struct usb_configuration **configs;
 };
 
-typedef enum {
-       USB_FUNCTION_IDX_MTP         = 0,
-       USB_FUNCTION_IDX_ACM         = 1,
-       USB_FUNCTION_IDX_SDB         = 2,
-       USB_FUNCTION_IDX_RNDIS       = 3,
-       USB_FUNCTION_IDX_DIAG        = 4,
-       USB_FUNCTION_IDX_CONN_GADGET = 5,
-       USB_FUNCTION_IDX_DM          = 6,
-       USB_FUNCTION_IDX_RMNET       = 7,
-       USB_FUNCTION_IDX_MAX         = USB_FUNCTION_IDX_RMNET + 1
-} usb_function_idx_e;
-
-typedef enum {
-       USB_FUNCTION_NONE        = 0,
-       USB_FUNCTION_MTP         = 1 << USB_FUNCTION_IDX_MTP,
-       USB_FUNCTION_ACM         = 1 << USB_FUNCTION_IDX_ACM,
-       USB_FUNCTION_SDB         = 1 << USB_FUNCTION_IDX_SDB,
-       USB_FUNCTION_RNDIS       = 1 << USB_FUNCTION_IDX_RNDIS,
-       USB_FUNCTION_DIAG        = 1 << USB_FUNCTION_IDX_DIAG,
-       USB_FUNCTION_CONN_GADGET = 1 << USB_FUNCTION_IDX_CONN_GADGET,
-       USB_FUNCTION_DM          = 1 << USB_FUNCTION_IDX_DM,
-       USB_FUNCTION_RMNET       = 1 << USB_FUNCTION_IDX_RMNET
-} usb_function_e;
-
-static void free_simple_func(struct usb_function *func)
-{
-       if (func) {
-               free((void *)func->name);
-               free((void *)func->instance);
-               free((void *)func->ffs_service);
-               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->ffs_service) {
-               other->ffs_service = strdup(func->ffs_service);
-               if (!other->ffs_service)
-                       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;
-}
-
-void rndis_handler(int enable);
-
-#define DEFINE_USB_FUNCTION(_id, _name, _ffs_service, _service, _handler)      \
-       static struct usb_function _##_name##_function = {                      \
-               .id = _id,                                                      \
-               .name = #_name,                                                 \
-               .instance = "default",                                          \
-               .ffs_service = _ffs_service,                                    \
-               .service = _service,                                            \
-               .handler = _handler,                                            \
-               .clone = clone_simple_func,                                     \
-               .free_func = free_simple_func,                                  \
-       }
-
-DEFINE_USB_FUNCTION(USB_FUNCTION_DIAG,        diag,        NULL, NULL,            NULL);
-DEFINE_USB_FUNCTION(USB_FUNCTION_RMNET,       rmnet,       NULL, NULL,            NULL);
-DEFINE_USB_FUNCTION(USB_FUNCTION_DM,          dm,          NULL, NULL,            NULL);
-DEFINE_USB_FUNCTION(USB_FUNCTION_CONN_GADGET, conn_gadget, NULL, NULL,            NULL);
-DEFINE_USB_FUNCTION(USB_FUNCTION_SDB,         sdb,         "sdbd", NULL,          NULL);
-DEFINE_USB_FUNCTION(USB_FUNCTION_MTP,         mtp,         "mtp-responder", NULL, NULL);
-DEFINE_USB_FUNCTION(USB_FUNCTION_ACM,         acm,         NULL, "data-router",   NULL);
-DEFINE_USB_FUNCTION(USB_FUNCTION_RNDIS,       rndis,       NULL, "sshd",          rndis_handler);
-#undef DEFINE_USB_FUNCTION
-
-/* Caution: index order of arrary is important, because simple_id_to_gadget() uses it. */
-static struct usb_function *_available_funcs[] = {
-       [USB_FUNCTION_IDX_MTP]         = &_mtp_function,
-       [USB_FUNCTION_IDX_ACM]         = &_acm_function,
-       [USB_FUNCTION_IDX_SDB]         = &_sdb_function,
-       [USB_FUNCTION_IDX_RNDIS]       = &_rndis_function,
-       [USB_FUNCTION_IDX_DIAG]        = &_diag_function,
-       [USB_FUNCTION_IDX_CONN_GADGET] = &_conn_gadget_function,
-       [USB_FUNCTION_IDX_DM]          = &_dm_function,
-       [USB_FUNCTION_IDX_RMNET]       = &_rmnet_function,
-       [USB_FUNCTION_IDX_MAX]         = NULL /* An indicator to end the array */
-};
-
 struct usb_gadget_id {
        unsigned int function_mask;
 };
@@ -226,4 +140,6 @@ int simple_translator_open(struct hw_info *info,
                const char *id, struct hw_common **common);
 int simple_translator_close(struct hw_common *common);
 
+extern struct usb_function *_available_funcs[];
+
 #endif
index 4552b53..7416790 100644 (file)
@@ -406,6 +406,91 @@ 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->ffs_service);
+               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->ffs_service) {
+               other->ffs_service = strdup(func->ffs_service);
+               if (!other->ffs_service)
+                       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, _ffs_service, _service, _handler)      \
+       static struct usb_function _##_name##_function = {                      \
+               .id = _id,                                                      \
+               .name = #_name,                                                 \
+               .instance = "default",                                          \
+               .ffs_service = _ffs_service,                                    \
+               .service = _service,                                            \
+               .handler = _handler,                                            \
+               .clone = clone_simple_func,                                     \
+               .free_func = free_simple_func,                                  \
+       }
+
+DEFINE_USB_FUNCTION(USB_FUNCTION_DIAG,        diag,        NULL, NULL,            NULL);
+DEFINE_USB_FUNCTION(USB_FUNCTION_RMNET,       rmnet,       NULL, NULL,            NULL);
+DEFINE_USB_FUNCTION(USB_FUNCTION_DM,          dm,          NULL, NULL,            NULL);
+DEFINE_USB_FUNCTION(USB_FUNCTION_CONN_GADGET, conn_gadget, NULL, NULL,            NULL);
+DEFINE_USB_FUNCTION(USB_FUNCTION_SDB,         sdb,         "sdbd", NULL,          NULL);
+DEFINE_USB_FUNCTION(USB_FUNCTION_MTP,         mtp,         "mtp-responder", NULL, NULL);
+DEFINE_USB_FUNCTION(USB_FUNCTION_ACM,         acm,         NULL, "data-router",   NULL);
+DEFINE_USB_FUNCTION(USB_FUNCTION_RNDIS,       rndis,       NULL, "sshd",          rndis_handler);
+#undef DEFINE_USB_FUNCTION
+
+/* Caution: index order of arrary is important, because simple_id_to_gadget() uses it. */
+struct usb_function *_available_funcs[] = {
+       [USB_FUNCTION_IDX_MTP]         = &_mtp_function,
+       [USB_FUNCTION_IDX_ACM]         = &_acm_function,
+       [USB_FUNCTION_IDX_SDB]         = &_sdb_function,
+       [USB_FUNCTION_IDX_RNDIS]       = &_rndis_function,
+       [USB_FUNCTION_IDX_DIAG]        = &_diag_function,
+       [USB_FUNCTION_IDX_CONN_GADGET] = &_conn_gadget_function,
+       [USB_FUNCTION_IDX_DM]          = &_dm_function,
+       [USB_FUNCTION_IDX_RMNET]       = &_rmnet_function,
+       [USB_FUNCTION_IDX_MAX]         = NULL /* An indicator to end the array */
+};
+
 EXPORT
 int simple_translator_open(struct hw_info *info,
                const char *id, struct hw_common **common)
index ee84de6..4aa0de8 100644 (file)
@@ -1096,14 +1096,10 @@ TEST_F(USBCLIENTHalTest, InitP)
 TEST_F(USBCLIENTHalTest, EnableP)
 {
        int ret;
-       char str[256];
 
        if (!supported)
                return;
 
-       //dummy code to prevent error for not used function
-       snprintf(str, 255, "%s,", _available_funcs[2]->name);
-
        if (!client_dev || !client_dev->enable) {
                cout << "There is no function for enable" << endl;
                return;
@@ -1258,14 +1254,12 @@ TEST_F(USBGADGETHalTest, IdToGadget)
 {
        struct usb_gadget_id gadget_id;
        int ret;
-       char str[256];
 
        if (!gadget_translator || !gadget_translator->id_to_gadget) {
                cout << "There is no function for id_to_gadget" << endl;
                return;
        }
-       //dummy code to prevent error for not used function
-       snprintf(str, 255, "%s,", _available_funcs[2]->name);
+
        gadget_id.function_mask = 7;
        ret = gadget_translator->id_to_gadget(&gadget_id, &gadget_dev);
        EXPECT_EQ(ret, 0) << "Fail to id_to_gadget (" << ret << ")";