summaryrefslogtreecommitdiff
path: root/hw/usb_cfs_client_common.c
diff options
context:
space:
mode:
authorINSUN PYO <insun.pyo@samsung.com>2020-03-25 19:49:21 +0900
committerHyotaek Shim <hyotaek.shim@samsung.com>2020-03-26 04:53:31 +0000
commitb13cd53ed4983e17f7d11c5e153a428a2b821cd3 (patch)
tree670a09f06552dde06ad940016cb0595824ee2848 /hw/usb_cfs_client_common.c
parent39dec821c92e4022ac6326b459d55f9c55ad0b92 (diff)
downloadlibdevice-node-b13cd53ed4983e17f7d11c5e153a428a2b821cd3.tar.gz
libdevice-node-b13cd53ed4983e17f7d11c5e153a428a2b821cd3.tar.bz2
libdevice-node-b13cd53ed4983e17f7d11c5e153a428a2b821cd3.zip
Refactoring gadget's string
The usb gadget uses only one string information. So instead of dynamically creating string information, only use one fixed. Change-Id: I01adf3d0c7ce498e516b08b5a284c63d2940bcb6 (cherry picked from commit 998f44215d67cdf7aa33d63f012369c3a413bfaa)
Diffstat (limited to 'hw/usb_cfs_client_common.c')
-rw-r--r--hw/usb_cfs_client_common.c47
1 files changed, 24 insertions, 23 deletions
diff --git a/hw/usb_cfs_client_common.c b/hw/usb_cfs_client_common.c
index 3c4740d..db6b781 100644
--- a/hw/usb_cfs_client_common.c
+++ b/hw/usb_cfs_client_common.c
@@ -111,15 +111,20 @@ static bool cfs_is_function_supported(struct usb_client *usb,
return res;
}
-static bool cfs_is_gadget_supported(struct usb_client *usb,
- struct usb_gadget *gadget)
+static bool cfs_is_gadget_supported(struct usb_client *usb, struct usb_gadget *gadget)
{
int i, j;
if (!gadget || !gadget->configs || !gadget->funcs)
return false;
- /* No real restrictions for strings */
+ /* only strings in US_en are allowed */
+ if (gadget->strs.lang_code != DEFAULT_LANG)
+ return false;
+
+ if (!gadget->strs.manufacturer || !gadget->strs.product || !gadget->strs.serial)
+ return false;
+
for (j = 0; gadget->configs && gadget->configs[j]; ++j) {
struct usb_configuration *config = gadget->configs[j];
@@ -159,25 +164,24 @@ static int cfs_set_gadget_attrs(struct cfs_client *cfs_client,
return ret;
}
-static int cfs_set_gadget_strs(struct cfs_client *cfs_client,
- struct usb_gadget_strings *strs)
+static int cfs_set_gadget_strs(struct cfs_client *cfs_client, struct usb_gadget_strings *strs)
{
int ret;
-#define SET_STR(FIELD, STR_ID) \
- if (strs->FIELD) { \
- ret = usbg_set_gadget_str(cfs_client->gadget, \
- STR_ID, \
- strs->lang_code, \
- strs->FIELD); \
- if (ret) \
- return ret; \
- }
+ if (!strs->manufacturer || !strs->product || !strs->serial)
+ return -EINVAL;
- SET_STR(manufacturer, USBG_STR_MANUFACTURER);
- SET_STR(product, USBG_STR_PRODUCT);
- SET_STR(serial, USBG_STR_SERIAL_NUMBER);
-#undef SET_STR
+ ret = usbg_set_gadget_str(cfs_client->gadget, USBG_STR_MANUFACTURER, strs->lang_code, strs->manufacturer);
+ if (ret)
+ return ret;
+
+ ret = usbg_set_gadget_str(cfs_client->gadget, USBG_STR_PRODUCT, strs->lang_code, strs->product);
+ if (ret)
+ return ret;
+
+ ret = usbg_set_gadget_str(cfs_client->gadget, USBG_STR_SERIAL_NUMBER, strs->lang_code, strs->serial);
+ if (ret)
+ return ret;
return 0;
}
@@ -461,11 +465,9 @@ static int cfs_reconfigure_gadget(struct usb_client *usb, struct usb_gadget *gad
if (ret)
return ret;
- for (i = 0; gadget->strs && gadget->strs[i].lang_code > 0; ++i) {
- ret = cfs_set_gadget_strs(cfs_client, gadget->strs + i);
+ ret = cfs_set_gadget_strs(cfs_client, &gadget->strs);
if (ret)
return ret;
- }
ret = cfs_cleanup_all_config_and_function(cfs_client);
if (ret)
@@ -587,8 +589,7 @@ int hw_cfs_gadget_open(struct hw_info *info,
}
ret = usbg_create_gadget(cfs_client->ctx, CONFIGFS_GADGET_NAME,
- &default_g_attrs, &default_g_strs,
- &cfs_client->gadget);
+ &default_g_attrs, &default_g_strs, &cfs_client->gadget);
if (ret)
goto err_create_gadget;