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

Commit 1616e99d authored by Sebastian Andrzej Siewior's avatar Sebastian Andrzej Siewior Committed by Felipe Balbi
Browse files

usb: gadget: let f_* use usb_string_ids_tab() where it makes sense



Instead of calling usb_string_id() multiple times I replace it with one
usb_string_ids_tab(). The NULL pointer in struct usb_string with "" and
are not overwritten in fail or unbind case.

The conditional assignment remains because some gadgets recycle the string
ID because the same descriptor (and string ID) is used if we have more
than one config descriptor.

Signed-off-by: default avatarSebastian Andrzej Siewior <bigeasy@linutronix.de>
Signed-off-by: default avatarFelipe Balbi <balbi@ti.com>
parent b36c3479
Loading
Loading
Loading
Loading
+8 −19
Original line number Diff line number Diff line
@@ -705,6 +705,7 @@ acm_unbind(struct usb_configuration *c, struct usb_function *f)
{
	struct f_acm		*acm = func_to_acm(f);

	acm_string_defs[0].id = 0;
	usb_free_all_descriptors(f);
	gs_free_req(acm->notify, acm->notify_req);
	kfree(acm);
@@ -742,27 +743,15 @@ int acm_bind_config(struct usb_configuration *c, u8 port_num)
	 */

	/* maybe allocate device-global string IDs, and patch descriptors */
	if (acm_string_defs[ACM_CTRL_IDX].id == 0) {
		status = usb_string_id(c->cdev);
	if (acm_string_defs[0].id == 0) {
		status = usb_string_ids_tab(c->cdev, acm_string_defs);
		if (status < 0)
			return status;
		acm_string_defs[ACM_CTRL_IDX].id = status;

		acm_control_interface_desc.iInterface = status;

		status = usb_string_id(c->cdev);
		if (status < 0)
			return status;
		acm_string_defs[ACM_DATA_IDX].id = status;

		acm_data_interface_desc.iInterface = status;

		status = usb_string_id(c->cdev);
		if (status < 0)
			return status;
		acm_string_defs[ACM_IAD_IDX].id = status;

		acm_iad_descriptor.iFunction = status;
		acm_control_interface_desc.iInterface =
			acm_string_defs[ACM_CTRL_IDX].id;
		acm_data_interface_desc.iInterface =
			acm_string_defs[ACM_DATA_IDX].id;
		acm_iad_descriptor.iFunction = acm_string_defs[ACM_IAD_IDX].id;
	}

	/* allocate and initialize one new instance */
+9 −33
Original line number Diff line number Diff line
@@ -354,7 +354,7 @@ static struct usb_descriptor_header *ecm_ss_function[] = {

static struct usb_string ecm_string_defs[] = {
	[0].s = "CDC Ethernet Control Model (ECM)",
	[1].s = NULL /* DYNAMIC */,
	[1].s = "",
	[2].s = "CDC Ethernet Data",
	[3].s = "CDC ECM",
	{  } /* end of list */
@@ -803,12 +803,11 @@ ecm_unbind(struct usb_configuration *c, struct usb_function *f)

	DBG(c->cdev, "ecm unbind\n");

	ecm_string_defs[0].id = 0;
	usb_free_all_descriptors(f);

	kfree(ecm->notify_req->buf);
	usb_ep_free_request(ecm->notify, ecm->notify_req);

	ecm_string_defs[1].s = NULL;
	kfree(ecm);
}

@@ -833,36 +832,15 @@ ecm_bind_config(struct usb_configuration *c, u8 ethaddr[ETH_ALEN])
	if (!can_support_ecm(c->cdev->gadget) || !ethaddr)
		return -EINVAL;

	/* maybe allocate device-global string IDs */
	if (ecm_string_defs[0].id == 0) {

		/* control interface label */
		status = usb_string_id(c->cdev);
		if (status < 0)
			return status;
		ecm_string_defs[0].id = status;
		ecm_control_intf.iInterface = status;

		/* data interface label */
		status = usb_string_id(c->cdev);
		if (status < 0)
			return status;
		ecm_string_defs[2].id = status;
		ecm_data_intf.iInterface = status;

		/* MAC address */
		status = usb_string_id(c->cdev);
		if (status < 0)
		status = usb_string_ids_tab(c->cdev, ecm_string_defs);
		if (status)
			return status;
		ecm_string_defs[1].id = status;
		ecm_desc.iMACAddress = status;

		/* IAD label */
		status = usb_string_id(c->cdev);
		if (status < 0)
			return status;
		ecm_string_defs[3].id = status;
		ecm_iad_descriptor.iFunction = status;
		ecm_control_intf.iInterface = ecm_string_defs[0].id;
		ecm_data_intf.iInterface = ecm_string_defs[2].id;
		ecm_desc.iMACAddress = ecm_string_defs[1].id;
		ecm_iad_descriptor.iFunction = ecm_string_defs[3].id;
	}

	/* allocate and initialize one new instance */
@@ -887,9 +865,7 @@ ecm_bind_config(struct usb_configuration *c, u8 ethaddr[ETH_ALEN])
	ecm->port.func.disable = ecm_disable;

	status = usb_add_function(c, &ecm->port.func);
	if (status) {
		ecm_string_defs[1].s = NULL;
	if (status)
		kfree(ecm);
	}
	return status;
}
+10 −30
Original line number Diff line number Diff line
@@ -321,7 +321,7 @@ static struct usb_descriptor_header *ncm_hs_function[] __initdata = {

static struct usb_string ncm_string_defs[] = {
	[STRING_CTRL_IDX].s = "CDC Network Control Model (NCM)",
	[STRING_MAC_IDX].s = NULL /* DYNAMIC */,
	[STRING_MAC_IDX].s = "",
	[STRING_DATA_IDX].s = "CDC Network Data",
	[STRING_IAD_IDX].s = "CDC NCM",
	{  } /* end of list */
@@ -1262,12 +1262,12 @@ ncm_unbind(struct usb_configuration *c, struct usb_function *f)

	DBG(c->cdev, "ncm unbind\n");

	ncm_string_defs[0].id = 0;
	usb_free_all_descriptors(f);

	kfree(ncm->notify_req->buf);
	usb_ep_free_request(ncm->notify, ncm->notify_req);

	ncm_string_defs[1].s = NULL;
	kfree(ncm);
}

@@ -1291,37 +1291,19 @@ int __init ncm_bind_config(struct usb_configuration *c, u8 ethaddr[ETH_ALEN])
	if (!can_support_ecm(c->cdev->gadget) || !ethaddr)
		return -EINVAL;

	/* maybe allocate device-global string IDs */
	if (ncm_string_defs[0].id == 0) {

		/* control interface label */
		status = usb_string_id(c->cdev);
		status = usb_string_ids_tab(c->cdev, ncm_string_defs);
		if (status < 0)
			return status;
		ncm_string_defs[STRING_CTRL_IDX].id = status;
		ncm_control_intf.iInterface = status;
		ncm_control_intf.iInterface =
			ncm_string_defs[STRING_CTRL_IDX].id;

		/* data interface label */
		status = usb_string_id(c->cdev);
		if (status < 0)
			return status;
		ncm_string_defs[STRING_DATA_IDX].id = status;
		status = ncm_string_defs[STRING_DATA_IDX].id;
		ncm_data_nop_intf.iInterface = status;
		ncm_data_intf.iInterface = status;

		/* MAC address */
		status = usb_string_id(c->cdev);
		if (status < 0)
			return status;
		ncm_string_defs[STRING_MAC_IDX].id = status;
		ecm_desc.iMACAddress = status;

		/* IAD */
		status = usb_string_id(c->cdev);
		if (status < 0)
			return status;
		ncm_string_defs[STRING_IAD_IDX].id = status;
		ncm_iad_desc.iFunction = status;
		ecm_desc.iMACAddress = ncm_string_defs[STRING_MAC_IDX].id;
		ncm_iad_desc.iFunction = ncm_string_defs[STRING_IAD_IDX].id;
	}

	/* allocate and initialize one new instance */
@@ -1331,7 +1313,7 @@ int __init ncm_bind_config(struct usb_configuration *c, u8 ethaddr[ETH_ALEN])

	/* export host's Ethernet address in CDC format */
	snprintf(ncm->ethaddr, sizeof ncm->ethaddr, "%pm", ethaddr);
	ncm_string_defs[1].s = ncm->ethaddr;
	ncm_string_defs[STRING_MAC_IDX].s = ncm->ethaddr;

	spin_lock_init(&ncm->lock);
	ncm_reset_values(ncm);
@@ -1351,9 +1333,7 @@ int __init ncm_bind_config(struct usb_configuration *c, u8 ethaddr[ETH_ALEN])
	ncm->port.unwrap = ncm_unwrap_ntb;

	status = usb_add_function(c, &ncm->port.func);
	if (status) {
		ncm_string_defs[1].s = NULL;
	if (status)
		kfree(ncm);
	}
	return status;
}
+7 −12
Original line number Diff line number Diff line
@@ -379,6 +379,7 @@ obex_bind(struct usb_configuration *c, struct usb_function *f)
static void
obex_unbind(struct usb_configuration *c, struct usb_function *f)
{
	obex_string_defs[OBEX_CTRL_IDX].id = 0;
	usb_free_all_descriptors(f);
	kfree(func_to_obex(f));
}
@@ -418,21 +419,15 @@ int __init obex_bind_config(struct usb_configuration *c, u8 port_num)
	if (!can_support_obex(c))
		return -EINVAL;

	/* maybe allocate device-global string IDs, and patch descriptors */
	if (obex_string_defs[OBEX_CTRL_IDX].id == 0) {
		status = usb_string_id(c->cdev);
		status = usb_string_ids_tab(c->cdev, obex_string_defs);
		if (status < 0)
			return status;
		obex_string_defs[OBEX_CTRL_IDX].id = status;
		obex_control_intf.iInterface =
			obex_string_defs[OBEX_CTRL_IDX].id;

		obex_control_intf.iInterface = status;

		status = usb_string_id(c->cdev);
		if (status < 0)
			return status;
		obex_string_defs[OBEX_DATA_IDX].id = status;

		obex_data_nop_intf.iInterface =
		status = obex_string_defs[OBEX_DATA_IDX].id;
		obex_data_nop_intf.iInterface = status;
		obex_data_intf.iInterface = status;
	}

+6 −21
Original line number Diff line number Diff line
@@ -795,8 +795,8 @@ rndis_unbind(struct usb_configuration *c, struct usb_function *f)

	rndis_deregister(rndis->config);
	rndis_exit();
	rndis_string_defs[0].id = 0;

	rndis_string_defs[0].id = 0;
	usb_free_all_descriptors(f);

	kfree(rndis->notify_req->buf);
@@ -822,34 +822,19 @@ rndis_bind_config_vendor(struct usb_configuration *c, u8 ethaddr[ETH_ALEN],
	if (!can_support_rndis(c) || !ethaddr)
		return -EINVAL;

	/* maybe allocate device-global string IDs */
	if (rndis_string_defs[0].id == 0) {

		/* ... and setup RNDIS itself */
		status = rndis_init();
		if (status < 0)
			return status;

		/* control interface label */
		status = usb_string_id(c->cdev);
		if (status < 0)
			return status;
		rndis_string_defs[0].id = status;
		rndis_control_intf.iInterface = status;

		/* data interface label */
		status = usb_string_id(c->cdev);
		if (status < 0)
		status = usb_string_ids_tab(c->cdev, rndis_string_defs);
		if (status)
			return status;
		rndis_string_defs[1].id = status;
		rndis_data_intf.iInterface = status;

		/* IAD iFunction label */
		status = usb_string_id(c->cdev);
		if (status < 0)
			return status;
		rndis_string_defs[2].id = status;
		rndis_iad_descriptor.iFunction = status;
		rndis_control_intf.iInterface = rndis_string_defs[0].id;
		rndis_data_intf.iInterface = rndis_string_defs[1].id;
		rndis_iad_descriptor.iFunction = rndis_string_defs[2].id;
	}

	/* allocate and initialize one new instance */
Loading