Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 19d3a743 authored by Ajay Agarwal's avatar Ajay Agarwal Committed by Gerrit - the friendly Code Review server
Browse files

Revert "usb: gadget: f_ecm: allocate/free net device upon driver bind/unbind"



This reverts commit d44dbd5aa7f6bbb5008092564223d47c0b1e5fac.

Move back the allocation of netdevice to alloc_inst(), one-time
registration to bind(), deregistration and free to rm_inst(). The
UI update issue will be taken up with proper stakeholders.

Change-Id: Ifbd91b3cbb045851e81d1d7c64479f74120f0b24
Signed-off-by: default avatarAjay Agarwal <ajaya@codeaurora.org>
parent fd9b37f2
Loading
Loading
Loading
Loading
+32 −35
Original line number Diff line number Diff line
@@ -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;
@@ -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;

@@ -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;
@@ -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
@@ -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;
@@ -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;
@@ -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;
@@ -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);
}

@@ -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);

@@ -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");

@@ -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);
@@ -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;