Skip to contentSkip to conversation

usb: gadget: legacy: fix error return code of msg_bind()

PATCH New Jia-Ju Bai 1 participant 1 message Mar 23, 2021 USB

lore
Share & tools
lore

Jia-Ju Bai

author
#0 lore raw

PATCH v2 1/1 usb: gadget: legacy: fix error return code of msg_bind()

When usb_otg_descriptor_alloc() returns NULL to usb_desc, no error return code of msg_bind() is assigned.
To fix this bug, status is assigned with -ENOMEM in this case.

---
v2:
* Fix a mistake in the report.
Thank Greg for good advice.

---
 drivers/usb/gadget/legacy/mass_storage.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/usb/gadget/legacy/mass_storage.c +3 -1
index 9ed22c5fb7fe..ac1741126619 100644
@@ -175,8 +175,10 @@ static int msg_bind(struct usb_composite_dev *cdev)
 		struct usb_descriptor_header *usb_desc;
 
 		usb_desc = usb_otg_descriptor_alloc(cdev->gadget);
-		if (!usb_desc)
+		if (!usb_desc) {
+			status = -ENOMEM;
 			goto fail_string_ids;
+		}
 		usb_otg_descriptor_init(cdev->gadget, usb_desc);
 		otg_desc[0] = usb_desc;
 		otg_desc[1] = NULL;
Signature · 1 line
2.17.1