diff options
Diffstat (limited to 'drivers/usb/gadget/g_ffs.c')
| -rw-r--r-- | drivers/usb/gadget/g_ffs.c | 627 |
1 files changed, 386 insertions, 241 deletions
diff --git a/drivers/usb/gadget/g_ffs.c b/drivers/usb/gadget/g_ffs.c index d1af253a910..fe12e6a2744 100644 --- a/drivers/usb/gadget/g_ffs.c +++ b/drivers/usb/gadget/g_ffs.c @@ -1,21 +1,22 @@ -#include <linux/module.h> -#include <linux/utsname.h> - - /* - * kbuild is not very cooperative with respect to linking separately - * compiled library objects into one module. So for now we won't use - * separate compilation ... ensuring init/exit sections work to shrink - * the runtime footprint, and giving us at least some parts of what - * a "gcc --combine ... part1.c part2.c part3.c ... " build would. + * g_ffs.c -- user mode file system API for USB composite function controllers + * + * Copyright (C) 2010 Samsung Electronics + * Author: Michal Nazarewicz <mina86@mina86.com> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. */ -#include "composite.c" -#include "usbstring.c" -#include "config.c" -#include "epautoconf.c" +#define pr_fmt(fmt) "g_ffs: " fmt + +#include <linux/module.h> #if defined CONFIG_USB_FUNCTIONFS_ETH || defined CONFIG_USB_FUNCTIONFS_RNDIS +#include <linux/netdevice.h> + # if defined USB_ETH_RNDIS # undef USB_ETH_RNDIS # endif @@ -23,25 +24,31 @@ # define USB_ETH_RNDIS y # endif -# include "f_ecm.c" -# include "f_subset.c" +# include "u_ecm.h" +# include "u_gether.h" # ifdef USB_ETH_RNDIS -# include "f_rndis.c" -# include "rndis.c" +# include "u_rndis.h" +# include "rndis.h" # endif -# include "u_ether.c" +# include "u_ether.h" + +USB_ETHERNET_MODULE_PARAMETERS(); -static u8 gfs_hostaddr[ETH_ALEN]; -#else -# if !defined CONFIG_USB_FUNCTIONFS_GENERIC -# define CONFIG_USB_FUNCTIONFS_GENERIC +# ifdef CONFIG_USB_FUNCTIONFS_ETH +static int eth_bind_config(struct usb_configuration *c); +static struct usb_function_instance *fi_ecm; +static struct usb_function *f_ecm; +static struct usb_function_instance *fi_geth; +static struct usb_function *f_geth; +# endif +# ifdef CONFIG_USB_FUNCTIONFS_RNDIS +static int bind_rndis_config(struct usb_configuration *c); +static struct usb_function_instance *fi_rndis; +static struct usb_function *f_rndis; # endif -# define gether_cleanup() do { } while (0) -# define gether_setup(gadget, hostaddr) ((int)0) #endif -#include "f_fs.c" - +#include "u_fs.h" #define DRIVER_NAME "g_ffs" #define DRIVER_DESC "USB Function Filesystem" @@ -51,9 +58,12 @@ MODULE_DESCRIPTION(DRIVER_DESC); MODULE_AUTHOR("Michal Nazarewicz"); MODULE_LICENSE("GPL"); +#define GFS_VENDOR_ID 0x1d6b /* Linux Foundation */ +#define GFS_PRODUCT_ID 0x0105 /* FunctionFS Gadget */ -static unsigned short gfs_vendor_id = 0x0525; /* XXX NetChip */ -static unsigned short gfs_product_id = 0xa4ac; /* XXX */ +#define GFS_MAX_DEVS 10 + +USB_GADGET_COMPOSITE_OPTIONS(); static struct usb_device_descriptor gfs_dev_desc = { .bLength = sizeof gfs_dev_desc, @@ -62,31 +72,21 @@ static struct usb_device_descriptor gfs_dev_desc = { .bcdUSB = cpu_to_le16(0x0200), .bDeviceClass = USB_CLASS_PER_INTERFACE, - /* Vendor and product id can be overridden by module parameters. */ - /* .idVendor = cpu_to_le16(gfs_vendor_id), */ - /* .idProduct = cpu_to_le16(gfs_product_id), */ - /* .bcdDevice = f(hardware) */ - /* .iManufacturer = DYNAMIC */ - /* .iProduct = DYNAMIC */ - /* NO SERIAL NUMBER */ - .bNumConfigurations = 1, + .idVendor = cpu_to_le16(GFS_VENDOR_ID), + .idProduct = cpu_to_le16(GFS_PRODUCT_ID), }; -#define GFS_MODULE_PARAM_DESC(name, field) \ - MODULE_PARM_DESC(name, "Value of the " #field " field of the device descriptor sent to the host. Takes effect only prior to the user-space driver registering to the FunctionFS.") - -module_param_named(usb_class, gfs_dev_desc.bDeviceClass, byte, 0644); -GFS_MODULE_PARAM_DESC(usb_class, bDeviceClass); -module_param_named(usb_subclass, gfs_dev_desc.bDeviceSubClass, byte, 0644); -GFS_MODULE_PARAM_DESC(usb_subclass, bDeviceSubClass); -module_param_named(usb_protocol, gfs_dev_desc.bDeviceProtocol, byte, 0644); -GFS_MODULE_PARAM_DESC(usb_protocol, bDeviceProtocol); -module_param_named(usb_vendor, gfs_vendor_id, ushort, 0644); -GFS_MODULE_PARAM_DESC(usb_vendor, idVendor); -module_param_named(usb_product, gfs_product_id, ushort, 0644); -GFS_MODULE_PARAM_DESC(usb_product, idProduct); - +static char *func_names[GFS_MAX_DEVS]; +static unsigned int func_num; +module_param_named(bDeviceClass, gfs_dev_desc.bDeviceClass, byte, 0644); +MODULE_PARM_DESC(bDeviceClass, "USB Device class"); +module_param_named(bDeviceSubClass, gfs_dev_desc.bDeviceSubClass, byte, 0644); +MODULE_PARM_DESC(bDeviceSubClass, "USB Device subclass"); +module_param_named(bDeviceProtocol, gfs_dev_desc.bDeviceProtocol, byte, 0644); +MODULE_PARM_DESC(bDeviceProtocol, "USB Device protocol"); +module_param_array_named(functions, func_names, charp, &func_num, 0); +MODULE_PARM_DESC(functions, "USB Functions list"); static const struct usb_descriptor_header *gfs_otg_desc[] = { (const struct usb_descriptor_header *) @@ -94,45 +94,29 @@ static const struct usb_descriptor_header *gfs_otg_desc[] = { .bLength = sizeof(struct usb_otg_descriptor), .bDescriptorType = USB_DT_OTG, - /* REVISIT SRP-only hardware is possible, although - * it would not be called "OTG" ... */ + /* + * REVISIT SRP-only hardware is possible, although + * it would not be called "OTG" ... + */ .bmAttributes = USB_OTG_SRP | USB_OTG_HNP, }, NULL }; -/* string IDs are assigned dynamically */ - -enum { - GFS_STRING_MANUFACTURER_IDX, - GFS_STRING_PRODUCT_IDX, -#ifdef CONFIG_USB_FUNCTIONFS_RNDIS - GFS_STRING_RNDIS_CONFIG_IDX, -#endif -#ifdef CONFIG_USB_FUNCTIONFS_ETH - GFS_STRING_ECM_CONFIG_IDX, -#endif -#ifdef CONFIG_USB_FUNCTIONFS_GENERIC - GFS_STRING_GENERIC_CONFIG_IDX, -#endif -}; - -static char gfs_manufacturer[50]; -static const char gfs_driver_desc[] = DRIVER_DESC; -static const char gfs_short_name[] = DRIVER_NAME; - +/* String IDs are assigned dynamically */ static struct usb_string gfs_strings[] = { - [GFS_STRING_MANUFACTURER_IDX].s = gfs_manufacturer, - [GFS_STRING_PRODUCT_IDX].s = gfs_driver_desc, + [USB_GADGET_MANUFACTURER_IDX].s = "", + [USB_GADGET_PRODUCT_IDX].s = DRIVER_DESC, + [USB_GADGET_SERIAL_IDX].s = "", #ifdef CONFIG_USB_FUNCTIONFS_RNDIS - [GFS_STRING_RNDIS_CONFIG_IDX].s = "FunctionFS + RNDIS", + { .s = "FunctionFS + RNDIS" }, #endif #ifdef CONFIG_USB_FUNCTIONFS_ETH - [GFS_STRING_ECM_CONFIG_IDX].s = "FunctionFS + ECM", + { .s = "FunctionFS + ECM" }, #endif #ifdef CONFIG_USB_FUNCTIONFS_GENERIC - [GFS_STRING_GENERIC_CONFIG_IDX].s = "FunctionFS", + { .s = "FunctionFS" }, #endif { } /* end of list */ }; @@ -145,236 +129,361 @@ static struct usb_gadget_strings *gfs_dev_strings[] = { NULL, }; - +struct gfs_configuration { + struct usb_configuration c; + int (*eth)(struct usb_configuration *c); + int num; +} gfs_configurations[] = { #ifdef CONFIG_USB_FUNCTIONFS_RNDIS -static int gfs_do_rndis_config(struct usb_configuration *c); - -static struct usb_configuration gfs_rndis_config_driver = { - .label = "FunctionFS + RNDIS", - .bind = gfs_do_rndis_config, - .bConfigurationValue = 1, - /* .iConfiguration = DYNAMIC */ - .bmAttributes = USB_CONFIG_ATT_SELFPOWER, -}; -# define gfs_add_rndis_config(cdev) \ - usb_add_config(cdev, &gfs_rndis_config_driver) -#else -# define gfs_add_rndis_config(cdev) 0 + { + .eth = bind_rndis_config, + }, #endif - #ifdef CONFIG_USB_FUNCTIONFS_ETH -static int gfs_do_ecm_config(struct usb_configuration *c); - -static struct usb_configuration gfs_ecm_config_driver = { - .label = "FunctionFS + ECM", - .bind = gfs_do_ecm_config, - .bConfigurationValue = 1, - /* .iConfiguration = DYNAMIC */ - .bmAttributes = USB_CONFIG_ATT_SELFPOWER, -}; -# define gfs_add_ecm_config(cdev) \ - usb_add_config(cdev, &gfs_ecm_config_driver) -#else -# define gfs_add_ecm_config(cdev) 0 + { + .eth = eth_bind_config, + }, #endif - #ifdef CONFIG_USB_FUNCTIONFS_GENERIC -static int gfs_do_generic_config(struct usb_configuration *c); - -static struct usb_configuration gfs_generic_config_driver = { - .label = "FunctionFS", - .bind = gfs_do_generic_config, - .bConfigurationValue = 2, - /* .iConfiguration = DYNAMIC */ - .bmAttributes = USB_CONFIG_ATT_SELFPOWER, -}; -# define gfs_add_generic_config(cdev) \ - usb_add_config(cdev, &gfs_generic_config_driver) -#else -# define gfs_add_generic_config(cdev) 0 + { + }, #endif +}; - +static void *functionfs_acquire_dev(struct ffs_dev *dev); +static void functionfs_release_dev(struct ffs_dev *dev); +static int functionfs_ready_callback(struct ffs_data *ffs); +static void functionfs_closed_callback(struct ffs_data *ffs); static int gfs_bind(struct usb_composite_dev *cdev); static int gfs_unbind(struct usb_composite_dev *cdev); +static int gfs_do_config(struct usb_configuration *c); -static struct usb_composite_driver gfs_driver = { - .name = gfs_short_name, + +static __refdata struct usb_composite_driver gfs_driver = { + .name = DRIVER_NAME, .dev = &gfs_dev_desc, .strings = gfs_dev_strings, + .max_speed = USB_SPEED_HIGH, .bind = gfs_bind, .unbind = gfs_unbind, }; +static unsigned int missing_funcs; +static bool gfs_registered; +static bool gfs_single_func; +static struct usb_function_instance **fi_ffs; +static struct usb_function **f_ffs[] = { +#ifdef CONFIG_USB_FUNCTIONFS_RNDIS + NULL, +#endif -static struct ffs_data *gfs_ffs_data; -static unsigned long gfs_registered; +#ifdef CONFIG_USB_FUNCTIONFS_ETH + NULL, +#endif + +#ifdef CONFIG_USB_FUNCTIONFS_GENERIC + NULL, +#endif +}; +#define N_CONF ARRAY_SIZE(f_ffs) -static int gfs_init(void) +static int __init gfs_init(void) { + struct f_fs_opts *opts; + int i; + int ret = 0; + ENTER(); - return functionfs_init(); + if (func_num < 2) { + gfs_single_func = true; + func_num = 1; + } + + /* + * Allocate in one chunk for easier maintenance + */ + f_ffs[0] = kcalloc(func_num * N_CONF, sizeof(*f_ffs), GFP_KERNEL); + if (!f_ffs[0]) { + ret = -ENOMEM; + goto no_func; + } + for (i = 1; i < N_CONF; ++i) + f_ffs[i] = f_ffs[0] + i * func_num; + + fi_ffs = kcalloc(func_num, sizeof(*fi_ffs), GFP_KERNEL); + if (!fi_ffs) { + ret = -ENOMEM; + goto no_func; + } + + for (i = 0; i < func_num; i++) { + fi_ffs[i] = usb_get_function_instance("ffs"); + if (IS_ERR(fi_ffs[i])) { + ret = PTR_ERR(fi_ffs[i]); + --i; + goto no_dev; + } + opts = to_f_fs_opts(fi_ffs[i]); + if (gfs_single_func) + ret = ffs_single_dev(opts->dev); + else + ret = ffs_name_dev(opts->dev, func_names[i]); + if (ret) + goto no_dev; + opts->dev->ffs_ready_callback = functionfs_ready_callback; + opts->dev->ffs_closed_callback = functionfs_closed_callback; + opts->dev->ffs_acquire_dev_callback = functionfs_acquire_dev; + opts->dev->ffs_release_dev_callback = functionfs_release_dev; + opts->no_configfs = true; + } + + missing_funcs = func_num; + + return 0; +no_dev: + while (i >= 0) + usb_put_function_instance(fi_ffs[i--]); + kfree(fi_ffs); +no_func: + kfree(f_ffs[0]); + return ret; } module_init(gfs_init); -static void gfs_exit(void) +static void __exit gfs_exit(void) { + int i; + ENTER(); - if (test_and_clear_bit(0, &gfs_registered)) + if (gfs_registered) usb_composite_unregister(&gfs_driver); + gfs_registered = false; + + kfree(f_ffs[0]); - functionfs_cleanup(); + for (i = 0; i < func_num; i++) + usb_put_function_instance(fi_ffs[i]); + + kfree(fi_ffs); } module_exit(gfs_exit); +static void *functionfs_acquire_dev(struct ffs_dev *dev) +{ + if (!try_module_get(THIS_MODULE)) + return ERR_PTR(-ENODEV); + + return 0; +} + +static void functionfs_release_dev(struct ffs_dev *dev) +{ + module_put(THIS_MODULE); +} +/* + * The caller of this function takes ffs_lock + */ static int functionfs_ready_callback(struct ffs_data *ffs) { - int ret; + int ret = 0; - ENTER(); + if (--missing_funcs) + return 0; - if (WARN_ON(test_and_set_bit(0, &gfs_registered))) + if (gfs_registered) return -EBUSY; - gfs_ffs_data = ffs; - ret = usb_composite_register(&gfs_driver); + gfs_registered = true; + + ret = usb_composite_probe(&gfs_driver); if (unlikely(ret < 0)) - clear_bit(0, &gfs_registered); + gfs_registered = false; + return ret; } +/* + * The caller of this function takes ffs_lock + */ static void functionfs_closed_callback(struct ffs_data *ffs) { - ENTER(); + missing_funcs++; - if (test_and_clear_bit(0, &gfs_registered)) + if (gfs_registered) usb_composite_unregister(&gfs_driver); + gfs_registered = false; } - -static int functionfs_check_dev_callback(const char *dev_name) -{ - return 0; -} - - - +/* + * It is assumed that gfs_bind is called from a context where ffs_lock is held + */ static int gfs_bind(struct usb_composite_dev *cdev) { - int ret; +#if defined CONFIG_USB_FUNCTIONFS_ETH || defined CONFIG_USB_FUNCTIONFS_RNDIS + struct net_device *net; +#endif + int ret, i; ENTER(); - if (WARN_ON(!gfs_ffs_data)) + if (missing_funcs) return -ENODEV; +#if defined CONFIG_USB_FUNCTIONFS_ETH + if (can_support_ecm(cdev->gadget)) { + struct f_ecm_opts *ecm_opts; + + fi_ecm = usb_get_function_instance("ecm"); + if (IS_ERR(fi_ecm)) + return PTR_ERR(fi_ecm); + ecm_opts = container_of(fi_ecm, struct f_ecm_opts, func_inst); + net = ecm_opts->net; + } else { + struct f_gether_opts *geth_opts; + + fi_geth = usb_get_function_instance("geth"); + if (IS_ERR(fi_geth)) + return PTR_ERR(fi_geth); + geth_opts = container_of(fi_geth, struct f_gether_opts, + func_inst); + net = geth_opts->net; + } +#endif - ret = gether_setup(cdev->gadget, gfs_hostaddr); - if (unlikely(ret < 0)) - goto error_quick; +#ifdef CONFIG_USB_FUNCTIONFS_RNDIS + { + struct f_rndis_opts *rndis_opts; + + fi_rndis = usb_get_function_instance("rndis"); + if (IS_ERR(fi_rndis)) { + ret = PTR_ERR(fi_rndis); + goto error; + } + rndis_opts = container_of(fi_rndis, struct f_rndis_opts, + func_inst); +#ifndef CONFIG_USB_FUNCTIONFS_ETH + net = rndis_opts->net; +#endif + } +#endif - gfs_dev_desc.idVendor = cpu_to_le16(gfs_vendor_id); - gfs_dev_desc.idProduct = cpu_to_le16(gfs_product_id); +#if defined CONFIG_USB_FUNCTIONFS_ETH || defined CONFIG_USB_FUNCTIONFS_RNDIS + gether_set_qmult(net, qmult); + if (!gether_set_host_addr(net, host_addr)) + pr_info("using host ethernet address: %s", host_addr); + if (!gether_set_dev_addr(net, dev_addr)) + pr_info("using self ethernet address: %s", dev_addr); +#endif - snprintf(gfs_manufacturer, sizeof gfs_manufacturer, "%s %s with %s", - init_utsname()->sysname, init_utsname()->release, - cdev->gadget->name); - ret = usb_string_id(cdev); - if (unlikely(ret < 0)) - goto error; - gfs_strings[GFS_STRING_MANUFACTURER_IDX].id = ret; - gfs_dev_desc.iManufacturer = ret; +#if defined CONFIG_USB_FUNCTIONFS_RNDIS && defined CONFIG_USB_FUNCTIONFS_ETH + gether_set_gadget(net, cdev->gadget); + ret = gether_register_netdev(net); + if (ret) + goto error_rndis; - ret = usb_string_id(cdev); - if (unlikely(ret < 0)) - goto error; - gfs_strings[GFS_STRING_PRODUCT_IDX].id = ret; - gfs_dev_desc.iProduct = ret; + if (can_support_ecm(cdev->gadget)) { + struct f_ecm_opts *ecm_opts; -#ifdef CONFIG_USB_FUNCTIONFS_RNDIS - ret = usb_string_id(cdev); - if (unlikely(ret < 0)) - goto error; - gfs_strings[GFS_STRING_RNDIS_CONFIG_IDX].id = ret; - gfs_rndis_config_driver.iConfiguration = ret; -#endif + ecm_opts = container_of(fi_ecm, struct f_ecm_opts, func_inst); + ecm_opts->bound = true; + } else { + struct f_gether_opts *geth_opts; -#ifdef CONFIG_USB_FUNCTIONFS_ETH - ret = usb_string_id(cdev); - if (unlikely(ret < 0)) - goto error; - gfs_strings[GFS_STRING_ECM_CONFIG_IDX].id = ret; - gfs_ecm_config_driver.iConfiguration = ret; -#endif + geth_opts = container_of(fi_geth, struct f_gether_opts, + func_inst); + geth_opts->bound = true; + } -#ifdef CONFIG_USB_FUNCTIONFS_GENERIC - ret = usb_string_id(cdev); - if (unlikely(ret < 0)) - goto error; - gfs_strings[GFS_STRING_GENERIC_CONFIG_IDX].id = ret; - gfs_generic_config_driver.iConfiguration = ret; + rndis_borrow_net(fi_rndis, net); #endif - ret = functionfs_bind(gfs_ffs_data, cdev); + /* TODO: gstrings_attach? */ + ret = usb_string_ids_tab(cdev, gfs_strings); if (unlikely(ret < 0)) - goto error; + goto error_rndis; + gfs_dev_desc.iProduct = gfs_strings[USB_GADGET_PRODUCT_IDX].id; - ret = gfs_add_rndis_config(cdev); - if (unlikely(ret < 0)) - goto error_unbind; + for (i = 0; i < ARRAY_SIZE(gfs_configurations); ++i) { + struct gfs_configuration *c = gfs_configurations + i; + int sid = USB_GADGET_FIRST_AVAIL_IDX + i; - ret = gfs_add_ecm_config(cdev); - if (unlikely(ret < 0)) - goto error_unbind; + c->c.label = gfs_strings[sid].s; + c->c.iConfiguration = gfs_strings[sid].id; + c->c.bConfigurationValue = 1 + i; + c->c.bmAttributes = USB_CONFIG_ATT_SELFPOWER; - ret = gfs_add_generic_config(cdev); - if (unlikely(ret < 0)) - goto error_unbind; + c->num = i; + ret = usb_add_config(cdev, &c->c, gfs_do_config); + if (unlikely(ret < 0)) + goto error_unbind; + } + usb_composite_overwrite_options(cdev, &coverwrite); return 0; +/* TODO */ error_unbind: - functionfs_unbind(gfs_ffs_data); +error_rndis: +#ifdef CONFIG_USB_FUNCTIONFS_RNDIS + usb_put_function_instance(fi_rndis); error: - gether_cleanup(); -error_quick: - gfs_ffs_data = NULL; +#endif +#if defined CONFIG_USB_FUNCTIONFS_ETH + if (can_support_ecm(cdev->gadget)) + usb_put_function_instance(fi_ecm); + else + usb_put_function_instance(fi_geth); +#endif return ret; } +/* + * It is assumed that gfs_unbind is called from a context where ffs_lock is held + */ static int gfs_unbind(struct usb_composite_dev *cdev) { + int i; + ENTER(); - /* We may have been called in an error recovery frem - * composite_bind() after gfs_unbind() failure so we need to - * check if gfs_ffs_data is not NULL since gfs_bind() handles - * all error recovery itself. I'd rather we werent called - * from composite on orror recovery, but what you're gonna - * do...? */ - - if (gfs_ffs_data) { - gether_cleanup(); - functionfs_unbind(gfs_ffs_data); - gfs_ffs_data = NULL; + +#ifdef CONFIG_USB_FUNCTIONFS_RNDIS + usb_put_function(f_rndis); + usb_put_function_instance(fi_rndis); +#endif + +#if defined CONFIG_USB_FUNCTIONFS_ETH + if (can_support_ecm(cdev->gadget)) { + usb_put_function(f_ecm); + usb_put_function_instance(fi_ecm); + } else { + usb_put_function(f_geth); + usb_put_function_instance(fi_geth); } +#endif + for (i = 0; i < N_CONF * func_num; ++i) + usb_put_function(*(f_ffs[0] + i)); return 0; } - -static int __gfs_do_config(struct usb_configuration *c, - int (*eth)(struct usb_configuration *c, u8 *ethaddr), - u8 *ethaddr) +/* + * It is assumed that gfs_do_config is called from a context where + * ffs_lock is held + */ +static int gfs_do_config(struct usb_configuration *c) { + struct gfs_configuration *gc = + container_of(c, struct gfs_configuration, c); + int i; int ret; - if (WARN_ON(!gfs_ffs_data)) + if (missing_funcs) return -ENODEV; if (gadget_is_otg(c->cdev->gadget)) { @@ -382,56 +491,92 @@ static int __gfs_do_config(struct usb_configuration *c, c->bmAttributes |= USB_CONFIG_ATT_WAKEUP; } - if (eth) { - ret = eth(c, ethaddr); + if (gc->eth) { + ret = gc->eth(c); if (unlikely(ret < 0)) return ret; } - ret = functionfs_add(c->cdev, c, gfs_ffs_data); - if (unlikely(ret < 0)) - return ret; + for (i = 0; i < func_num; i++) { + f_ffs[gc->num][i] = usb_get_function(fi_ffs[i]); + if (IS_ERR(f_ffs[gc->num][i])) { + ret = PTR_ERR(f_ffs[gc->num][i]); + goto error; + } + ret = usb_add_function(c, f_ffs[gc->num][i]); + if (ret < 0) { + usb_put_function(f_ffs[gc->num][i]); + goto error; + } + } - /* After previous do_configs there may be some invalid + /* + * After previous do_configs there may be some invalid * pointers in c->interface array. This happens every time * a user space function with fewer interfaces than a user * space function that was run before the new one is run. The * compasit's set_config() assumes that if there is no more * then MAX_CONFIG_INTERFACES interfaces in a configuration * then there is a NULL pointer after the last interface in - * c->interface array. We need to make sure this is true. */ + * c->interface array. We need to make sure this is true. + */ if (c->next_interface_id < ARRAY_SIZE(c->interface)) c->interface[c->next_interface_id] = NULL; return 0; +error: + while (--i >= 0) { + if (!IS_ERR(f_ffs[gc->num][i])) + usb_remove_function(c, f_ffs[gc->num][i]); + usb_put_function(f_ffs[gc->num][i]); + } + return ret; } -#ifdef CONFIG_USB_FUNCTIONFS_RNDIS -static int gfs_do_rndis_config(struct usb_configuration *c) +#ifdef CONFIG_USB_FUNCTIONFS_ETH + +static int eth_bind_config(struct usb_configuration *c) { - ENTER(); + int status = 0; - return __gfs_do_config(c, rndis_bind_config, gfs_hostaddr); -} -#endif + if (can_support_ecm(c->cdev->gadget)) { + f_ecm = usb_get_function(fi_ecm); + if (IS_ERR(f_ecm)) + return PTR_ERR(f_ecm); -#ifdef CONFIG_USB_FUNCTIONFS_ETH -static int gfs_do_ecm_config(struct usb_configuration *c) -{ - ENTER(); + status = usb_add_function(c, f_ecm); + if (status < 0) + usb_put_function(f_ecm); + + } else { + f_geth = usb_get_function(fi_geth); + if (IS_ERR(f_geth)) + return PTR_ERR(f_geth); - return __gfs_do_config(c, - can_support_ecm(c->cdev->gadget) - ? ecm_bind_config : geth_bind_config, - gfs_hostaddr); + status = usb_add_function(c, f_geth); + if (status < 0) + usb_put_function(f_geth); + } + return status; } + #endif -#ifdef CONFIG_USB_FUNCTIONFS_GENERIC -static int gfs_do_generic_config(struct usb_configuration *c) +#ifdef CONFIG_USB_FUNCTIONFS_RNDIS + +static int bind_rndis_config(struct usb_configuration *c) { - ENTER(); + int status = 0; + + f_rndis = usb_get_function(fi_rndis); + if (IS_ERR(f_rndis)) + return PTR_ERR(f_rndis); - return __gfs_do_config(c, NULL, NULL); + status = usb_add_function(c, f_rndis); + if (status < 0) + usb_put_function(f_rndis); + + return status; } + #endif |
