Skip to contentSkip to conversation

usb: gadget: f_uac2: fix error handling at afunc_bind

PATCH Superseded Peter Chen 3 participants 3 messages Oct 26, 2016 – Nov 3, 2016

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Peter Chen

author
#0 lore raw

PATCH 1/1 usb: gadget: f_uac2: fix error handling at afunc_bind

The current error handling flow uses incorrect goto label, fix it

Fixes d12a8727171c ("usb: gadget: function: Remove

redundant usb_free_all_descriptors")

---
 drivers/usb/gadget/function/f_uac2.c | 20 +++++++++++---------
 1 file changed, 11 insertions(+), 9 deletions(-)
drivers/usb/gadget/function/f_uac2.c +11 -9
index cd214ec8..3f4e478 100644
@@ -1067,13 +1067,13 @@ afunc_bind(struct usb_configuration *cfg, struct usb_function *fn)
 	agdev->out_ep = usb_ep_autoconfig(gadget, &fs_epout_desc);
 	if (!agdev->out_ep) {
 		dev_err(dev, "%s:%d Error!\n", __func__, __LINE__);
-		goto err;
+		return ret;
 	}
 
 	agdev->in_ep = usb_ep_autoconfig(gadget, &fs_epin_desc);
 	if (!agdev->in_ep) {
 		dev_err(dev, "%s:%d Error!\n", __func__, __LINE__);
-		goto err;
+		return ret;
 	}
 
 	uac2->p_prm.uac2 = uac2;
@@ -1091,13 +1091,14 @@ afunc_bind(struct usb_configuration *cfg, struct usb_function *fn)
 	ret = usb_assign_descriptors(fn, fs_audio_desc, hs_audio_desc, NULL,
 				     NULL);
 	if (ret)
-		goto err;
+		return ret;
 
 	prm = &agdev->uac2.c_prm;
 	prm->max_psize = hs_epout_desc.wMaxPacketSize;
 	prm->rbuf = kzalloc(prm->max_psize * USB_XFERS, GFP_KERNEL);
 	if (!prm->rbuf) {
 		prm->max_psize = 0;
+		ret = -ENOMEM;
 		goto err_free_descs;
 	}
 
@@ -1106,20 +1107,21 @@ afunc_bind(struct usb_configuration *cfg, struct usb_function *fn)
 	prm->rbuf = kzalloc(prm->max_psize * USB_XFERS, GFP_KERNEL);
 	if (!prm->rbuf) {
 		prm->max_psize = 0;
-		goto err_free_descs;
+		ret = -ENOMEM;
+		goto err_no_memory;
 	}
 
 	ret = alsa_uac2_init(agdev);
 	if (ret)
-		goto err_free_descs;
+		goto err_no_memory;
 	return 0;
 
-err_free_descs:
-	usb_free_all_descriptors(fn);
-err:
+err_no_memory:
 	kfree(agdev->uac2.p_prm.rbuf);
 	kfree(agdev->uac2.c_prm.rbuf);
-	return -EINVAL;
+err_free_descs:
+	usb_free_all_descriptors(fn);
+	return ret;
 }
 
 static int
Signature · 1 line
2.7.4
#1 lore raw

Hi,

Quoted 6 lines · Peter Chen

The current error handling flow uses incorrect goto label, fix it

Fixes d12a8727171c ("usb: gadget: function: Remove

redundant usb_free_all_descriptors")

seems like there's more than one fix here.

Quoted 25 lines
---
 drivers/usb/gadget/function/f_uac2.c | 20 +++++++++++---------
 1 file changed, 11 insertions(+), 9 deletions(-)
drivers/usb/gadget/function/f_uac2.c +2 -2
index cd214ec8..3f4e478 100644
@@ -1067,13 +1067,13 @@ afunc_bind(struct usb_configuration *cfg, struct usb_function *fn)
 	agdev->out_ep = usb_ep_autoconfig(gadget, &fs_epout_desc);
 	if (!agdev->out_ep) {
 		dev_err(dev, "%s:%d Error!\n", __func__, __LINE__);
-		goto err;
+		return ret;
 	}
 
 	agdev->in_ep = usb_ep_autoconfig(gadget, &fs_epin_desc);
 	if (!agdev->in_ep) {
 		dev_err(dev, "%s:%d Error!\n", __func__, __LINE__);
-		goto err;
+		return ret;
 	}
 
 	uac2->p_prm.uac2 = uac2;

drivers/usb/gadget/function/f_uac2.c afunc_bind(struct usb_configuration *cfg, struct usb_function *fn) · line 1094

Quoted 5 lines
drivers/usb/gadget/function/f_uac2.c +1 -1
@@ -1091,13 +1091,14 @@ afunc_bind(struct usb_configuration *cfg, struct usb_function *fn)
 	ret = usb_assign_descriptors(fn, fs_audio_desc, hs_audio_desc, NULL,
 				     NULL);
 	if (ret)
-		goto err;
+		return ret;

this is one fix

drivers/usb/gadget/function/f_uac2.c afunc_bind(struct usb_configuration *cfg, struct usb_function *fn) · line 1101

Quoted 7 lines
drivers/usb/gadget/function/f_uac2.c +1 -0
 	prm = &agdev->uac2.c_prm;
 	prm->max_psize = hs_epout_desc.wMaxPacketSize;
 	prm->rbuf = kzalloc(prm->max_psize * USB_XFERS, GFP_KERNEL);
 	if (!prm->rbuf) {
 		prm->max_psize = 0;
+		ret = -ENOMEM;

but initializing ret to -ENOMEM is a separate fix altogether.

Signature · 1 line
balbi
#2 lore raw
Quoted 47 lines · Felipe Balbi

Hi,

Quoted 6 lines · Peter Chen

The current error handling flow uses incorrect goto label, fix it

Fixes d12a8727171c ("usb: gadget: function: Remove

redundant usb_free_all_descriptors")

seems like there's more than one fix here.

Quoted 25 lines
---
 drivers/usb/gadget/function/f_uac2.c | 20 +++++++++++---------
 1 file changed, 11 insertions(+), 9 deletions(-)
drivers/usb/gadget/function/f_uac2.c +2 -2
index cd214ec8..3f4e478 100644
@@ -1067,13 +1067,13 @@ afunc_bind(struct usb_configuration *cfg, struct usb_function *fn)
 	agdev->out_ep = usb_ep_autoconfig(gadget, &fs_epout_desc);
 	if (!agdev->out_ep) {
 		dev_err(dev, "%s:%d Error!\n", __func__, __LINE__);
-		goto err;
+		return ret;
 	}
 
 	agdev->in_ep = usb_ep_autoconfig(gadget, &fs_epin_desc);
 	if (!agdev->in_ep) {
 		dev_err(dev, "%s:%d Error!\n", __func__, __LINE__);
-		goto err;
+		return ret;
 	}
 
 	uac2->p_prm.uac2 = uac2;

drivers/usb/gadget/function/f_uac2.c afunc_bind(struct usb_configuration *cfg, struct usb_function *fn) · line 1094

Quoted 5 lines
drivers/usb/gadget/function/f_uac2.c +1 -1
@@ -1091,13 +1091,14 @@ afunc_bind(struct usb_configuration *cfg, struct usb_function *fn)
 	ret = usb_assign_descriptors(fn, fs_audio_desc, hs_audio_desc, NULL,
 				     NULL);
 	if (ret)
-		goto err;
+		return ret;

this is one fix

Quoted 1 line
Quoted 9 lines

drivers/usb/gadget/function/f_uac2.c afunc_bind(struct usb_configuration *cfg, struct usb_function *fn) · line 1101

Quoted 6 lines
drivers/usb/gadget/function/f_uac2.c +1 -0
 	prm = &agdev->uac2.c_prm;
 	prm->max_psize = hs_epout_desc.wMaxPacketSize;
 	prm->rbuf = kzalloc(prm->max_psize * USB_XFERS, GFP_KERNEL);
 	if (!prm->rbuf) {
 		prm->max_psize = 0;
+		ret = -ENOMEM;

but initializing ret to -ENOMEM is a separate fix altogether.

Ok, I will have a bug-fix just fixing incorrect label, and have another patch to change return value for -next.

Signature · 2 lines
Best Regards,
Peter Chen