Skip to contentSkip to conversation

usb: hub: check return value

PATCH In review Pan Bian 2 participants 2 messages Apr 23, 2017 – Apr 24, 2017 USB

lore
Share & tools
lore

Pan Bian

author
#0 lore raw

PATCH 1/1 usb: hub: check return value

From: Pan Bian <[email protected]>

Function usb_autopm_get_interface() will return a negative errno on failure, and function usb_autopm_put_interface() should not be called if it fails. However, in function usb_remove_device(), the return value of function usb_autopm_get_interface() is not validated before calling usb_autopm_put_interface().

---
 drivers/usb/core/hub.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/usb/core/hub.c +4 -2
index 5286bf6..9627175 100644
@@ -940,16 +940,18 @@ int usb_remove_device(struct usb_device *udev)
 {
 	struct usb_hub *hub;
 	struct usb_interface *intf;
+	int if_err;
 
 	if (!udev->parent)	/* Can't remove a root hub */
 		return -EINVAL;
 	hub = usb_hub_to_struct_hub(udev->parent);
 	intf = to_usb_interface(hub->intfdev);
 
-	usb_autopm_get_interface(intf);
+	if_err = usb_autopm_get_interface(intf);
 	set_bit(udev->portnum, hub->removed_bits);
 	hub_port_logical_disconnect(hub, udev->portnum);
-	usb_autopm_put_interface(intf);
+	if (!if_err)
+		usb_autopm_put_interface(intf);
 	return 0;
 }
 
Signature · 1 line
1.9.1
#1 lore raw
Quoted 20 lines · Pan Bian

From: Pan Bian <[email protected]>

Function usb_autopm_get_interface() will return a negative errno on failure, and function usb_autopm_put_interface() should not be called if it fails. However, in function usb_remove_device(), the return value of function usb_autopm_get_interface() is not validated before calling usb_autopm_put_interface().

---
 drivers/usb/core/hub.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/usb/core/hub.c +0 -0
index 5286bf6..9627175 100644
@@ -940,16 +940,18 @@ int usb_remove_device(struct usb_device *udev)
 {
        struct usb_hub *hub;

drivers/usb/core/hub.c int usb_remove_device(struct usb_device *udev) · line 950

Quoted 10 lines
drivers/usb/core/hub.c +2 -1
        struct usb_interface *intf;
+       int if_err;
 
        if (!udev->parent)      /* Can't remove a root hub */
                return -EINVAL;
        hub = usb_hub_to_struct_hub(udev->parent);
        intf = to_usb_interface(hub->intfdev);
 
-       usb_autopm_get_interface(intf);
+       if_err = usb_autopm_get_interface(intf);

Why shouldn't we return right from here ?

Quoted 12 lines
drivers/usb/core/hub.c +2 -2
        set_bit(udev->portnum, hub->removed_bits);
        hub_port_logical_disconnect(hub, udev->portnum);
-       usb_autopm_put_interface(intf);
+       if (!if_err)
+               usb_autopm_put_interface(intf);
        return 0;
 }
 
--

1.9.1