Loading drivers/usb/gadget/function/f_ecm.c +32 −35 Original line number Diff line number Diff line Loading @@ -708,36 +708,18 @@ ecm_bind(struct usb_configuration *c, struct usb_function *f) */ if (!ecm_opts->bound) { mutex_lock(&ecm_opts->lock); ecm_opts->net = gether_setup_name_default("ecm"); if (IS_ERR(ecm_opts->net)) { status = PTR_ERR(ecm_opts->net); mutex_unlock(&ecm_opts->lock); goto error; } gether_set_gadget(ecm_opts->net, cdev->gadget); status = gether_register_netdev(ecm_opts->net); mutex_unlock(&ecm_opts->lock); if (status) { free_netdev(ecm_opts->net); goto error; } if (status) return status; ecm_opts->bound = true; } /* export host's Ethernet address in CDC format */ status = gether_get_host_addr_cdc(ecm_opts->net, ecm->ethaddr, sizeof(ecm->ethaddr)); if (status < 12) { status = -EINVAL; goto netdev_cleanup; } ecm->port.ioport = netdev_priv(ecm_opts->net); us = usb_gstrings_attach(cdev, ecm_strings, ARRAY_SIZE(ecm_string_defs)); if (IS_ERR(us)) { status = PTR_ERR(us); goto netdev_cleanup; } if (IS_ERR(us)) return PTR_ERR(us); ecm_control_intf.iInterface = us[0].id; ecm_data_intf.iInterface = us[2].id; ecm_desc.iMACAddress = us[1].id; Loading @@ -746,7 +728,7 @@ ecm_bind(struct usb_configuration *c, struct usb_function *f) /* allocate instance-specific interface IDs */ status = usb_interface_id(c, f); if (status < 0) goto netdev_cleanup; goto fail; ecm->ctrl_id = status; ecm_iad_descriptor.bFirstInterface = status; Loading @@ -755,7 +737,7 @@ ecm_bind(struct usb_configuration *c, struct usb_function *f) status = usb_interface_id(c, f); if (status < 0) goto netdev_cleanup; goto fail; ecm->data_id = status; ecm_data_nop_intf.bInterfaceNumber = status; Loading @@ -767,12 +749,12 @@ ecm_bind(struct usb_configuration *c, struct usb_function *f) /* allocate instance-specific endpoints */ ep = usb_ep_autoconfig(cdev->gadget, &fs_ecm_in_desc); if (!ep) goto netdev_cleanup; goto fail; ecm->port.in_ep = ep; ep = usb_ep_autoconfig(cdev->gadget, &fs_ecm_out_desc); if (!ep) goto netdev_cleanup; goto fail; ecm->port.out_ep = ep; /* NOTE: a status/notification endpoint is *OPTIONAL* but we Loading @@ -781,7 +763,7 @@ ecm_bind(struct usb_configuration *c, struct usb_function *f) */ ep = usb_ep_autoconfig(cdev->gadget, &fs_ecm_notify_desc); if (!ep) goto netdev_cleanup; goto fail; ecm->notify = ep; status = -ENOMEM; Loading @@ -789,7 +771,7 @@ ecm_bind(struct usb_configuration *c, struct usb_function *f) /* allocate notification request and buffer */ ecm->notify_req = usb_ep_alloc_request(ep, GFP_KERNEL); if (!ecm->notify_req) goto netdev_cleanup; goto fail; ecm->notify_req->buf = kmalloc(ECM_STATUS_BYTECOUNT, GFP_KERNEL); if (!ecm->notify_req->buf) goto fail; Loading Loading @@ -836,9 +818,6 @@ ecm_bind(struct usb_configuration *c, struct usb_function *f) usb_ep_free_request(ecm->notify, ecm->notify_req); } netdev_cleanup: gether_cleanup(netdev_priv(ecm_opts->net)); error: ERROR(cdev, "%s: can't bind, err %d\n", f->name, status); return status; Loading Loading @@ -884,6 +863,10 @@ static void ecm_free_inst(struct usb_function_instance *f) struct f_ecm_opts *opts; opts = container_of(f, struct f_ecm_opts, func_inst); if (opts->bound) gether_cleanup(netdev_priv(opts->net)); else free_netdev(opts->net); kfree(opts); } Loading @@ -896,6 +879,13 @@ static struct usb_function_instance *ecm_alloc_inst(void) return ERR_PTR(-ENOMEM); mutex_init(&opts->lock); opts->func_inst.free_func_inst = ecm_free_inst; opts->net = gether_setup_name_default("ecm"); if (IS_ERR(opts->net)) { struct net_device *net = opts->net; kfree(opts); return ERR_CAST(net); } config_group_init_type_name(&opts->func_inst.group, "", &ecm_func_type); Loading @@ -918,8 +908,6 @@ static void ecm_free(struct usb_function *f) static void ecm_unbind(struct usb_configuration *c, struct usb_function *f) { struct f_ecm *ecm = func_to_ecm(f); struct f_ecm_opts *opts = container_of(f->fi, struct f_ecm_opts, func_inst); DBG(c->cdev, "ecm unbind\n"); Loading @@ -932,14 +920,13 @@ static void ecm_unbind(struct usb_configuration *c, struct usb_function *f) kfree(ecm->notify_req->buf); usb_ep_free_request(ecm->notify, ecm->notify_req); opts->bound = false; gether_cleanup(netdev_priv(opts->net)); } static struct usb_function *ecm_alloc(struct usb_function_instance *fi) { struct f_ecm *ecm; struct f_ecm_opts *opts; int status; /* allocate and initialize one new instance */ ecm = kzalloc(sizeof(*ecm), GFP_KERNEL); Loading @@ -949,8 +936,18 @@ static struct usb_function *ecm_alloc(struct usb_function_instance *fi) opts = container_of(fi, struct f_ecm_opts, func_inst); mutex_lock(&opts->lock); opts->refcnt++; /* export host's Ethernet address in CDC format */ status = gether_get_host_addr_cdc(opts->net, ecm->ethaddr, sizeof(ecm->ethaddr)); if (status < 12) { kfree(ecm); mutex_unlock(&opts->lock); return ERR_PTR(-EINVAL); } ecm_string_defs[1].s = ecm->ethaddr; ecm->port.ioport = netdev_priv(opts->net); mutex_unlock(&opts->lock); ecm->port.cdc_filter = DEFAULT_FILTER; Loading drivers/usb/gadget/function/u_ether_configfs.h +0 −35 Original line number Diff line number Diff line Loading @@ -35,11 +35,6 @@ struct f_##_f_##_opts *opts = to_f_##_f_##_opts(item); \ int result; \ \ if (opts->bound == false) { \ pr_err("Gadget function do not bind yet.\n"); \ return -ENODEV; \ } \ \ mutex_lock(&opts->lock); \ result = gether_get_dev_addr(opts->net, page, PAGE_SIZE); \ mutex_unlock(&opts->lock); \ Loading @@ -53,11 +48,6 @@ struct f_##_f_##_opts *opts = to_f_##_f_##_opts(item); \ int ret; \ \ if (opts->bound == false) { \ pr_err("Gadget function do not bind yet.\n"); \ return -ENODEV; \ } \ \ mutex_lock(&opts->lock); \ if (opts->refcnt) { \ mutex_unlock(&opts->lock); \ Loading @@ -80,11 +70,6 @@ struct f_##_f_##_opts *opts = to_f_##_f_##_opts(item); \ int result; \ \ if (opts->bound == false) { \ pr_err("Gadget function do not bind yet.\n"); \ return -ENODEV; \ } \ \ mutex_lock(&opts->lock); \ result = gether_get_host_addr(opts->net, page, PAGE_SIZE); \ mutex_unlock(&opts->lock); \ Loading @@ -98,11 +83,6 @@ struct f_##_f_##_opts *opts = to_f_##_f_##_opts(item); \ int ret; \ \ if (opts->bound == false) { \ pr_err("Gadget function do not bind yet.\n"); \ return -ENODEV; \ } \ \ mutex_lock(&opts->lock); \ if (opts->refcnt) { \ mutex_unlock(&opts->lock); \ Loading @@ -125,11 +105,6 @@ struct f_##_f_##_opts *opts = to_f_##_f_##_opts(item); \ unsigned qmult; \ \ if (opts->bound == false) { \ pr_err("Gadget function do not bind yet.\n"); \ return -ENODEV; \ } \ \ mutex_lock(&opts->lock); \ qmult = gether_get_qmult(opts->net); \ mutex_unlock(&opts->lock); \ Loading @@ -143,11 +118,6 @@ u8 val; \ int ret; \ \ if (opts->bound == false) { \ pr_err("Gadget function do not bind yet.\n"); \ return -ENODEV; \ } \ \ mutex_lock(&opts->lock); \ if (opts->refcnt) { \ ret = -EBUSY; \ Loading @@ -174,11 +144,6 @@ out: \ struct f_##_f_##_opts *opts = to_f_##_f_##_opts(item); \ int ret; \ \ if (opts->bound == false) { \ pr_err("Gadget function do not bind yet.\n"); \ return -ENODEV; \ } \ \ mutex_lock(&opts->lock); \ ret = gether_get_ifname(opts->net, page, PAGE_SIZE); \ mutex_unlock(&opts->lock); \ Loading Loading
drivers/usb/gadget/function/f_ecm.c +32 −35 Original line number Diff line number Diff line Loading @@ -708,36 +708,18 @@ ecm_bind(struct usb_configuration *c, struct usb_function *f) */ if (!ecm_opts->bound) { mutex_lock(&ecm_opts->lock); ecm_opts->net = gether_setup_name_default("ecm"); if (IS_ERR(ecm_opts->net)) { status = PTR_ERR(ecm_opts->net); mutex_unlock(&ecm_opts->lock); goto error; } gether_set_gadget(ecm_opts->net, cdev->gadget); status = gether_register_netdev(ecm_opts->net); mutex_unlock(&ecm_opts->lock); if (status) { free_netdev(ecm_opts->net); goto error; } if (status) return status; ecm_opts->bound = true; } /* export host's Ethernet address in CDC format */ status = gether_get_host_addr_cdc(ecm_opts->net, ecm->ethaddr, sizeof(ecm->ethaddr)); if (status < 12) { status = -EINVAL; goto netdev_cleanup; } ecm->port.ioport = netdev_priv(ecm_opts->net); us = usb_gstrings_attach(cdev, ecm_strings, ARRAY_SIZE(ecm_string_defs)); if (IS_ERR(us)) { status = PTR_ERR(us); goto netdev_cleanup; } if (IS_ERR(us)) return PTR_ERR(us); ecm_control_intf.iInterface = us[0].id; ecm_data_intf.iInterface = us[2].id; ecm_desc.iMACAddress = us[1].id; Loading @@ -746,7 +728,7 @@ ecm_bind(struct usb_configuration *c, struct usb_function *f) /* allocate instance-specific interface IDs */ status = usb_interface_id(c, f); if (status < 0) goto netdev_cleanup; goto fail; ecm->ctrl_id = status; ecm_iad_descriptor.bFirstInterface = status; Loading @@ -755,7 +737,7 @@ ecm_bind(struct usb_configuration *c, struct usb_function *f) status = usb_interface_id(c, f); if (status < 0) goto netdev_cleanup; goto fail; ecm->data_id = status; ecm_data_nop_intf.bInterfaceNumber = status; Loading @@ -767,12 +749,12 @@ ecm_bind(struct usb_configuration *c, struct usb_function *f) /* allocate instance-specific endpoints */ ep = usb_ep_autoconfig(cdev->gadget, &fs_ecm_in_desc); if (!ep) goto netdev_cleanup; goto fail; ecm->port.in_ep = ep; ep = usb_ep_autoconfig(cdev->gadget, &fs_ecm_out_desc); if (!ep) goto netdev_cleanup; goto fail; ecm->port.out_ep = ep; /* NOTE: a status/notification endpoint is *OPTIONAL* but we Loading @@ -781,7 +763,7 @@ ecm_bind(struct usb_configuration *c, struct usb_function *f) */ ep = usb_ep_autoconfig(cdev->gadget, &fs_ecm_notify_desc); if (!ep) goto netdev_cleanup; goto fail; ecm->notify = ep; status = -ENOMEM; Loading @@ -789,7 +771,7 @@ ecm_bind(struct usb_configuration *c, struct usb_function *f) /* allocate notification request and buffer */ ecm->notify_req = usb_ep_alloc_request(ep, GFP_KERNEL); if (!ecm->notify_req) goto netdev_cleanup; goto fail; ecm->notify_req->buf = kmalloc(ECM_STATUS_BYTECOUNT, GFP_KERNEL); if (!ecm->notify_req->buf) goto fail; Loading Loading @@ -836,9 +818,6 @@ ecm_bind(struct usb_configuration *c, struct usb_function *f) usb_ep_free_request(ecm->notify, ecm->notify_req); } netdev_cleanup: gether_cleanup(netdev_priv(ecm_opts->net)); error: ERROR(cdev, "%s: can't bind, err %d\n", f->name, status); return status; Loading Loading @@ -884,6 +863,10 @@ static void ecm_free_inst(struct usb_function_instance *f) struct f_ecm_opts *opts; opts = container_of(f, struct f_ecm_opts, func_inst); if (opts->bound) gether_cleanup(netdev_priv(opts->net)); else free_netdev(opts->net); kfree(opts); } Loading @@ -896,6 +879,13 @@ static struct usb_function_instance *ecm_alloc_inst(void) return ERR_PTR(-ENOMEM); mutex_init(&opts->lock); opts->func_inst.free_func_inst = ecm_free_inst; opts->net = gether_setup_name_default("ecm"); if (IS_ERR(opts->net)) { struct net_device *net = opts->net; kfree(opts); return ERR_CAST(net); } config_group_init_type_name(&opts->func_inst.group, "", &ecm_func_type); Loading @@ -918,8 +908,6 @@ static void ecm_free(struct usb_function *f) static void ecm_unbind(struct usb_configuration *c, struct usb_function *f) { struct f_ecm *ecm = func_to_ecm(f); struct f_ecm_opts *opts = container_of(f->fi, struct f_ecm_opts, func_inst); DBG(c->cdev, "ecm unbind\n"); Loading @@ -932,14 +920,13 @@ static void ecm_unbind(struct usb_configuration *c, struct usb_function *f) kfree(ecm->notify_req->buf); usb_ep_free_request(ecm->notify, ecm->notify_req); opts->bound = false; gether_cleanup(netdev_priv(opts->net)); } static struct usb_function *ecm_alloc(struct usb_function_instance *fi) { struct f_ecm *ecm; struct f_ecm_opts *opts; int status; /* allocate and initialize one new instance */ ecm = kzalloc(sizeof(*ecm), GFP_KERNEL); Loading @@ -949,8 +936,18 @@ static struct usb_function *ecm_alloc(struct usb_function_instance *fi) opts = container_of(fi, struct f_ecm_opts, func_inst); mutex_lock(&opts->lock); opts->refcnt++; /* export host's Ethernet address in CDC format */ status = gether_get_host_addr_cdc(opts->net, ecm->ethaddr, sizeof(ecm->ethaddr)); if (status < 12) { kfree(ecm); mutex_unlock(&opts->lock); return ERR_PTR(-EINVAL); } ecm_string_defs[1].s = ecm->ethaddr; ecm->port.ioport = netdev_priv(opts->net); mutex_unlock(&opts->lock); ecm->port.cdc_filter = DEFAULT_FILTER; Loading
drivers/usb/gadget/function/u_ether_configfs.h +0 −35 Original line number Diff line number Diff line Loading @@ -35,11 +35,6 @@ struct f_##_f_##_opts *opts = to_f_##_f_##_opts(item); \ int result; \ \ if (opts->bound == false) { \ pr_err("Gadget function do not bind yet.\n"); \ return -ENODEV; \ } \ \ mutex_lock(&opts->lock); \ result = gether_get_dev_addr(opts->net, page, PAGE_SIZE); \ mutex_unlock(&opts->lock); \ Loading @@ -53,11 +48,6 @@ struct f_##_f_##_opts *opts = to_f_##_f_##_opts(item); \ int ret; \ \ if (opts->bound == false) { \ pr_err("Gadget function do not bind yet.\n"); \ return -ENODEV; \ } \ \ mutex_lock(&opts->lock); \ if (opts->refcnt) { \ mutex_unlock(&opts->lock); \ Loading @@ -80,11 +70,6 @@ struct f_##_f_##_opts *opts = to_f_##_f_##_opts(item); \ int result; \ \ if (opts->bound == false) { \ pr_err("Gadget function do not bind yet.\n"); \ return -ENODEV; \ } \ \ mutex_lock(&opts->lock); \ result = gether_get_host_addr(opts->net, page, PAGE_SIZE); \ mutex_unlock(&opts->lock); \ Loading @@ -98,11 +83,6 @@ struct f_##_f_##_opts *opts = to_f_##_f_##_opts(item); \ int ret; \ \ if (opts->bound == false) { \ pr_err("Gadget function do not bind yet.\n"); \ return -ENODEV; \ } \ \ mutex_lock(&opts->lock); \ if (opts->refcnt) { \ mutex_unlock(&opts->lock); \ Loading @@ -125,11 +105,6 @@ struct f_##_f_##_opts *opts = to_f_##_f_##_opts(item); \ unsigned qmult; \ \ if (opts->bound == false) { \ pr_err("Gadget function do not bind yet.\n"); \ return -ENODEV; \ } \ \ mutex_lock(&opts->lock); \ qmult = gether_get_qmult(opts->net); \ mutex_unlock(&opts->lock); \ Loading @@ -143,11 +118,6 @@ u8 val; \ int ret; \ \ if (opts->bound == false) { \ pr_err("Gadget function do not bind yet.\n"); \ return -ENODEV; \ } \ \ mutex_lock(&opts->lock); \ if (opts->refcnt) { \ ret = -EBUSY; \ Loading @@ -174,11 +144,6 @@ out: \ struct f_##_f_##_opts *opts = to_f_##_f_##_opts(item); \ int ret; \ \ if (opts->bound == false) { \ pr_err("Gadget function do not bind yet.\n"); \ return -ENODEV; \ } \ \ mutex_lock(&opts->lock); \ ret = gether_get_ifname(opts->net, page, PAGE_SIZE); \ mutex_unlock(&opts->lock); \ Loading