Skip to contentSkip to conversation

usb: return correct errno code when krealloc 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: return correct errno code when krealloc fails

In function wusb_dev_sec_add(), variable result takes the return value. Its value should be negative on failures. When function krealloc() is called, an earlier check of variable result guarantees that the value of result must not be less than "sizeof(*secd)", and result is not reassigned when krealloc() returns a NULL pointer. As a result, a positive value may be returned, which makes it impossible for the caller of wusb_dev_sec_add() to detect the error. This patch fixes the bug by assigning -ENOMEM to result when krealloc() returns NULL.

---
 drivers/usb/wusbcore/security.c | 1 +
 1 file changed, 1 insertion(+)
drivers/usb/wusbcore/security.c +1 -0
index 8c9421b..170f2c3 100644
@@ -240,6 +240,7 @@ int wusb_dev_sec_add(struct wusbhc *wusbhc,
 	if (new_secd == NULL) {
 		dev_err(dev,
 			"Can't allocate space for security descriptors\n");
+		result = -ENOMEM;
 		goto out;
 	}
 	secd = new_secd;
Signature · 1 line
1.9.1