Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1629002 > unrolled thread

[PATCH 1/1] usb: hub: check return value

Started byPan Bian <bianpan201602@163.com>
First post2017-04-23 13:30 +0200
Last post2017-04-24 06:00 +0200
Articles 2 — 2 participants

Back to article view | Back to linux.kernel


Contents

  [PATCH 1/1] usb: hub: check return value Pan Bian <bianpan201602@163.com> - 2017-04-23 13:30 +0200
    Re: [PATCH 1/1] usb: hub: check return value Viresh Kumar <viresh.kumar@linaro.org> - 2017-04-24 06:00 +0200

#1629002 — [PATCH 1/1] usb: hub: check return value

FromPan Bian <bianpan201602@163.com>
Date2017-04-23 13:30 +0200
Subject[PATCH 1/1] usb: hub: check return value
Message-ID<tznSh-7OO-1@gated-at.bofh.it>
From: Pan Bian <bianpan2016@163.com>

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().

Signed-off-by: Pan Bian <bianpan2016@163.com>
---
 drivers/usb/core/hub.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c
index 5286bf6..9627175 100644
--- a/drivers/usb/core/hub.c
+++ b/drivers/usb/core/hub.c
@@ -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;
 }
 
-- 
1.9.1

[toc] | [next] | [standalone]


#1629151

FromViresh Kumar <viresh.kumar@linaro.org>
Date2017-04-24 06:00 +0200
Message-ID<tzDkl-1vZ-1@gated-at.bofh.it>
In reply to#1629002
On Sun, Apr 23, 2017 at 4:52 PM, Pan Bian <bianpan201602@163.com> wrote:
> From: Pan Bian <bianpan2016@163.com>
>
> 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().
>
> Signed-off-by: Pan Bian <bianpan2016@163.com>
> ---
>  drivers/usb/core/hub.c | 6 ++++--
>  1 file changed, 4 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c
> index 5286bf6..9627175 100644
> --- a/drivers/usb/core/hub.c
> +++ b/drivers/usb/core/hub.c
> @@ -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);

Why shouldn't we return right from here ?

>         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
>
>

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web