[PATCH 2/2] tcm_usb_gadget: Fix nexus leak + enabled attribute failure

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: Nicholas Bellinger <nab@xxxxxxxxxxxxxxx>

This patch adds the missing tcm_usbg_drop_nexus() to properly
release tcm_usbg_nexus memory during typical ->fabric_drop_tpg()
callback shutdown.

Also, fix up tcm_usbg_tpg_store_enable() return value to propigate
usbg_attach() failure up to user-space if no HDC is found.

Reported-by: Andrzej Pietrasiewicz <andrzej.p@xxxxxxxxxxx>
Cc: Andrzej Pietrasiewicz <andrzej.p@xxxxxxxxxxx>
Cc: Sebastian Andrzej Siewior <bigeasy@xxxxxxxxxxxxx>
Signed-off-by: Nicholas Bellinger <nab@xxxxxxxxxxxxxxx>
---
 drivers/usb/gadget/legacy/tcm_usb_gadget.c | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)

diff --git a/drivers/usb/gadget/legacy/tcm_usb_gadget.c b/drivers/usb/gadget/legacy/tcm_usb_gadget.c
index b764e91..54f036b 100644
--- a/drivers/usb/gadget/legacy/tcm_usb_gadget.c
+++ b/drivers/usb/gadget/legacy/tcm_usb_gadget.c
@@ -1425,11 +1425,14 @@ static struct se_portal_group *usbg_make_tpg(
 	return &tpg->se_tpg;
 }
 
+static int tcm_usbg_drop_nexus(struct usbg_tpg *);
+
 static void usbg_drop_tpg(struct se_portal_group *se_tpg)
 {
 	struct usbg_tpg *tpg = container_of(se_tpg,
 				struct usbg_tpg, se_tpg);
 
+	tcm_usbg_drop_nexus(tpg);
 	core_tpg_deregister(se_tpg);
 	destroy_workqueue(tpg->workqueue);
 	kfree(tpg);
@@ -1507,10 +1510,14 @@ static ssize_t tcm_usbg_tpg_store_enable(
 	if (op > 1)
 		return -EINVAL;
 
-	if (op && tpg->gadget_connect)
+	if (op && tpg->gadget_connect) {
+		ret = -EINVAL;
 		goto out;
-	if (!op && !tpg->gadget_connect)
+	}
+	if (!op && !tpg->gadget_connect) {
+		ret = -EINVAL;
 		goto out;
+	}
 
 	if (op) {
 		ret = usbg_attach(tpg);
@@ -1520,8 +1527,10 @@ static ssize_t tcm_usbg_tpg_store_enable(
 		usbg_detach(tpg);
 	}
 	tpg->gadget_connect = op;
-out:
+
 	return count;
+out:
+	return ret;
 }
 TF_TPG_BASE_ATTR(tcm_usbg, enable, S_IRUGO | S_IWUSR);
 
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [Linux Media]     [Linux Input]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Old Linux USB Devel Archive]

  Powered by Linux