Lines Matching +full:language +full:- +full:id

1 // SPDX-License-Identifier: GPL-2.0
26 return -EINVAL; in check_user_usb_string()
28 stringtab_dev->language = num; in check_user_usb_string()
86 return container_of(cfg->c.cdev, struct gadget_info, cdev); in cfg_to_gadget_info()
121 return -EOVERFLOW; in usb_string_copy()
123 return -EINVAL; in usb_string_copy()
130 return -ENOMEM; in usb_string_copy()
133 if (str[ret - 1] == '\n') in usb_string_copy()
134 str[ret - 1] = '\0'; in usb_string_copy()
144 to_gadget_info(item)->cdev.desc.__name); \
152 le16_to_cpup(&to_gadget_info(item)->cdev.desc.__name)); \
165 to_gadget_info(item)->cdev.desc._name = val; \
178 to_gadget_info(item)->cdev.desc._name = cpu_to_le16p(&val); \
198 return -EINVAL; in is_valid_bcd()
200 return -EINVAL; in is_valid_bcd()
202 return -EINVAL; in is_valid_bcd()
204 return -EINVAL; in is_valid_bcd()
221 to_gadget_info(item)->cdev.desc.bcdDevice = cpu_to_le16(bcdDevice); in gadget_dev_desc_bcdDevice_store()
238 to_gadget_info(item)->cdev.desc.bcdUSB = cpu_to_le16(bcdUSB); in gadget_dev_desc_bcdUSB_store()
248 mutex_lock(&gi->lock); in gadget_dev_desc_UDC_show()
249 udc_name = gi->composite.gadget_driver.udc_name; in gadget_dev_desc_UDC_show()
251 mutex_unlock(&gi->lock); in gadget_dev_desc_UDC_show()
260 if (!gi->composite.gadget_driver.udc_name) in unregister_gadget()
261 return -ENODEV; in unregister_gadget()
263 ret = usb_gadget_unregister_driver(&gi->composite.gadget_driver); in unregister_gadget()
266 kfree(gi->composite.gadget_driver.udc_name); in unregister_gadget()
267 gi->composite.gadget_driver.udc_name = NULL; in unregister_gadget()
279 return -EOVERFLOW; in gadget_dev_desc_UDC_store()
283 return -ENOMEM; in gadget_dev_desc_UDC_store()
284 if (name[len - 1] == '\n') in gadget_dev_desc_UDC_store()
285 name[len - 1] = '\0'; in gadget_dev_desc_UDC_store()
287 mutex_lock(&gi->lock); in gadget_dev_desc_UDC_store()
295 if (gi->composite.gadget_driver.udc_name) { in gadget_dev_desc_UDC_store()
296 ret = -EBUSY; in gadget_dev_desc_UDC_store()
299 gi->composite.gadget_driver.udc_name = name; in gadget_dev_desc_UDC_store()
300 ret = usb_gadget_register_driver(&gi->composite.gadget_driver); in gadget_dev_desc_UDC_store()
302 gi->composite.gadget_driver.udc_name = NULL; in gadget_dev_desc_UDC_store()
306 mutex_unlock(&gi->lock); in gadget_dev_desc_UDC_store()
310 mutex_unlock(&gi->lock); in gadget_dev_desc_UDC_store()
317 enum usb_device_speed speed = to_gadget_info(item)->composite.max_speed; in gadget_dev_desc_max_speed_show()
327 mutex_lock(&gi->lock); in gadget_dev_desc_max_speed_store()
330 if (gi->composite.gadget_driver.udc_name) in gadget_dev_desc_max_speed_store()
333 if (strncmp(page, "super-speed-plus", 16) == 0) in gadget_dev_desc_max_speed_store()
334 gi->composite.max_speed = USB_SPEED_SUPER_PLUS; in gadget_dev_desc_max_speed_store()
335 else if (strncmp(page, "super-speed", 11) == 0) in gadget_dev_desc_max_speed_store()
336 gi->composite.max_speed = USB_SPEED_SUPER; in gadget_dev_desc_max_speed_store()
337 else if (strncmp(page, "high-speed", 10) == 0) in gadget_dev_desc_max_speed_store()
338 gi->composite.max_speed = USB_SPEED_HIGH; in gadget_dev_desc_max_speed_store()
339 else if (strncmp(page, "full-speed", 10) == 0) in gadget_dev_desc_max_speed_store()
340 gi->composite.max_speed = USB_SPEED_FULL; in gadget_dev_desc_max_speed_store()
341 else if (strncmp(page, "low-speed", 9) == 0) in gadget_dev_desc_max_speed_store()
342 gi->composite.max_speed = USB_SPEED_LOW; in gadget_dev_desc_max_speed_store()
346 gi->composite.gadget_driver.max_speed = gi->composite.max_speed; in gadget_dev_desc_max_speed_store()
348 mutex_unlock(&gi->lock); in gadget_dev_desc_max_speed_store()
351 mutex_unlock(&gi->lock); in gadget_dev_desc_max_speed_store()
352 return -EINVAL; in gadget_dev_desc_max_speed_store()
404 WARN_ON(!list_empty(&gi->cdev.configs)); in gadget_info_attr_release()
405 WARN_ON(!list_empty(&gi->string_list)); in gadget_info_attr_release()
406 WARN_ON(!list_empty(&gi->available_func)); in gadget_info_attr_release()
407 kfree(gi->composite.gadget_driver.function); in gadget_info_attr_release()
408 kfree(gi->composite.gadget_driver.driver.name); in gadget_info_attr_release()
420 WARN_ON(!list_empty(&cfg->c.functions)); in gadget_config_attr_release()
421 list_del(&cfg->c.list); in gadget_config_attr_release()
422 kfree(cfg->c.label); in gadget_config_attr_release()
439 mutex_lock(&gi->lock); in config_usb_cfg_link()
446 if (gi->composite.gadget_driver.udc_name) { in config_usb_cfg_link()
447 ret = -EINVAL; in config_usb_cfg_link()
451 list_for_each_entry(iter, &gi->available_func, cfs_list) { in config_usb_cfg_link()
458 ret = -EINVAL; in config_usb_cfg_link()
462 list_for_each_entry(f, &cfg->func_list, list) { in config_usb_cfg_link()
463 if (f->fi == fi) { in config_usb_cfg_link()
464 ret = -EEXIST; in config_usb_cfg_link()
476 list_add_tail(&f->list, &cfg->func_list); in config_usb_cfg_link()
479 mutex_unlock(&gi->lock); in config_usb_cfg_link()
500 mutex_lock(&gi->lock); in config_usb_cfg_unlink()
501 if (gi->composite.gadget_driver.udc_name) in config_usb_cfg_unlink()
503 WARN_ON(gi->composite.gadget_driver.udc_name); in config_usb_cfg_unlink()
505 list_for_each_entry(f, &cfg->func_list, list) { in config_usb_cfg_unlink()
506 if (f->fi == fi) { in config_usb_cfg_unlink()
507 list_del(&f->list); in config_usb_cfg_unlink()
509 mutex_unlock(&gi->lock); in config_usb_cfg_unlink()
513 mutex_unlock(&gi->lock); in config_usb_cfg_unlink()
529 return sprintf(page, "%u\n", cfg->c.MaxPower); in gadget_config_desc_MaxPower_show()
542 return -ERANGE; in gadget_config_desc_MaxPower_store()
543 cfg->c.MaxPower = val; in gadget_config_desc_MaxPower_store()
552 return sprintf(page, "0x%02x\n", cfg->c.bmAttributes); in gadget_config_desc_bmAttributes_show()
565 return -EINVAL; in gadget_config_desc_bmAttributes_store()
568 return -EINVAL; in gadget_config_desc_bmAttributes_store()
569 cfg->c.bmAttributes = val; in gadget_config_desc_bmAttributes_store()
596 spin_lock_init(&cdev->lock); in composite_init_dev()
597 INIT_LIST_HEAD(&cdev->configs); in composite_init_dev()
598 INIT_LIST_HEAD(&cdev->gstrings); in composite_init_dev()
614 return ERR_PTR(-ENAMETOOLONG); in function_make()
620 return ERR_PTR(-EINVAL); in function_make()
629 ret = config_item_set_name(&fi->group.cg_item, "%s", name); in function_make()
634 if (fi->set_inst_name) { in function_make()
635 ret = fi->set_inst_name(fi, instance_name); in function_make()
644 mutex_lock(&gi->lock); in function_make()
645 list_add_tail(&fi->cfs_list, &gi->available_func); in function_make()
646 mutex_unlock(&gi->lock); in function_make()
647 return &fi->group; in function_make()
659 mutex_lock(&gi->lock); in function_drop()
660 list_del(&fi->cfs_list); in function_drop()
661 mutex_unlock(&gi->lock); in function_drop()
686 kfree(cn->configuration); in gadget_config_name_attr_release()
688 list_del(&cn->list); in gadget_config_name_attr_release()
709 return ERR_PTR(-ENAMETOOLONG); in config_desc_make()
714 return ERR_PTR(-EINVAL); in config_desc_make()
721 return ERR_PTR(-EINVAL); in config_desc_make()
729 return ERR_PTR(-ENOMEM); in config_desc_make()
730 cfg->c.label = kstrdup(buf, GFP_KERNEL); in config_desc_make()
731 if (!cfg->c.label) { in config_desc_make()
732 ret = -ENOMEM; in config_desc_make()
735 cfg->c.bConfigurationValue = num; in config_desc_make()
736 cfg->c.MaxPower = CONFIG_USB_GADGET_VBUS_DRAW; in config_desc_make()
737 cfg->c.bmAttributes = USB_CONFIG_ATT_ONE; in config_desc_make()
738 INIT_LIST_HEAD(&cfg->string_list); in config_desc_make()
739 INIT_LIST_HEAD(&cfg->func_list); in config_desc_make()
741 config_group_init_type_name(&cfg->group, name, in config_desc_make()
744 config_group_init_type_name(&cfg->strings_group, "strings", in config_desc_make()
746 configfs_add_default_group(&cfg->strings_group, &cfg->group); in config_desc_make()
748 ret = usb_add_config_only(&gi->cdev, &cfg->c); in config_desc_make()
752 return &cfg->group; in config_desc_make()
754 kfree(cfg->c.label); in config_desc_make()
791 kfree(gs->manufacturer); in gadget_language_attr_release()
792 kfree(gs->product); in gadget_language_attr_release()
793 kfree(gs->serialnumber); in gadget_language_attr_release()
795 list_del(&gs->list); in gadget_language_attr_release()
808 ret = sprintf(page, "%u\n", string->usb_string.id); in gadget_string_id_show()
811 CONFIGFS_ATTR_RO(gadget_string_, id);
818 ret = snprintf(page, sizeof(string->string), "%s\n", string->string); in gadget_string_s_show()
826 int size = min(sizeof(string->string), len + 1); in gadget_string_s_store()
829 return -EINVAL; in gadget_string_s_store()
831 return strscpy(string->string, page, size); in gadget_string_s_store()
861 struct gadget_language *language; in gadget_language_string_make() local
864 language = to_gadget_language(&group->cg_item); in gadget_language_string_make()
868 return ERR_PTR(-ENOMEM); in gadget_language_string_make()
870 string->usb_string.id = language->nstrings++; in gadget_language_string_make()
871 string->usb_string.s = string->string; in gadget_language_string_make()
872 list_add_tail(&string->list, &language->gadget_strings); in gadget_language_string_make()
874 config_item_init_type_name(&string->item, name, &gadget_string_type); in gadget_language_string_make()
876 return &string->item; in gadget_language_string_make()
882 struct gadget_language *language; in gadget_language_string_drop() local
886 language = to_gadget_language(&group->cg_item); in gadget_language_string_drop()
889 list_del(&string->list); in gadget_language_string_drop()
890 language->nstrings--; in gadget_language_string_drop()
892 /* Reset the ids for the language's strings to guarantee a continuous set */ in gadget_language_string_drop()
893 list_for_each_entry(string, &language->gadget_strings, list) in gadget_language_string_drop()
894 string->usb_string.id = i++; in gadget_language_string_drop()
920 return ERR_PTR(-ENOMEM); in gadget_language_make()
922 ret = check_user_usb_string(name, &new->stringtab_dev); in gadget_language_make()
925 config_group_init_type_name(&new->group, name, in gadget_language_make()
929 ret = -EEXIST; in gadget_language_make()
930 list_for_each_entry(gs, &gi->string_list, list) { in gadget_language_make()
931 if (gs->stringtab_dev.language == new->stringtab_dev.language) in gadget_language_make()
935 ret = -EOVERFLOW; in gadget_language_make()
939 list_add_tail(&new->list, &gi->string_list); in gadget_language_make()
940 INIT_LIST_HEAD(&new->gadget_strings); in gadget_language_make()
943 new->nstrings = 3; in gadget_language_make()
944 return &new->group; in gadget_language_make()
976 webusb_item_to_gadget_info(item)->use_webusb); in webusb_use_show()
990 mutex_lock(&gi->lock); in webusb_use_store()
991 gi->use_webusb = use; in webusb_use_store()
992 mutex_unlock(&gi->lock); in webusb_use_store()
1000 webusb_item_to_gadget_info(item)->bcd_webusb_version); in webusb_bcdVersion_show()
1018 mutex_lock(&gi->lock); in webusb_bcdVersion_store()
1019 gi->bcd_webusb_version = bcdVersion; in webusb_bcdVersion_store()
1020 mutex_unlock(&gi->lock); in webusb_bcdVersion_store()
1028 webusb_item_to_gadget_info(item)->b_webusb_vendor_code); in webusb_bVendorCode_show()
1042 mutex_lock(&gi->lock); in webusb_bVendorCode_store()
1043 gi->b_webusb_vendor_code = b_vendor_code; in webusb_bVendorCode_store()
1044 mutex_unlock(&gi->lock); in webusb_bVendorCode_store()
1051 return sysfs_emit(page, "%s\n", webusb_item_to_gadget_info(item)->landing_page); in webusb_landingPage_show()
1061 if (page[l - 1] == '\n') { in webusb_landingPage_store()
1062 --l; in webusb_landingPage_store()
1066 if (l > sizeof(gi->landing_page)) { in webusb_landingPage_store()
1068 return -EINVAL; in webusb_landingPage_store()
1079 if (l > U8_MAX - WEBUSB_URL_DESCRIPTOR_HEADER_LENGTH + bytes_to_strip) { in webusb_landingPage_store()
1081 l - U8_MAX + WEBUSB_URL_DESCRIPTOR_HEADER_LENGTH - bytes_to_strip); in webusb_landingPage_store()
1082 return -EINVAL; in webusb_landingPage_store()
1085 mutex_lock(&gi->lock); in webusb_landingPage_store()
1087 memcpy_and_pad(gi->landing_page, sizeof(gi->landing_page), page, l, 0); in webusb_landingPage_store()
1088 mutex_unlock(&gi->lock); in webusb_landingPage_store()
1121 os_desc_item_to_gadget_info(item)->use_os_desc); in os_desc_use_show()
1135 mutex_lock(&gi->lock); in os_desc_use_store()
1136 gi->use_os_desc = use; in os_desc_use_store()
1137 mutex_unlock(&gi->lock); in os_desc_use_store()
1145 os_desc_item_to_gadget_info(item)->b_vendor_code); in os_desc_b_vendor_code_show()
1159 mutex_lock(&gi->lock); in os_desc_b_vendor_code_store()
1160 gi->b_vendor_code = b_vendor_code; in os_desc_b_vendor_code_store()
1161 mutex_unlock(&gi->lock); in os_desc_b_vendor_code_store()
1171 res = utf16s_to_utf8s((wchar_t *) gi->qw_sign, OS_STRING_QW_SIGN_LEN, in os_desc_qw_sign_show()
1172 UTF16_LITTLE_ENDIAN, page, PAGE_SIZE - 1); in os_desc_qw_sign_show()
1185 if (page[l - 1] == '\n') in os_desc_qw_sign_store()
1186 --l; in os_desc_qw_sign_store()
1188 mutex_lock(&gi->lock); in os_desc_qw_sign_store()
1190 UTF16_LITTLE_ENDIAN, (wchar_t *) gi->qw_sign, in os_desc_qw_sign_store()
1194 mutex_unlock(&gi->lock); in os_desc_qw_sign_store()
1214 struct usb_composite_dev *cdev = &gi->cdev; in os_desc_link()
1219 mutex_lock(&gi->lock); in os_desc_link()
1220 list_for_each_entry(iter, &cdev->configs, list) { in os_desc_link()
1221 if (iter != &c_target->c) in os_desc_link()
1227 ret = -EINVAL; in os_desc_link()
1231 if (cdev->os_desc_config) { in os_desc_link()
1232 ret = -EBUSY; in os_desc_link()
1236 cdev->os_desc_config = &c_target->c; in os_desc_link()
1240 mutex_unlock(&gi->lock); in os_desc_link()
1248 struct usb_composite_dev *cdev = &gi->cdev; in os_desc_unlink()
1250 mutex_lock(&gi->lock); in os_desc_unlink()
1251 if (gi->composite.gadget_driver.udc_name) in os_desc_unlink()
1253 cdev->os_desc_config = NULL; in os_desc_unlink()
1254 WARN_ON(gi->composite.gadget_driver.udc_name); in os_desc_unlink()
1255 mutex_unlock(&gi->lock); in os_desc_unlink()
1277 return sprintf(page, "%d\n", to_usb_os_desc_ext_prop(item)->type); in ext_prop_type_show()
1284 struct usb_os_desc *desc = to_usb_os_desc(ext_prop->item.ci_parent); in ext_prop_type_store()
1293 return -EINVAL; in ext_prop_type_store()
1295 if (desc->opts_mutex) in ext_prop_type_store()
1296 mutex_lock(desc->opts_mutex); in ext_prop_type_store()
1298 if ((ext_prop->type == USB_EXT_PROP_BINARY || in ext_prop_type_store()
1299 ext_prop->type == USB_EXT_PROP_LE32 || in ext_prop_type_store()
1300 ext_prop->type == USB_EXT_PROP_BE32) && in ext_prop_type_store()
1304 ext_prop->data_len <<= 1; in ext_prop_type_store()
1305 else if ((ext_prop->type == USB_EXT_PROP_UNICODE || in ext_prop_type_store()
1306 ext_prop->type == USB_EXT_PROP_UNICODE_ENV || in ext_prop_type_store()
1307 ext_prop->type == USB_EXT_PROP_UNICODE_LINK) && in ext_prop_type_store()
1311 ext_prop->data_len >>= 1; in ext_prop_type_store()
1312 ext_prop->type = type; in ext_prop_type_store()
1314 if (desc->opts_mutex) in ext_prop_type_store()
1315 mutex_unlock(desc->opts_mutex); in ext_prop_type_store()
1322 int len = ext_prop->data_len; in ext_prop_data_show()
1324 if (ext_prop->type == USB_EXT_PROP_UNICODE || in ext_prop_data_show()
1325 ext_prop->type == USB_EXT_PROP_UNICODE_ENV || in ext_prop_data_show()
1326 ext_prop->type == USB_EXT_PROP_UNICODE_LINK) in ext_prop_data_show()
1328 memcpy(page, ext_prop->data, len); in ext_prop_data_show()
1337 struct usb_os_desc *desc = to_usb_os_desc(ext_prop->item.ci_parent); in ext_prop_data_store()
1341 if (page[len - 1] == '\n' || page[len - 1] == '\0') in ext_prop_data_store()
1342 --len; in ext_prop_data_store()
1345 return -ENOMEM; in ext_prop_data_store()
1347 if (desc->opts_mutex) in ext_prop_data_store()
1348 mutex_lock(desc->opts_mutex); in ext_prop_data_store()
1349 kfree(ext_prop->data); in ext_prop_data_store()
1350 ext_prop->data = new_data; in ext_prop_data_store()
1351 desc->ext_prop_len -= ext_prop->data_len; in ext_prop_data_store()
1352 ext_prop->data_len = len; in ext_prop_data_store()
1353 desc->ext_prop_len += ext_prop->data_len; in ext_prop_data_store()
1354 if (ext_prop->type == USB_EXT_PROP_UNICODE || in ext_prop_data_store()
1355 ext_prop->type == USB_EXT_PROP_UNICODE_ENV || in ext_prop_data_store()
1356 ext_prop->type == USB_EXT_PROP_UNICODE_LINK) { in ext_prop_data_store()
1357 desc->ext_prop_len -= ext_prop->data_len; in ext_prop_data_store()
1358 ext_prop->data_len <<= 1; in ext_prop_data_store()
1359 ext_prop->data_len += 2; in ext_prop_data_store()
1360 desc->ext_prop_len += ext_prop->data_len; in ext_prop_data_store()
1362 if (desc->opts_mutex) in ext_prop_data_store()
1363 mutex_unlock(desc->opts_mutex); in ext_prop_data_store()
1402 return ERR_PTR(-ENOMEM); in ext_prop_make()
1408 ext_prop_type->ct_item_ops = &ext_prop_ops; in ext_prop_make()
1409 ext_prop_type->ct_attrs = ext_prop_attrs; in ext_prop_make()
1410 ext_prop_type->ct_owner = desc->owner; in ext_prop_make()
1412 config_item_init_type_name(&ext_prop->item, name, ext_prop_type); in ext_prop_make()
1414 ext_prop->name = kstrdup(name, GFP_KERNEL); in ext_prop_make()
1415 if (!ext_prop->name) { in ext_prop_make()
1417 return ERR_PTR(-ENOMEM); in ext_prop_make()
1419 desc->ext_prop_len += 14; in ext_prop_make()
1420 ext_prop->name_len = 2 * strlen(ext_prop->name) + 2; in ext_prop_make()
1421 if (desc->opts_mutex) in ext_prop_make()
1422 mutex_lock(desc->opts_mutex); in ext_prop_make()
1423 desc->ext_prop_len += ext_prop->name_len; in ext_prop_make()
1424 list_add_tail(&ext_prop->entry, &desc->ext_prop); in ext_prop_make()
1425 ++desc->ext_prop_count; in ext_prop_make()
1426 if (desc->opts_mutex) in ext_prop_make()
1427 mutex_unlock(desc->opts_mutex); in ext_prop_make()
1429 return &ext_prop->item; in ext_prop_make()
1435 struct usb_os_desc *desc = to_usb_os_desc(&group->cg_item); in ext_prop_drop()
1437 if (desc->opts_mutex) in ext_prop_drop()
1438 mutex_lock(desc->opts_mutex); in ext_prop_drop()
1439 list_del(&ext_prop->entry); in ext_prop_drop()
1440 --desc->ext_prop_count; in ext_prop_drop()
1441 kfree(ext_prop->name); in ext_prop_drop()
1442 desc->ext_prop_len -= (ext_prop->name_len + ext_prop->data_len + 14); in ext_prop_drop()
1443 if (desc->opts_mutex) in ext_prop_drop()
1444 mutex_unlock(desc->opts_mutex); in ext_prop_drop()
1456 memcpy(page, to_usb_os_desc(item)->ext_compat_id, 8); in interf_grp_compatible_id_show()
1467 if (page[l - 1] == '\n') in interf_grp_compatible_id_store()
1468 --l; in interf_grp_compatible_id_store()
1469 if (desc->opts_mutex) in interf_grp_compatible_id_store()
1470 mutex_lock(desc->opts_mutex); in interf_grp_compatible_id_store()
1471 memcpy(desc->ext_compat_id, page, l); in interf_grp_compatible_id_store()
1473 if (desc->opts_mutex) in interf_grp_compatible_id_store()
1474 mutex_unlock(desc->opts_mutex); in interf_grp_compatible_id_store()
1482 memcpy(page, to_usb_os_desc(item)->ext_compat_id + 8, 8); in interf_grp_sub_compatible_id_show()
1493 if (page[l - 1] == '\n') in interf_grp_sub_compatible_id_store()
1494 --l; in interf_grp_sub_compatible_id_store()
1495 if (desc->opts_mutex) in interf_grp_sub_compatible_id_store()
1496 mutex_lock(desc->opts_mutex); in interf_grp_sub_compatible_id_store()
1497 memcpy(desc->ext_compat_id + 8, page, l); in interf_grp_sub_compatible_id_store()
1499 if (desc->opts_mutex) in interf_grp_sub_compatible_id_store()
1500 mutex_unlock(desc->opts_mutex); in interf_grp_sub_compatible_id_store()
1531 return ERR_PTR(-ENOMEM); in usb_os_desc_prepare_interf_dir()
1537 os_desc_type->ct_owner = owner; in usb_os_desc_prepare_interf_dir()
1541 interface_type->ct_group_ops = &interf_grp_ops; in usb_os_desc_prepare_interf_dir()
1542 interface_type->ct_attrs = interf_grp_attrs; in usb_os_desc_prepare_interf_dir()
1543 interface_type->ct_owner = owner; in usb_os_desc_prepare_interf_dir()
1545 while (n_interf--) { in usb_os_desc_prepare_interf_dir()
1549 d->owner = owner; in usb_os_desc_prepare_interf_dir()
1550 config_group_init_type_name(&d->group, "", interface_type); in usb_os_desc_prepare_interf_dir()
1551 config_item_set_name(&d->group.cg_item, "interface.%s", in usb_os_desc_prepare_interf_dir()
1553 configfs_add_default_group(&d->group, os_desc_group); in usb_os_desc_prepare_interf_dir()
1563 return -EINVAL; in configfs_do_nothing()
1576 list_for_each_entry(c, &gi->cdev.configs, list) { in purge_configs_funcs()
1582 list_for_each_entry_safe_reverse(f, tmp, &c->functions, list) { in purge_configs_funcs()
1584 list_move(&f->list, &cfg->func_list); in purge_configs_funcs()
1585 if (f->unbind) { in purge_configs_funcs()
1586 dev_dbg(&gi->cdev.gadget->dev, in purge_configs_funcs()
1588 f->name, f); in purge_configs_funcs()
1589 f->unbind(c, f); in purge_configs_funcs()
1592 c->next_interface_id = 0; in purge_configs_funcs()
1593 memset(c->interface, 0, sizeof(c->interface)); in purge_configs_funcs()
1594 c->superspeed_plus = 0; in purge_configs_funcs()
1595 c->superspeed = 0; in purge_configs_funcs()
1596 c->highspeed = 0; in purge_configs_funcs()
1597 c->fullspeed = 0; in purge_configs_funcs()
1605 struct gadget_language *language; in configfs_attach_gadget_strings() local
1611 int nstrings = -1; in configfs_attach_gadget_strings()
1614 list_for_each(iter, &gi->string_list) in configfs_attach_gadget_strings()
1624 return ERR_PTR(-ENOMEM); in configfs_attach_gadget_strings()
1626 list_for_each_entry(language, &gi->string_list, list) { in configfs_attach_gadget_strings()
1629 if (nstrings == -1) { in configfs_attach_gadget_strings()
1630 nstrings = language->nstrings; in configfs_attach_gadget_strings()
1631 } else if (nstrings != language->nstrings) { in configfs_attach_gadget_strings()
1633 us = ERR_PTR(-EINVAL); in configfs_attach_gadget_strings()
1637 stringtab = kcalloc(language->nstrings + 1, sizeof(struct usb_string), in configfs_attach_gadget_strings()
1640 us = ERR_PTR(-ENOMEM); in configfs_attach_gadget_strings()
1644 stringtab[USB_GADGET_MANUFACTURER_IDX].id = USB_GADGET_MANUFACTURER_IDX; in configfs_attach_gadget_strings()
1645 stringtab[USB_GADGET_MANUFACTURER_IDX].s = language->manufacturer; in configfs_attach_gadget_strings()
1646 stringtab[USB_GADGET_PRODUCT_IDX].id = USB_GADGET_PRODUCT_IDX; in configfs_attach_gadget_strings()
1647 stringtab[USB_GADGET_PRODUCT_IDX].s = language->product; in configfs_attach_gadget_strings()
1648 stringtab[USB_GADGET_SERIAL_IDX].id = USB_GADGET_SERIAL_IDX; in configfs_attach_gadget_strings()
1649 stringtab[USB_GADGET_SERIAL_IDX].s = language->serialnumber; in configfs_attach_gadget_strings()
1652 list_for_each_entry(string, &language->gadget_strings, list) { in configfs_attach_gadget_strings()
1653 memcpy(&stringtab[j], &string->usb_string, sizeof(struct usb_string)); in configfs_attach_gadget_strings()
1657 language->stringtab_dev.strings = stringtab; in configfs_attach_gadget_strings()
1658 gadget_strings[i] = &language->stringtab_dev; in configfs_attach_gadget_strings()
1662 us = usb_gstrings_attach(&gi->cdev, gadget_strings, nstrings); in configfs_attach_gadget_strings()
1665 list_for_each_entry(language, &gi->string_list, list) { in configfs_attach_gadget_strings()
1666 kfree(language->stringtab_dev.strings); in configfs_attach_gadget_strings()
1667 language->stringtab_dev.strings = NULL; in configfs_attach_gadget_strings()
1681 struct usb_composite_dev *cdev = &gi->cdev; in configfs_composite_bind()
1687 /* the gi->lock is hold by the caller */ in configfs_composite_bind()
1688 gi->unbind = 0; in configfs_composite_bind()
1689 cdev->gadget = gadget; in configfs_composite_bind()
1695 ret = -EINVAL; in configfs_composite_bind()
1697 if (list_empty(&gi->cdev.configs)) { in configfs_composite_bind()
1699 gi->composite.name); in configfs_composite_bind()
1704 list_for_each_entry(c, &gi->cdev.configs, list) { in configfs_composite_bind()
1708 if (list_empty(&cfg->func_list)) { in configfs_composite_bind()
1710 c->label, c->bConfigurationValue, in configfs_composite_bind()
1711 gi->composite.name); in configfs_composite_bind()
1717 if (!list_empty(&gi->string_list)) { in configfs_composite_bind()
1724 gi->cdev.desc.iManufacturer = s[USB_GADGET_MANUFACTURER_IDX].id; in configfs_composite_bind()
1725 gi->cdev.desc.iProduct = s[USB_GADGET_PRODUCT_IDX].id; in configfs_composite_bind()
1726 gi->cdev.desc.iSerialNumber = s[USB_GADGET_SERIAL_IDX].id; in configfs_composite_bind()
1728 gi->cdev.usb_strings = s; in configfs_composite_bind()
1731 if (gi->use_webusb) { in configfs_composite_bind()
1732 cdev->use_webusb = true; in configfs_composite_bind()
1733 cdev->bcd_webusb_version = gi->bcd_webusb_version; in configfs_composite_bind()
1734 cdev->b_webusb_vendor_code = gi->b_webusb_vendor_code; in configfs_composite_bind()
1735 memcpy(cdev->landing_page, gi->landing_page, WEBUSB_URL_RAW_MAX_LENGTH); in configfs_composite_bind()
1738 if (gi->use_os_desc) { in configfs_composite_bind()
1739 cdev->use_os_string = true; in configfs_composite_bind()
1740 cdev->b_vendor_code = gi->b_vendor_code; in configfs_composite_bind()
1741 memcpy(cdev->qw_sign, gi->qw_sign, OS_STRING_QW_SIGN_LEN); in configfs_composite_bind()
1749 ret = -ENOMEM; in configfs_composite_bind()
1758 list_for_each_entry(c, &gi->cdev.configs, list) { in configfs_composite_bind()
1765 c->descriptors = otg_desc; in configfs_composite_bind()
1771 if (!list_empty(&cfg->string_list)) { in configfs_composite_bind()
1773 list_for_each_entry(cn, &cfg->string_list, list) { in configfs_composite_bind()
1774 cfg->gstrings[i] = &cn->stringtab_dev; in configfs_composite_bind()
1775 cn->stringtab_dev.strings = &cn->strings; in configfs_composite_bind()
1776 cn->strings.s = cn->configuration; in configfs_composite_bind()
1779 cfg->gstrings[i] = NULL; in configfs_composite_bind()
1780 s = usb_gstrings_attach(&gi->cdev, cfg->gstrings, 1); in configfs_composite_bind()
1785 c->iConfiguration = s[0].id; in configfs_composite_bind()
1788 list_for_each_entry_safe(f, tmp, &cfg->func_list, list) { in configfs_composite_bind()
1789 list_del(&f->list); in configfs_composite_bind()
1792 list_add(&f->list, &cfg->func_list); in configfs_composite_bind()
1796 ret = usb_gadget_check_config(cdev->gadget); in configfs_composite_bind()
1800 usb_ep_autoconfig_reset(cdev->gadget); in configfs_composite_bind()
1802 if (cdev->use_os_string) { in configfs_composite_bind()
1803 ret = composite_os_desc_req_prepare(cdev, gadget->ep0); in configfs_composite_bind()
1808 usb_ep_autoconfig_reset(cdev->gadget); in configfs_composite_bind()
1824 /* the gi->lock is hold by the caller */ in configfs_composite_unbind()
1828 spin_lock_irqsave(&gi->spinlock, flags); in configfs_composite_unbind()
1829 gi->unbind = 1; in configfs_composite_unbind()
1830 spin_unlock_irqrestore(&gi->spinlock, flags); in configfs_composite_unbind()
1836 usb_ep_autoconfig_reset(cdev->gadget); in configfs_composite_unbind()
1837 spin_lock_irqsave(&gi->spinlock, flags); in configfs_composite_unbind()
1838 cdev->gadget = NULL; in configfs_composite_unbind()
1839 cdev->deactivations = 0; in configfs_composite_unbind()
1840 gadget->deactivated = false; in configfs_composite_unbind()
1842 spin_unlock_irqrestore(&gi->spinlock, flags); in configfs_composite_unbind()
1858 spin_lock_irqsave(&gi->spinlock, flags); in configfs_composite_setup()
1860 if (!cdev || gi->unbind) { in configfs_composite_setup()
1861 spin_unlock_irqrestore(&gi->spinlock, flags); in configfs_composite_setup()
1866 spin_unlock_irqrestore(&gi->spinlock, flags); in configfs_composite_setup()
1881 spin_lock_irqsave(&gi->spinlock, flags); in configfs_composite_disconnect()
1883 if (!cdev || gi->unbind) { in configfs_composite_disconnect()
1884 spin_unlock_irqrestore(&gi->spinlock, flags); in configfs_composite_disconnect()
1889 spin_unlock_irqrestore(&gi->spinlock, flags); in configfs_composite_disconnect()
1903 spin_lock_irqsave(&gi->spinlock, flags); in configfs_composite_reset()
1905 if (!cdev || gi->unbind) { in configfs_composite_reset()
1906 spin_unlock_irqrestore(&gi->spinlock, flags); in configfs_composite_reset()
1911 spin_unlock_irqrestore(&gi->spinlock, flags); in configfs_composite_reset()
1925 spin_lock_irqsave(&gi->spinlock, flags); in configfs_composite_suspend()
1927 if (!cdev || gi->unbind) { in configfs_composite_suspend()
1928 spin_unlock_irqrestore(&gi->spinlock, flags); in configfs_composite_suspend()
1933 spin_unlock_irqrestore(&gi->spinlock, flags); in configfs_composite_suspend()
1947 spin_lock_irqsave(&gi->spinlock, flags); in configfs_composite_resume()
1949 if (!cdev || gi->unbind) { in configfs_composite_resume()
1950 spin_unlock_irqrestore(&gi->spinlock, flags); in configfs_composite_resume()
1955 spin_unlock_irqrestore(&gi->spinlock, flags); in configfs_composite_resume()
1984 return ERR_PTR(-ENOMEM); in gadgets_make()
1986 config_group_init_type_name(&gi->group, name, &gadget_root_type); in gadgets_make()
1988 config_group_init_type_name(&gi->functions_group, "functions", in gadgets_make()
1990 configfs_add_default_group(&gi->functions_group, &gi->group); in gadgets_make()
1992 config_group_init_type_name(&gi->configs_group, "configs", in gadgets_make()
1994 configfs_add_default_group(&gi->configs_group, &gi->group); in gadgets_make()
1996 config_group_init_type_name(&gi->strings_group, "strings", in gadgets_make()
1998 configfs_add_default_group(&gi->strings_group, &gi->group); in gadgets_make()
2000 config_group_init_type_name(&gi->os_desc_group, "os_desc", in gadgets_make()
2002 configfs_add_default_group(&gi->os_desc_group, &gi->group); in gadgets_make()
2004 config_group_init_type_name(&gi->webusb_group, "webusb", in gadgets_make()
2006 configfs_add_default_group(&gi->webusb_group, &gi->group); in gadgets_make()
2008 gi->composite.bind = configfs_do_nothing; in gadgets_make()
2009 gi->composite.unbind = configfs_do_nothing; in gadgets_make()
2010 gi->composite.suspend = NULL; in gadgets_make()
2011 gi->composite.resume = NULL; in gadgets_make()
2012 gi->composite.max_speed = USB_SPEED_SUPER_PLUS; in gadgets_make()
2014 spin_lock_init(&gi->spinlock); in gadgets_make()
2015 mutex_init(&gi->lock); in gadgets_make()
2016 INIT_LIST_HEAD(&gi->string_list); in gadgets_make()
2017 INIT_LIST_HEAD(&gi->available_func); in gadgets_make()
2019 composite_init_dev(&gi->cdev); in gadgets_make()
2020 gi->cdev.desc.bLength = USB_DT_DEVICE_SIZE; in gadgets_make()
2021 gi->cdev.desc.bDescriptorType = USB_DT_DEVICE; in gadgets_make()
2022 gi->cdev.desc.bcdDevice = cpu_to_le16(get_default_bcdDevice()); in gadgets_make()
2024 gi->composite.gadget_driver = configfs_driver_template; in gadgets_make()
2026 gi->composite.gadget_driver.driver.name = kasprintf(GFP_KERNEL, in gadgets_make()
2027 "configfs-gadget.%s", name); in gadgets_make()
2028 if (!gi->composite.gadget_driver.driver.name) in gadgets_make()
2031 gi->composite.gadget_driver.function = kstrdup(name, GFP_KERNEL); in gadgets_make()
2032 gi->composite.name = gi->composite.gadget_driver.function; in gadgets_make()
2034 if (!gi->composite.gadget_driver.function) in gadgets_make()
2037 return &gi->group; in gadgets_make()
2040 kfree(gi->composite.gadget_driver.driver.name); in gadgets_make()
2043 return ERR_PTR(-ENOMEM); in gadgets_make()
2075 mutex_lock(&gi->lock); in unregister_gadget_item()
2077 mutex_unlock(&gi->lock); in unregister_gadget_item()