Skip to contentSkip to conversation

usb: fix improper return value when kzalloc fails

PATCH New Pan Bian 1 participant 1 message Nov 29, 2016 USB

lore
Share & tools
lore

Pan Bian

author
#0 lore raw

PATCH 1/1 usb: fix improper return value when kzalloc fails

The comment says function wa_nep_queue() should return 0 if ok, and <0 errno code on error. However, its implementation always returns 0, even if the call to kzalloc() fails. As a result, the return value may be inconsistent with the execution status, which may mislead the callers. This patch fixes the bug, returning -ENOMEM when the call to kzalloc() fails.

---
 drivers/usb/wusbcore/wa-nep.c | 1 +
 1 file changed, 1 insertion(+)
drivers/usb/wusbcore/wa-nep.c +1 -0
index ed46222..e3819fc 100644
@@ -198,6 +198,7 @@ static int wa_nep_queue(struct wahc *wa, size_t size)
 	if (nw == NULL) {
 		if (printk_ratelimit())
 			dev_err(dev, "No memory to queue notification\n");
+		result = -ENOMEM;
 		goto out;
 	}
 	INIT_WORK(&nw->work, wa_notif_dispatch);
Signature · 1 line
1.9.1