1 #include <linux/configfs.h>
2 #include <linux/module.h>
3 #include <linux/slab.h>
4 #include <linux/device.h>
6 #include <linux/usb/composite.h>
7 #include <linux/usb/gadget_configfs.h>
10 #include "u_os_desc.h"
12 #ifdef CONFIG_USB_CONFIGFS_UEVENT
13 #include <linux/platform_device.h>
14 #include <linux/kdev_t.h>
15 #include <linux/usb/ch9.h>
17 #ifdef CONFIG_USB_CONFIGFS_F_ACC
18 extern int acc_ctrlrequest(struct usb_composite_dev *cdev,
19 const struct usb_ctrlrequest *ctrl);
20 void acc_disconnect(void);
22 static struct class *android_class;
23 static struct device *android_device;
26 struct device *create_function_device(char *name)
28 if (android_device && !IS_ERR(android_device))
29 return device_create(android_class, android_device,
30 MKDEV(0, index++), NULL, name);
32 return ERR_PTR(-EINVAL);
34 EXPORT_SYMBOL_GPL(create_function_device);
37 int check_user_usb_string(const char *name,
38 struct usb_gadget_strings *stringtab_dev)
40 unsigned primary_lang;
45 ret = kstrtou16(name, 0, &num);
49 primary_lang = num & 0x3ff;
52 /* simple sanity check for valid langid */
53 switch (primary_lang) {
62 stringtab_dev->language = num;
66 #define MAX_NAME_LEN 40
67 #define MAX_USB_STRING_LANGS 2
69 static const struct usb_descriptor_header *otg_desc[2];
72 struct config_group group;
73 struct config_group functions_group;
74 struct config_group configs_group;
75 struct config_group strings_group;
76 struct config_group os_desc_group;
77 struct config_group *default_groups[5];
80 struct usb_gadget_strings *gstrings[MAX_USB_STRING_LANGS + 1];
81 struct list_head string_list;
82 struct list_head available_func;
85 struct usb_composite_driver composite;
86 struct usb_composite_dev cdev;
89 char qw_sign[OS_STRING_QW_SIGN_LEN];
90 #ifdef CONFIG_USB_CONFIGFS_UEVENT
93 struct work_struct work;
98 static inline struct gadget_info *to_gadget_info(struct config_item *item)
100 return container_of(to_config_group(item), struct gadget_info, group);
103 struct config_usb_cfg {
104 struct config_group group;
105 struct config_group strings_group;
106 struct config_group *default_groups[2];
107 struct list_head string_list;
108 struct usb_configuration c;
109 struct list_head func_list;
110 struct usb_gadget_strings *gstrings[MAX_USB_STRING_LANGS + 1];
113 static inline struct config_usb_cfg *to_config_usb_cfg(struct config_item *item)
115 return container_of(to_config_group(item), struct config_usb_cfg,
119 struct gadget_strings {
120 struct usb_gadget_strings stringtab_dev;
121 struct usb_string strings[USB_GADGET_FIRST_AVAIL_IDX];
126 struct config_group group;
127 struct list_head list;
131 struct config_group group;
134 struct gadget_config_name {
135 struct usb_gadget_strings stringtab_dev;
136 struct usb_string strings;
139 struct config_group group;
140 struct list_head list;
143 static int usb_string_copy(const char *s, char **s_copy)
147 char *copy = *s_copy;
152 str = kstrdup(s, GFP_KERNEL);
155 if (str[ret - 1] == '\n')
162 #define GI_DEVICE_DESC_SIMPLE_R_u8(__name) \
163 static ssize_t gadget_dev_desc_##__name##_show(struct config_item *item, \
166 return sprintf(page, "0x%02x\n", \
167 to_gadget_info(item)->cdev.desc.__name); \
170 #define GI_DEVICE_DESC_SIMPLE_R_u16(__name) \
171 static ssize_t gadget_dev_desc_##__name##_show(struct config_item *item, \
174 return sprintf(page, "0x%04x\n", \
175 le16_to_cpup(&to_gadget_info(item)->cdev.desc.__name)); \
179 #define GI_DEVICE_DESC_SIMPLE_W_u8(_name) \
180 static ssize_t gadget_dev_desc_##_name##_store(struct config_item *item, \
181 const char *page, size_t len) \
185 ret = kstrtou8(page, 0, &val); \
188 to_gadget_info(item)->cdev.desc._name = val; \
192 #define GI_DEVICE_DESC_SIMPLE_W_u16(_name) \
193 static ssize_t gadget_dev_desc_##_name##_store(struct config_item *item, \
194 const char *page, size_t len) \
198 ret = kstrtou16(page, 0, &val); \
201 to_gadget_info(item)->cdev.desc._name = cpu_to_le16p(&val); \
205 #define GI_DEVICE_DESC_SIMPLE_RW(_name, _type) \
206 GI_DEVICE_DESC_SIMPLE_R_##_type(_name) \
207 GI_DEVICE_DESC_SIMPLE_W_##_type(_name)
209 GI_DEVICE_DESC_SIMPLE_R_u16(bcdUSB);
210 GI_DEVICE_DESC_SIMPLE_RW(bDeviceClass, u8);
211 GI_DEVICE_DESC_SIMPLE_RW(bDeviceSubClass, u8);
212 GI_DEVICE_DESC_SIMPLE_RW(bDeviceProtocol, u8);
213 GI_DEVICE_DESC_SIMPLE_RW(bMaxPacketSize0, u8);
214 GI_DEVICE_DESC_SIMPLE_RW(idVendor, u16);
215 GI_DEVICE_DESC_SIMPLE_RW(idProduct, u16);
216 GI_DEVICE_DESC_SIMPLE_R_u16(bcdDevice);
218 static ssize_t is_valid_bcd(u16 bcd_val)
220 if ((bcd_val & 0xf) > 9)
222 if (((bcd_val >> 4) & 0xf) > 9)
224 if (((bcd_val >> 8) & 0xf) > 9)
226 if (((bcd_val >> 12) & 0xf) > 9)
231 static ssize_t gadget_dev_desc_bcdDevice_store(struct config_item *item,
232 const char *page, size_t len)
237 ret = kstrtou16(page, 0, &bcdDevice);
240 ret = is_valid_bcd(bcdDevice);
244 to_gadget_info(item)->cdev.desc.bcdDevice = cpu_to_le16(bcdDevice);
248 static ssize_t gadget_dev_desc_bcdUSB_store(struct config_item *item,
249 const char *page, size_t len)
254 ret = kstrtou16(page, 0, &bcdUSB);
257 ret = is_valid_bcd(bcdUSB);
261 to_gadget_info(item)->cdev.desc.bcdUSB = cpu_to_le16(bcdUSB);
265 static ssize_t gadget_dev_desc_UDC_show(struct config_item *item, char *page)
267 return sprintf(page, "%s\n", to_gadget_info(item)->udc_name ?: "");
270 static int unregister_gadget(struct gadget_info *gi)
277 ret = usb_gadget_unregister_driver(&gi->composite.gadget_driver);
285 static ssize_t gadget_dev_desc_UDC_store(struct config_item *item,
286 const char *page, size_t len)
288 struct gadget_info *gi = to_gadget_info(item);
292 name = kstrdup(page, GFP_KERNEL);
295 if (name[len - 1] == '\n')
296 name[len - 1] = '\0';
298 mutex_lock(&gi->lock);
300 if (!strlen(name) || strcmp(name, "none") == 0) {
301 ret = unregister_gadget(gi);
309 ret = usb_udc_attach_driver(name, &gi->composite.gadget_driver);
314 mutex_unlock(&gi->lock);
318 mutex_unlock(&gi->lock);
322 CONFIGFS_ATTR(gadget_dev_desc_, bDeviceClass);
323 CONFIGFS_ATTR(gadget_dev_desc_, bDeviceSubClass);
324 CONFIGFS_ATTR(gadget_dev_desc_, bDeviceProtocol);
325 CONFIGFS_ATTR(gadget_dev_desc_, bMaxPacketSize0);
326 CONFIGFS_ATTR(gadget_dev_desc_, idVendor);
327 CONFIGFS_ATTR(gadget_dev_desc_, idProduct);
328 CONFIGFS_ATTR(gadget_dev_desc_, bcdDevice);
329 CONFIGFS_ATTR(gadget_dev_desc_, bcdUSB);
330 CONFIGFS_ATTR(gadget_dev_desc_, UDC);
332 static struct configfs_attribute *gadget_root_attrs[] = {
333 &gadget_dev_desc_attr_bDeviceClass,
334 &gadget_dev_desc_attr_bDeviceSubClass,
335 &gadget_dev_desc_attr_bDeviceProtocol,
336 &gadget_dev_desc_attr_bMaxPacketSize0,
337 &gadget_dev_desc_attr_idVendor,
338 &gadget_dev_desc_attr_idProduct,
339 &gadget_dev_desc_attr_bcdDevice,
340 &gadget_dev_desc_attr_bcdUSB,
341 &gadget_dev_desc_attr_UDC,
345 static inline struct gadget_strings *to_gadget_strings(struct config_item *item)
347 return container_of(to_config_group(item), struct gadget_strings,
351 static inline struct gadget_config_name *to_gadget_config_name(
352 struct config_item *item)
354 return container_of(to_config_group(item), struct gadget_config_name,
358 static inline struct usb_function_instance *to_usb_function_instance(
359 struct config_item *item)
361 return container_of(to_config_group(item),
362 struct usb_function_instance, group);
365 static void gadget_info_attr_release(struct config_item *item)
367 struct gadget_info *gi = to_gadget_info(item);
369 WARN_ON(!list_empty(&gi->cdev.configs));
370 WARN_ON(!list_empty(&gi->string_list));
371 WARN_ON(!list_empty(&gi->available_func));
372 kfree(gi->composite.gadget_driver.function);
376 static struct configfs_item_operations gadget_root_item_ops = {
377 .release = gadget_info_attr_release,
380 static void gadget_config_attr_release(struct config_item *item)
382 struct config_usb_cfg *cfg = to_config_usb_cfg(item);
384 WARN_ON(!list_empty(&cfg->c.functions));
385 list_del(&cfg->c.list);
390 static int config_usb_cfg_link(
391 struct config_item *usb_cfg_ci,
392 struct config_item *usb_func_ci)
394 struct config_usb_cfg *cfg = to_config_usb_cfg(usb_cfg_ci);
395 struct usb_composite_dev *cdev = cfg->c.cdev;
396 struct gadget_info *gi = container_of(cdev, struct gadget_info, cdev);
398 struct config_group *group = to_config_group(usb_func_ci);
399 struct usb_function_instance *fi = container_of(group,
400 struct usb_function_instance, group);
401 struct usb_function_instance *a_fi;
402 struct usb_function *f;
405 mutex_lock(&gi->lock);
407 * Make sure this function is from within our _this_ gadget and not
408 * from another gadget or a random directory.
409 * Also a function instance can only be linked once.
411 list_for_each_entry(a_fi, &gi->available_func, cfs_list) {
420 list_for_each_entry(f, &cfg->func_list, list) {
427 f = usb_get_function(fi);
429 /* Are we trying to symlink PTP without MTP function? */
430 ret = -EINVAL; /* Invalid Configuration */
438 /* stash the function until we bind it to the gadget */
439 list_add_tail(&f->list, &cfg->func_list);
442 mutex_unlock(&gi->lock);
446 static int config_usb_cfg_unlink(
447 struct config_item *usb_cfg_ci,
448 struct config_item *usb_func_ci)
450 struct config_usb_cfg *cfg = to_config_usb_cfg(usb_cfg_ci);
451 struct usb_composite_dev *cdev = cfg->c.cdev;
452 struct gadget_info *gi = container_of(cdev, struct gadget_info, cdev);
454 struct config_group *group = to_config_group(usb_func_ci);
455 struct usb_function_instance *fi = container_of(group,
456 struct usb_function_instance, group);
457 struct usb_function *f;
460 * ideally I would like to forbid to unlink functions while a gadget is
461 * bound to an UDC. Since this isn't possible at the moment, we simply
462 * force an unbind, the function is available here and then we can
463 * remove the function.
465 mutex_lock(&gi->lock);
467 unregister_gadget(gi);
468 WARN_ON(gi->udc_name);
470 list_for_each_entry(f, &cfg->func_list, list) {
474 mutex_unlock(&gi->lock);
478 mutex_unlock(&gi->lock);
479 WARN(1, "Unable to locate function to unbind\n");
483 static struct configfs_item_operations gadget_config_item_ops = {
484 .release = gadget_config_attr_release,
485 .allow_link = config_usb_cfg_link,
486 .drop_link = config_usb_cfg_unlink,
490 static ssize_t gadget_config_desc_MaxPower_show(struct config_item *item,
493 return sprintf(page, "%u\n", to_config_usb_cfg(item)->c.MaxPower);
496 static ssize_t gadget_config_desc_MaxPower_store(struct config_item *item,
497 const char *page, size_t len)
501 ret = kstrtou16(page, 0, &val);
504 if (DIV_ROUND_UP(val, 8) > 0xff)
506 to_config_usb_cfg(item)->c.MaxPower = val;
510 static ssize_t gadget_config_desc_bmAttributes_show(struct config_item *item,
513 return sprintf(page, "0x%02x\n",
514 to_config_usb_cfg(item)->c.bmAttributes);
517 static ssize_t gadget_config_desc_bmAttributes_store(struct config_item *item,
518 const char *page, size_t len)
522 ret = kstrtou8(page, 0, &val);
525 if (!(val & USB_CONFIG_ATT_ONE))
527 if (val & ~(USB_CONFIG_ATT_ONE | USB_CONFIG_ATT_SELFPOWER |
528 USB_CONFIG_ATT_WAKEUP))
530 to_config_usb_cfg(item)->c.bmAttributes = val;
534 CONFIGFS_ATTR(gadget_config_desc_, MaxPower);
535 CONFIGFS_ATTR(gadget_config_desc_, bmAttributes);
537 static struct configfs_attribute *gadget_config_attrs[] = {
538 &gadget_config_desc_attr_MaxPower,
539 &gadget_config_desc_attr_bmAttributes,
543 static struct config_item_type gadget_config_type = {
544 .ct_item_ops = &gadget_config_item_ops,
545 .ct_attrs = gadget_config_attrs,
546 .ct_owner = THIS_MODULE,
549 static struct config_item_type gadget_root_type = {
550 .ct_item_ops = &gadget_root_item_ops,
551 .ct_attrs = gadget_root_attrs,
552 .ct_owner = THIS_MODULE,
555 static void composite_init_dev(struct usb_composite_dev *cdev)
557 spin_lock_init(&cdev->lock);
558 INIT_LIST_HEAD(&cdev->configs);
559 INIT_LIST_HEAD(&cdev->gstrings);
562 static struct config_group *function_make(
563 struct config_group *group,
566 struct gadget_info *gi;
567 struct usb_function_instance *fi;
568 char buf[MAX_NAME_LEN];
573 ret = snprintf(buf, MAX_NAME_LEN, "%s", name);
574 if (ret >= MAX_NAME_LEN)
575 return ERR_PTR(-ENAMETOOLONG);
578 instance_name = strchr(func_name, '.');
579 if (!instance_name) {
580 pr_err("Unable to locate . in FUNC.INSTANCE\n");
581 return ERR_PTR(-EINVAL);
583 *instance_name = '\0';
586 fi = usb_get_function_instance(func_name);
590 ret = config_item_set_name(&fi->group.cg_item, "%s", name);
592 usb_put_function_instance(fi);
595 if (fi->set_inst_name) {
596 ret = fi->set_inst_name(fi, instance_name);
598 usb_put_function_instance(fi);
603 gi = container_of(group, struct gadget_info, functions_group);
605 mutex_lock(&gi->lock);
606 list_add_tail(&fi->cfs_list, &gi->available_func);
607 mutex_unlock(&gi->lock);
611 static void function_drop(
612 struct config_group *group,
613 struct config_item *item)
615 struct usb_function_instance *fi = to_usb_function_instance(item);
616 struct gadget_info *gi;
618 gi = container_of(group, struct gadget_info, functions_group);
620 mutex_lock(&gi->lock);
621 list_del(&fi->cfs_list);
622 mutex_unlock(&gi->lock);
623 config_item_put(item);
626 static struct configfs_group_operations functions_ops = {
627 .make_group = &function_make,
628 .drop_item = &function_drop,
631 static struct config_item_type functions_type = {
632 .ct_group_ops = &functions_ops,
633 .ct_owner = THIS_MODULE,
636 GS_STRINGS_RW(gadget_config_name, configuration);
638 static struct configfs_attribute *gadget_config_name_langid_attrs[] = {
639 &gadget_config_name_attr_configuration,
643 static void gadget_config_name_attr_release(struct config_item *item)
645 struct gadget_config_name *cn = to_gadget_config_name(item);
647 kfree(cn->configuration);
653 USB_CONFIG_STRING_RW_OPS(gadget_config_name);
654 USB_CONFIG_STRINGS_LANG(gadget_config_name, config_usb_cfg);
656 static struct config_group *config_desc_make(
657 struct config_group *group,
660 struct gadget_info *gi;
661 struct config_usb_cfg *cfg;
662 char buf[MAX_NAME_LEN];
667 gi = container_of(group, struct gadget_info, configs_group);
668 ret = snprintf(buf, MAX_NAME_LEN, "%s", name);
669 if (ret >= MAX_NAME_LEN)
670 return ERR_PTR(-ENAMETOOLONG);
672 num_str = strchr(buf, '.');
674 pr_err("Unable to locate . in name.bConfigurationValue\n");
675 return ERR_PTR(-EINVAL);
682 return ERR_PTR(-EINVAL);
684 ret = kstrtou8(num_str, 0, &num);
688 cfg = kzalloc(sizeof(*cfg), GFP_KERNEL);
690 return ERR_PTR(-ENOMEM);
691 cfg->c.label = kstrdup(buf, GFP_KERNEL);
696 cfg->c.bConfigurationValue = num;
697 cfg->c.MaxPower = CONFIG_USB_GADGET_VBUS_DRAW;
698 cfg->c.bmAttributes = USB_CONFIG_ATT_ONE;
699 INIT_LIST_HEAD(&cfg->string_list);
700 INIT_LIST_HEAD(&cfg->func_list);
702 cfg->group.default_groups = cfg->default_groups;
703 cfg->default_groups[0] = &cfg->strings_group;
705 config_group_init_type_name(&cfg->group, name,
706 &gadget_config_type);
707 config_group_init_type_name(&cfg->strings_group, "strings",
708 &gadget_config_name_strings_type);
710 ret = usb_add_config_only(&gi->cdev, &cfg->c);
721 static void config_desc_drop(
722 struct config_group *group,
723 struct config_item *item)
725 config_item_put(item);
728 static struct configfs_group_operations config_desc_ops = {
729 .make_group = &config_desc_make,
730 .drop_item = &config_desc_drop,
733 static struct config_item_type config_desc_type = {
734 .ct_group_ops = &config_desc_ops,
735 .ct_owner = THIS_MODULE,
738 GS_STRINGS_RW(gadget_strings, manufacturer);
739 GS_STRINGS_RW(gadget_strings, product);
740 GS_STRINGS_RW(gadget_strings, serialnumber);
742 static struct configfs_attribute *gadget_strings_langid_attrs[] = {
743 &gadget_strings_attr_manufacturer,
744 &gadget_strings_attr_product,
745 &gadget_strings_attr_serialnumber,
749 static void gadget_strings_attr_release(struct config_item *item)
751 struct gadget_strings *gs = to_gadget_strings(item);
753 kfree(gs->manufacturer);
755 kfree(gs->serialnumber);
761 USB_CONFIG_STRING_RW_OPS(gadget_strings);
762 USB_CONFIG_STRINGS_LANG(gadget_strings, gadget_info);
764 static inline struct os_desc *to_os_desc(struct config_item *item)
766 return container_of(to_config_group(item), struct os_desc, group);
769 static inline struct gadget_info *os_desc_item_to_gadget_info(
770 struct config_item *item)
772 return to_gadget_info(to_os_desc(item)->group.cg_item.ci_parent);
775 static ssize_t os_desc_use_show(struct config_item *item, char *page)
777 return sprintf(page, "%d",
778 os_desc_item_to_gadget_info(item)->use_os_desc);
781 static ssize_t os_desc_use_store(struct config_item *item, const char *page,
784 struct gadget_info *gi = os_desc_item_to_gadget_info(item);
788 mutex_lock(&gi->lock);
789 ret = strtobool(page, &use);
791 gi->use_os_desc = use;
794 mutex_unlock(&gi->lock);
799 static ssize_t os_desc_b_vendor_code_show(struct config_item *item, char *page)
801 return sprintf(page, "%d",
802 os_desc_item_to_gadget_info(item)->b_vendor_code);
805 static ssize_t os_desc_b_vendor_code_store(struct config_item *item,
806 const char *page, size_t len)
808 struct gadget_info *gi = os_desc_item_to_gadget_info(item);
812 mutex_lock(&gi->lock);
813 ret = kstrtou8(page, 0, &b_vendor_code);
815 gi->b_vendor_code = b_vendor_code;
818 mutex_unlock(&gi->lock);
823 static ssize_t os_desc_qw_sign_show(struct config_item *item, char *page)
825 struct gadget_info *gi = os_desc_item_to_gadget_info(item);
827 memcpy(page, gi->qw_sign, OS_STRING_QW_SIGN_LEN);
828 return OS_STRING_QW_SIGN_LEN;
831 static ssize_t os_desc_qw_sign_store(struct config_item *item, const char *page,
834 struct gadget_info *gi = os_desc_item_to_gadget_info(item);
837 l = min((int)len, OS_STRING_QW_SIGN_LEN >> 1);
838 if (page[l - 1] == '\n')
841 mutex_lock(&gi->lock);
842 res = utf8s_to_utf16s(page, l,
843 UTF16_LITTLE_ENDIAN, (wchar_t *) gi->qw_sign,
844 OS_STRING_QW_SIGN_LEN);
847 mutex_unlock(&gi->lock);
852 CONFIGFS_ATTR(os_desc_, use);
853 CONFIGFS_ATTR(os_desc_, b_vendor_code);
854 CONFIGFS_ATTR(os_desc_, qw_sign);
856 static struct configfs_attribute *os_desc_attrs[] = {
858 &os_desc_attr_b_vendor_code,
859 &os_desc_attr_qw_sign,
863 static void os_desc_attr_release(struct config_item *item)
865 struct os_desc *os_desc = to_os_desc(item);
869 static int os_desc_link(struct config_item *os_desc_ci,
870 struct config_item *usb_cfg_ci)
872 struct gadget_info *gi = container_of(to_config_group(os_desc_ci),
873 struct gadget_info, os_desc_group);
874 struct usb_composite_dev *cdev = &gi->cdev;
875 struct config_usb_cfg *c_target =
876 container_of(to_config_group(usb_cfg_ci),
877 struct config_usb_cfg, group);
878 struct usb_configuration *c;
881 mutex_lock(&gi->lock);
882 list_for_each_entry(c, &cdev->configs, list) {
883 if (c == &c_target->c)
886 if (c != &c_target->c) {
891 if (cdev->os_desc_config) {
896 cdev->os_desc_config = &c_target->c;
900 mutex_unlock(&gi->lock);
904 static int os_desc_unlink(struct config_item *os_desc_ci,
905 struct config_item *usb_cfg_ci)
907 struct gadget_info *gi = container_of(to_config_group(os_desc_ci),
908 struct gadget_info, os_desc_group);
909 struct usb_composite_dev *cdev = &gi->cdev;
911 mutex_lock(&gi->lock);
913 unregister_gadget(gi);
914 cdev->os_desc_config = NULL;
915 WARN_ON(gi->udc_name);
916 mutex_unlock(&gi->lock);
920 static struct configfs_item_operations os_desc_ops = {
921 .release = os_desc_attr_release,
922 .allow_link = os_desc_link,
923 .drop_link = os_desc_unlink,
926 static struct config_item_type os_desc_type = {
927 .ct_item_ops = &os_desc_ops,
928 .ct_attrs = os_desc_attrs,
929 .ct_owner = THIS_MODULE,
932 static inline struct usb_os_desc_ext_prop
933 *to_usb_os_desc_ext_prop(struct config_item *item)
935 return container_of(item, struct usb_os_desc_ext_prop, item);
938 static ssize_t ext_prop_type_show(struct config_item *item, char *page)
940 return sprintf(page, "%d", to_usb_os_desc_ext_prop(item)->type);
943 static ssize_t ext_prop_type_store(struct config_item *item,
944 const char *page, size_t len)
946 struct usb_os_desc_ext_prop *ext_prop = to_usb_os_desc_ext_prop(item);
947 struct usb_os_desc *desc = to_usb_os_desc(ext_prop->item.ci_parent);
951 if (desc->opts_mutex)
952 mutex_lock(desc->opts_mutex);
953 ret = kstrtou8(page, 0, &type);
956 if (type < USB_EXT_PROP_UNICODE || type > USB_EXT_PROP_UNICODE_MULTI) {
961 if ((ext_prop->type == USB_EXT_PROP_BINARY ||
962 ext_prop->type == USB_EXT_PROP_LE32 ||
963 ext_prop->type == USB_EXT_PROP_BE32) &&
964 (type == USB_EXT_PROP_UNICODE ||
965 type == USB_EXT_PROP_UNICODE_ENV ||
966 type == USB_EXT_PROP_UNICODE_LINK))
967 ext_prop->data_len <<= 1;
968 else if ((ext_prop->type == USB_EXT_PROP_UNICODE ||
969 ext_prop->type == USB_EXT_PROP_UNICODE_ENV ||
970 ext_prop->type == USB_EXT_PROP_UNICODE_LINK) &&
971 (type == USB_EXT_PROP_BINARY ||
972 type == USB_EXT_PROP_LE32 ||
973 type == USB_EXT_PROP_BE32))
974 ext_prop->data_len >>= 1;
975 ext_prop->type = type;
979 if (desc->opts_mutex)
980 mutex_unlock(desc->opts_mutex);
984 static ssize_t ext_prop_data_show(struct config_item *item, char *page)
986 struct usb_os_desc_ext_prop *ext_prop = to_usb_os_desc_ext_prop(item);
987 int len = ext_prop->data_len;
989 if (ext_prop->type == USB_EXT_PROP_UNICODE ||
990 ext_prop->type == USB_EXT_PROP_UNICODE_ENV ||
991 ext_prop->type == USB_EXT_PROP_UNICODE_LINK)
993 memcpy(page, ext_prop->data, len);
998 static ssize_t ext_prop_data_store(struct config_item *item,
999 const char *page, size_t len)
1001 struct usb_os_desc_ext_prop *ext_prop = to_usb_os_desc_ext_prop(item);
1002 struct usb_os_desc *desc = to_usb_os_desc(ext_prop->item.ci_parent);
1004 size_t ret_len = len;
1006 if (page[len - 1] == '\n' || page[len - 1] == '\0')
1008 new_data = kmemdup(page, len, GFP_KERNEL);
1012 if (desc->opts_mutex)
1013 mutex_lock(desc->opts_mutex);
1014 kfree(ext_prop->data);
1015 ext_prop->data = new_data;
1016 desc->ext_prop_len -= ext_prop->data_len;
1017 ext_prop->data_len = len;
1018 desc->ext_prop_len += ext_prop->data_len;
1019 if (ext_prop->type == USB_EXT_PROP_UNICODE ||
1020 ext_prop->type == USB_EXT_PROP_UNICODE_ENV ||
1021 ext_prop->type == USB_EXT_PROP_UNICODE_LINK) {
1022 desc->ext_prop_len -= ext_prop->data_len;
1023 ext_prop->data_len <<= 1;
1024 ext_prop->data_len += 2;
1025 desc->ext_prop_len += ext_prop->data_len;
1027 if (desc->opts_mutex)
1028 mutex_unlock(desc->opts_mutex);
1032 CONFIGFS_ATTR(ext_prop_, type);
1033 CONFIGFS_ATTR(ext_prop_, data);
1035 static struct configfs_attribute *ext_prop_attrs[] = {
1036 &ext_prop_attr_type,
1037 &ext_prop_attr_data,
1041 static void usb_os_desc_ext_prop_release(struct config_item *item)
1043 struct usb_os_desc_ext_prop *ext_prop = to_usb_os_desc_ext_prop(item);
1045 kfree(ext_prop); /* frees a whole chunk */
1048 static struct configfs_item_operations ext_prop_ops = {
1049 .release = usb_os_desc_ext_prop_release,
1052 static struct config_item *ext_prop_make(
1053 struct config_group *group,
1056 struct usb_os_desc_ext_prop *ext_prop;
1057 struct config_item_type *ext_prop_type;
1058 struct usb_os_desc *desc;
1061 vla_group(data_chunk);
1062 vla_item(data_chunk, struct usb_os_desc_ext_prop, ext_prop, 1);
1063 vla_item(data_chunk, struct config_item_type, ext_prop_type, 1);
1065 vlabuf = kzalloc(vla_group_size(data_chunk), GFP_KERNEL);
1067 return ERR_PTR(-ENOMEM);
1069 ext_prop = vla_ptr(vlabuf, data_chunk, ext_prop);
1070 ext_prop_type = vla_ptr(vlabuf, data_chunk, ext_prop_type);
1072 desc = container_of(group, struct usb_os_desc, group);
1073 ext_prop_type->ct_item_ops = &ext_prop_ops;
1074 ext_prop_type->ct_attrs = ext_prop_attrs;
1075 ext_prop_type->ct_owner = desc->owner;
1077 config_item_init_type_name(&ext_prop->item, name, ext_prop_type);
1079 ext_prop->name = kstrdup(name, GFP_KERNEL);
1080 if (!ext_prop->name) {
1082 return ERR_PTR(-ENOMEM);
1084 desc->ext_prop_len += 14;
1085 ext_prop->name_len = 2 * strlen(ext_prop->name) + 2;
1086 if (desc->opts_mutex)
1087 mutex_lock(desc->opts_mutex);
1088 desc->ext_prop_len += ext_prop->name_len;
1089 list_add_tail(&ext_prop->entry, &desc->ext_prop);
1090 ++desc->ext_prop_count;
1091 if (desc->opts_mutex)
1092 mutex_unlock(desc->opts_mutex);
1094 return &ext_prop->item;
1097 static void ext_prop_drop(struct config_group *group, struct config_item *item)
1099 struct usb_os_desc_ext_prop *ext_prop = to_usb_os_desc_ext_prop(item);
1100 struct usb_os_desc *desc = to_usb_os_desc(&group->cg_item);
1102 if (desc->opts_mutex)
1103 mutex_lock(desc->opts_mutex);
1104 list_del(&ext_prop->entry);
1105 --desc->ext_prop_count;
1106 kfree(ext_prop->name);
1107 desc->ext_prop_len -= (ext_prop->name_len + ext_prop->data_len + 14);
1108 if (desc->opts_mutex)
1109 mutex_unlock(desc->opts_mutex);
1110 config_item_put(item);
1113 static struct configfs_group_operations interf_grp_ops = {
1114 .make_item = &ext_prop_make,
1115 .drop_item = &ext_prop_drop,
1118 static ssize_t interf_grp_compatible_id_show(struct config_item *item,
1121 memcpy(page, to_usb_os_desc(item)->ext_compat_id, 8);
1125 static ssize_t interf_grp_compatible_id_store(struct config_item *item,
1126 const char *page, size_t len)
1128 struct usb_os_desc *desc = to_usb_os_desc(item);
1131 l = min_t(int, 8, len);
1132 if (page[l - 1] == '\n')
1134 if (desc->opts_mutex)
1135 mutex_lock(desc->opts_mutex);
1136 memcpy(desc->ext_compat_id, page, l);
1138 if (desc->opts_mutex)
1139 mutex_unlock(desc->opts_mutex);
1144 static ssize_t interf_grp_sub_compatible_id_show(struct config_item *item,
1147 memcpy(page, to_usb_os_desc(item)->ext_compat_id + 8, 8);
1151 static ssize_t interf_grp_sub_compatible_id_store(struct config_item *item,
1152 const char *page, size_t len)
1154 struct usb_os_desc *desc = to_usb_os_desc(item);
1157 l = min_t(int, 8, len);
1158 if (page[l - 1] == '\n')
1160 if (desc->opts_mutex)
1161 mutex_lock(desc->opts_mutex);
1162 memcpy(desc->ext_compat_id + 8, page, l);
1164 if (desc->opts_mutex)
1165 mutex_unlock(desc->opts_mutex);
1170 CONFIGFS_ATTR(interf_grp_, compatible_id);
1171 CONFIGFS_ATTR(interf_grp_, sub_compatible_id);
1173 static struct configfs_attribute *interf_grp_attrs[] = {
1174 &interf_grp_attr_compatible_id,
1175 &interf_grp_attr_sub_compatible_id,
1179 int usb_os_desc_prepare_interf_dir(struct config_group *parent,
1181 struct usb_os_desc **desc,
1183 struct module *owner)
1185 struct config_group **f_default_groups, *os_desc_group,
1187 struct config_item_type *os_desc_type, *interface_type;
1189 vla_group(data_chunk);
1190 vla_item(data_chunk, struct config_group *, f_default_groups, 2);
1191 vla_item(data_chunk, struct config_group, os_desc_group, 1);
1192 vla_item(data_chunk, struct config_group *, interface_groups,
1194 vla_item(data_chunk, struct config_item_type, os_desc_type, 1);
1195 vla_item(data_chunk, struct config_item_type, interface_type, 1);
1197 char *vlabuf = kzalloc(vla_group_size(data_chunk), GFP_KERNEL);
1201 f_default_groups = vla_ptr(vlabuf, data_chunk, f_default_groups);
1202 os_desc_group = vla_ptr(vlabuf, data_chunk, os_desc_group);
1203 os_desc_type = vla_ptr(vlabuf, data_chunk, os_desc_type);
1204 interface_groups = vla_ptr(vlabuf, data_chunk, interface_groups);
1205 interface_type = vla_ptr(vlabuf, data_chunk, interface_type);
1207 parent->default_groups = f_default_groups;
1208 os_desc_type->ct_owner = owner;
1209 config_group_init_type_name(os_desc_group, "os_desc", os_desc_type);
1210 f_default_groups[0] = os_desc_group;
1212 os_desc_group->default_groups = interface_groups;
1213 interface_type->ct_group_ops = &interf_grp_ops;
1214 interface_type->ct_attrs = interf_grp_attrs;
1215 interface_type->ct_owner = owner;
1217 while (n_interf--) {
1218 struct usb_os_desc *d;
1222 config_group_init_type_name(&d->group, "", interface_type);
1223 config_item_set_name(&d->group.cg_item, "interface.%s",
1225 interface_groups[n_interf] = &d->group;
1230 EXPORT_SYMBOL(usb_os_desc_prepare_interf_dir);
1232 static int configfs_do_nothing(struct usb_composite_dev *cdev)
1238 int composite_dev_prepare(struct usb_composite_driver *composite,
1239 struct usb_composite_dev *dev);
1241 int composite_os_desc_req_prepare(struct usb_composite_dev *cdev,
1242 struct usb_ep *ep0);
1244 static void purge_configs_funcs(struct gadget_info *gi)
1246 struct usb_configuration *c;
1248 list_for_each_entry(c, &gi->cdev.configs, list) {
1249 struct usb_function *f, *tmp;
1250 struct config_usb_cfg *cfg;
1252 cfg = container_of(c, struct config_usb_cfg, c);
1254 list_for_each_entry_safe(f, tmp, &c->functions, list) {
1256 list_move_tail(&f->list, &cfg->func_list);
1258 dev_err(&gi->cdev.gadget->dev, "unbind function"
1259 " '%s'/%p\n", f->name, f);
1263 c->next_interface_id = 0;
1264 memset(c->interface, 0, sizeof(c->interface));
1271 static int configfs_composite_bind(struct usb_gadget *gadget,
1272 struct usb_gadget_driver *gdriver)
1274 struct usb_composite_driver *composite = to_cdriver(gdriver);
1275 struct gadget_info *gi = container_of(composite,
1276 struct gadget_info, composite);
1277 struct usb_composite_dev *cdev = &gi->cdev;
1278 struct usb_configuration *c;
1279 struct usb_string *s;
1283 /* the gi->lock is hold by the caller */
1284 cdev->gadget = gadget;
1285 set_gadget_data(gadget, cdev);
1286 ret = composite_dev_prepare(composite, cdev);
1289 /* and now the gadget bind */
1292 if (list_empty(&gi->cdev.configs)) {
1293 pr_err("Need at least one configuration in %s.\n",
1294 gi->composite.name);
1295 goto err_comp_cleanup;
1299 list_for_each_entry(c, &gi->cdev.configs, list) {
1300 struct config_usb_cfg *cfg;
1302 cfg = container_of(c, struct config_usb_cfg, c);
1303 if (list_empty(&cfg->func_list)) {
1304 pr_err("Config %s/%d of %s needs at least one function.\n",
1305 c->label, c->bConfigurationValue,
1306 gi->composite.name);
1307 goto err_comp_cleanup;
1311 /* init all strings */
1312 if (!list_empty(&gi->string_list)) {
1313 struct gadget_strings *gs;
1316 list_for_each_entry(gs, &gi->string_list, list) {
1318 gi->gstrings[i] = &gs->stringtab_dev;
1319 gs->stringtab_dev.strings = gs->strings;
1320 gs->strings[USB_GADGET_MANUFACTURER_IDX].s =
1322 gs->strings[USB_GADGET_PRODUCT_IDX].s = gs->product;
1323 gs->strings[USB_GADGET_SERIAL_IDX].s = gs->serialnumber;
1326 gi->gstrings[i] = NULL;
1327 s = usb_gstrings_attach(&gi->cdev, gi->gstrings,
1328 USB_GADGET_FIRST_AVAIL_IDX);
1331 goto err_comp_cleanup;
1334 gi->cdev.desc.iManufacturer = s[USB_GADGET_MANUFACTURER_IDX].id;
1335 gi->cdev.desc.iProduct = s[USB_GADGET_PRODUCT_IDX].id;
1336 gi->cdev.desc.iSerialNumber = s[USB_GADGET_SERIAL_IDX].id;
1339 if (gi->use_os_desc) {
1340 cdev->use_os_string = true;
1341 cdev->b_vendor_code = gi->b_vendor_code;
1342 memcpy(cdev->qw_sign, gi->qw_sign, OS_STRING_QW_SIGN_LEN);
1345 if (gadget_is_otg(gadget) && !otg_desc[0]) {
1346 struct usb_descriptor_header *usb_desc;
1348 usb_desc = usb_otg_descriptor_alloc(gadget);
1351 goto err_comp_cleanup;
1353 usb_otg_descriptor_init(gadget, usb_desc);
1354 otg_desc[0] = usb_desc;
1358 /* Go through all configs, attach all functions */
1359 list_for_each_entry(c, &gi->cdev.configs, list) {
1360 struct config_usb_cfg *cfg;
1361 struct usb_function *f;
1362 struct usb_function *tmp;
1363 struct gadget_config_name *cn;
1365 if (gadget_is_otg(gadget))
1366 c->descriptors = otg_desc;
1368 cfg = container_of(c, struct config_usb_cfg, c);
1369 if (!list_empty(&cfg->string_list)) {
1371 list_for_each_entry(cn, &cfg->string_list, list) {
1372 cfg->gstrings[i] = &cn->stringtab_dev;
1373 cn->stringtab_dev.strings = &cn->strings;
1374 cn->strings.s = cn->configuration;
1377 cfg->gstrings[i] = NULL;
1378 s = usb_gstrings_attach(&gi->cdev, cfg->gstrings, 1);
1381 goto err_comp_cleanup;
1383 c->iConfiguration = s[0].id;
1386 list_for_each_entry_safe(f, tmp, &cfg->func_list, list) {
1388 ret = usb_add_function(c, f);
1390 list_add(&f->list, &cfg->func_list);
1391 goto err_purge_funcs;
1394 usb_ep_autoconfig_reset(cdev->gadget);
1396 if (cdev->use_os_string) {
1397 ret = composite_os_desc_req_prepare(cdev, gadget->ep0);
1399 goto err_purge_funcs;
1402 usb_ep_autoconfig_reset(cdev->gadget);
1406 purge_configs_funcs(gi);
1408 composite_dev_cleanup(cdev);
1412 #ifdef CONFIG_USB_CONFIGFS_UEVENT
1413 static void android_work(struct work_struct *data)
1415 struct gadget_info *gi = container_of(data, struct gadget_info, work);
1416 struct usb_composite_dev *cdev = &gi->cdev;
1417 char *disconnected[2] = { "USB_STATE=DISCONNECTED", NULL };
1418 char *connected[2] = { "USB_STATE=CONNECTED", NULL };
1419 char *configured[2] = { "USB_STATE=CONFIGURED", NULL };
1420 /* 0-connected 1-configured 2-disconnected*/
1421 bool status[3] = { false, false, false };
1422 unsigned long flags;
1423 bool uevent_sent = false;
1425 spin_lock_irqsave(&cdev->lock, flags);
1429 if (gi->connected != gi->sw_connected) {
1434 gi->sw_connected = gi->connected;
1436 spin_unlock_irqrestore(&cdev->lock, flags);
1439 kobject_uevent_env(&android_device->kobj,
1440 KOBJ_CHANGE, connected);
1441 pr_info("%s: sent uevent %s\n", __func__, connected[0]);
1446 kobject_uevent_env(&android_device->kobj,
1447 KOBJ_CHANGE, configured);
1448 pr_info("%s: sent uevent %s\n", __func__, configured[0]);
1453 kobject_uevent_env(&android_device->kobj,
1454 KOBJ_CHANGE, disconnected);
1455 pr_info("%s: sent uevent %s\n", __func__, disconnected[0]);
1460 pr_info("%s: did not send uevent (%d %d %p)\n", __func__,
1461 gi->connected, gi->sw_connected, cdev->config);
1466 static void configfs_composite_unbind(struct usb_gadget *gadget)
1468 struct usb_composite_dev *cdev;
1469 struct gadget_info *gi;
1471 /* the gi->lock is hold by the caller */
1473 cdev = get_gadget_data(gadget);
1474 gi = container_of(cdev, struct gadget_info, cdev);
1478 purge_configs_funcs(gi);
1479 composite_dev_cleanup(cdev);
1480 usb_ep_autoconfig_reset(cdev->gadget);
1481 cdev->gadget = NULL;
1482 set_gadget_data(gadget, NULL);
1485 #ifdef CONFIG_USB_CONFIGFS_UEVENT
1486 static int android_setup(struct usb_gadget *gadget,
1487 const struct usb_ctrlrequest *c)
1489 struct usb_composite_dev *cdev = get_gadget_data(gadget);
1490 unsigned long flags;
1491 struct gadget_info *gi = container_of(cdev, struct gadget_info, cdev);
1492 int value = -EOPNOTSUPP;
1493 struct usb_function_instance *fi;
1495 spin_lock_irqsave(&cdev->lock, flags);
1496 if (!gi->connected) {
1498 schedule_work(&gi->work);
1500 spin_unlock_irqrestore(&cdev->lock, flags);
1501 list_for_each_entry(fi, &gi->available_func, cfs_list) {
1502 if (fi != NULL && fi->f != NULL && fi->f->setup != NULL) {
1503 value = fi->f->setup(fi->f, c);
1509 #ifdef CONFIG_USB_CONFIGFS_F_ACC
1511 value = acc_ctrlrequest(cdev, c);
1515 value = composite_setup(gadget, c);
1517 spin_lock_irqsave(&cdev->lock, flags);
1518 if (c->bRequest == USB_REQ_SET_CONFIGURATION &&
1520 schedule_work(&gi->work);
1522 spin_unlock_irqrestore(&cdev->lock, flags);
1527 static void android_disconnect(struct usb_gadget *gadget)
1529 struct usb_composite_dev *cdev = get_gadget_data(gadget);
1530 struct gadget_info *gi = container_of(cdev, struct gadget_info, cdev);
1532 /* accessory HID support can be active while the
1533 accessory function is not actually enabled,
1534 so we need to inform it when we are disconnected.
1537 #ifdef CONFIG_USB_CONFIGFS_F_ACC
1541 schedule_work(&gi->work);
1542 composite_disconnect(gadget);
1546 static const struct usb_gadget_driver configfs_driver_template = {
1547 .bind = configfs_composite_bind,
1548 .unbind = configfs_composite_unbind,
1549 #ifdef CONFIG_USB_CONFIGFS_UEVENT
1550 .setup = android_setup,
1551 .disconnect = android_disconnect,
1553 .setup = composite_setup,
1554 .reset = composite_disconnect,
1555 .disconnect = composite_disconnect,
1557 .suspend = composite_suspend,
1558 .resume = composite_resume,
1560 .max_speed = USB_SPEED_SUPER,
1562 .owner = THIS_MODULE,
1563 .name = "configfs-gadget",
1567 #ifdef CONFIG_USB_CONFIGFS_UEVENT
1568 static ssize_t state_show(struct device *pdev, struct device_attribute *attr,
1571 struct gadget_info *dev = dev_get_drvdata(pdev);
1572 struct usb_composite_dev *cdev;
1573 char *state = "DISCONNECTED";
1574 unsigned long flags;
1584 spin_lock_irqsave(&cdev->lock, flags);
1586 state = "CONFIGURED";
1587 else if (dev->connected)
1588 state = "CONNECTED";
1589 spin_unlock_irqrestore(&cdev->lock, flags);
1591 return sprintf(buf, "%s\n", state);
1594 static DEVICE_ATTR(state, S_IRUGO, state_show, NULL);
1596 static struct device_attribute *android_usb_attributes[] = {
1602 static struct config_group *gadgets_make(
1603 struct config_group *group,
1606 struct gadget_info *gi;
1607 struct device_attribute **attrs;
1608 struct device_attribute *attr;
1611 gi = kzalloc(sizeof(*gi), GFP_KERNEL);
1613 return ERR_PTR(-ENOMEM);
1614 gi->group.default_groups = gi->default_groups;
1615 gi->group.default_groups[0] = &gi->functions_group;
1616 gi->group.default_groups[1] = &gi->configs_group;
1617 gi->group.default_groups[2] = &gi->strings_group;
1618 gi->group.default_groups[3] = &gi->os_desc_group;
1620 config_group_init_type_name(&gi->functions_group, "functions",
1622 config_group_init_type_name(&gi->configs_group, "configs",
1624 config_group_init_type_name(&gi->strings_group, "strings",
1625 &gadget_strings_strings_type);
1626 config_group_init_type_name(&gi->os_desc_group, "os_desc",
1629 gi->composite.bind = configfs_do_nothing;
1630 gi->composite.unbind = configfs_do_nothing;
1631 gi->composite.suspend = NULL;
1632 gi->composite.resume = NULL;
1633 gi->composite.max_speed = USB_SPEED_SUPER;
1635 mutex_init(&gi->lock);
1636 INIT_LIST_HEAD(&gi->string_list);
1637 INIT_LIST_HEAD(&gi->available_func);
1639 composite_init_dev(&gi->cdev);
1640 gi->cdev.desc.bLength = USB_DT_DEVICE_SIZE;
1641 gi->cdev.desc.bDescriptorType = USB_DT_DEVICE;
1642 gi->cdev.desc.bcdDevice = cpu_to_le16(get_default_bcdDevice());
1644 gi->composite.gadget_driver = configfs_driver_template;
1646 gi->composite.gadget_driver.function = kstrdup(name, GFP_KERNEL);
1647 gi->composite.name = gi->composite.gadget_driver.function;
1649 #ifdef CONFIG_USB_CONFIGFS_UEVENT
1650 INIT_WORK(&gi->work, android_work);
1651 android_device = device_create(android_class, NULL,
1652 MKDEV(0, 0), NULL, "android0");
1653 if (IS_ERR(android_device))
1656 dev_set_drvdata(android_device, gi);
1658 attrs = android_usb_attributes;
1659 while ((attr = *attrs++)) {
1660 err = device_create_file(android_device, attr);
1666 if (!gi->composite.gadget_driver.function)
1669 config_group_init_type_name(&gi->group, name,
1674 #ifdef CONFIG_USB_CONFIGFS_UEVENT
1675 attrs = android_usb_attributes;
1676 while ((attr = *attrs++))
1677 device_remove_file(android_device, attr);
1679 device_destroy(android_device->class,
1680 android_device->devt);
1684 return ERR_PTR(-ENOMEM);
1687 static void gadgets_drop(struct config_group *group, struct config_item *item)
1689 struct device_attribute **attrs;
1690 struct device_attribute *attr;
1692 config_item_put(item);
1694 #ifdef CONFIG_USB_CONFIGFS_UEVENT
1695 attrs = android_usb_attributes;
1696 while ((attr = *attrs++))
1697 device_remove_file(android_device, attr);
1698 device_destroy(android_device->class, android_device->devt);
1702 static struct configfs_group_operations gadgets_ops = {
1703 .make_group = &gadgets_make,
1704 .drop_item = &gadgets_drop,
1707 static struct config_item_type gadgets_type = {
1708 .ct_group_ops = &gadgets_ops,
1709 .ct_owner = THIS_MODULE,
1712 static struct configfs_subsystem gadget_subsys = {
1715 .ci_namebuf = "usb_gadget",
1716 .ci_type = &gadgets_type,
1719 .su_mutex = __MUTEX_INITIALIZER(gadget_subsys.su_mutex),
1722 void unregister_gadget_item(struct config_item *item)
1724 struct gadget_info *gi = to_gadget_info(item);
1726 unregister_gadget(gi);
1728 EXPORT_SYMBOL_GPL(unregister_gadget_item);
1730 static int __init gadget_cfs_init(void)
1734 config_group_init(&gadget_subsys.su_group);
1736 ret = configfs_register_subsystem(&gadget_subsys);
1738 #ifdef CONFIG_USB_CONFIGFS_UEVENT
1739 android_class = class_create(THIS_MODULE, "android_usb");
1740 if (IS_ERR(android_class))
1741 return PTR_ERR(android_class);
1746 module_init(gadget_cfs_init);
1748 static void __exit gadget_cfs_exit(void)
1750 configfs_unregister_subsystem(&gadget_subsys);
1751 #ifdef CONFIG_USB_CONFIGFS_UEVENT
1752 if (!IS_ERR(android_class))
1753 class_destroy(android_class);
1757 module_exit(gadget_cfs_exit);