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

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

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



This reverts commit b26b39948b03892071104c91cddb479e54fd215c.

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: I844ecda80197d7bb83860473723c431d52686b1f
Signed-off-by: default avatarAjay Agarwal <ajaya@codeaurora.org>
parent 2303700e
Loading
Loading
Loading
Loading
+15 −23
Original line number Diff line number Diff line
@@ -788,31 +788,18 @@ rndis_bind(struct usb_configuration *c, struct usb_function *f)
	 * with regard to rndis_opts->bound access
	 */
	if (!rndis_opts->bound) {
		mutex_lock(&rndis_opts->lock);
		rndis_opts->net = gether_setup_name_default("rndis");
		if (IS_ERR(rndis_opts->net)) {
			status = PTR_ERR(rndis_opts->net);
			mutex_unlock(&rndis_opts->lock);
			goto error;
		}
		gether_set_gadget(rndis_opts->net, cdev->gadget);
		status = gether_register_netdev(rndis_opts->net);
		mutex_unlock(&rndis_opts->lock);
		if (status) {
			free_netdev(rndis_opts->net);
			goto error;
		}
		if (status)
			goto fail;
		rndis_opts->bound = true;
	}

	gether_get_host_addr_u8(rndis_opts->net, rndis->ethaddr);
	rndis->port.ioport = netdev_priv(rndis_opts->net);

	us = usb_gstrings_attach(cdev, rndis_strings,
				 ARRAY_SIZE(rndis_string_defs));
	if (IS_ERR(us)) {
		status = PTR_ERR(us);
		goto netdev_cleanup;
		goto fail;
	}
	rndis_control_intf.iInterface = us[0].id;
	rndis_data_intf.iInterface = us[1].id;
@@ -950,9 +937,7 @@ rndis_bind(struct usb_configuration *c, struct usb_function *f)
		kfree(rndis->notify_req->buf);
		usb_ep_free_request(rndis->notify, rndis->notify_req);
	}
netdev_cleanup:
	gether_cleanup(rndis->port.ioport);
error:

	ERROR(cdev, "%s: can't bind, err %d\n", f->name, status);

	return status;
@@ -1019,6 +1004,8 @@ static void rndis_free_inst(struct usb_function_instance *f)
	if (!opts->borrowed_net) {
		if (opts->bound)
			gether_cleanup(netdev_priv(opts->net));
		else
			free_netdev(opts->net);
	}

	kfree(opts->rndis_interf_group);	/* single VLA chunk */
@@ -1040,6 +1027,13 @@ static struct usb_function_instance *rndis_alloc_inst(void)
	mutex_init(&opts->lock);
	spin_lock_init(&_rndis_lock);
	opts->func_inst.free_func_inst = rndis_free_inst;
	opts->net = gether_setup_name_default("rndis");
	if (IS_ERR(opts->net)) {
		struct net_device *net = opts->net;

		kfree(opts);
		return ERR_CAST(net);
	}
	INIT_LIST_HEAD(&opts->rndis_os_desc.ext_prop);

	descs[0] = &opts->rndis_os_desc;
@@ -1082,8 +1076,6 @@ static void rndis_free(struct usb_function *f)
static void rndis_unbind(struct usb_configuration *c, struct usb_function *f)
{
	struct f_rndis		*rndis = func_to_rndis(f);
	struct f_rndis_opts	*opts = container_of(f->fi, struct f_rndis_opts,
								func_inst);

	kfree(f->os_desc_table);
	f->os_desc_n = 0;
@@ -1091,8 +1083,6 @@ static void rndis_unbind(struct usb_configuration *c, struct usb_function *f)

	kfree(rndis->notify_req->buf);
	usb_ep_free_request(rndis->notify, rndis->notify_req);
	gether_cleanup(rndis->port.ioport);
	opts->bound = false;
}

static struct usb_function *rndis_alloc(struct usb_function_instance *fi)
@@ -1112,9 +1102,11 @@ static struct usb_function *rndis_alloc(struct usb_function_instance *fi)
	mutex_lock(&opts->lock);
	opts->refcnt++;

	gether_get_host_addr_u8(opts->net, rndis->ethaddr);
	rndis->vendorID = opts->vendor_id;
	rndis->manufacturer = opts->manufacturer;

	rndis->port.ioport = netdev_priv(opts->net);
	mutex_unlock(&opts->lock);
	/* RNDIS activates when the host changes this filter */
	rndis->port.cdc_filter = 0;