Re: [PATCH v2] USB: EHCI: fix dereference of ERR_PTR

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wed, 16 Sep 2015, Sudip Mukherjee wrote:

> On error find_tt() returns either a NULL pointer or the error value in
> ERR_PTR. But we were dereferencing it directly without even checking if
> find_tt() returned a valid pointer or not.
> 
> Signed-off-by: Sudip Mukherjee <sudip@xxxxxxxxxxxxxxx>
> ---
> 
> v2: used IS_ERR_OR_NULL (didn't know it was there. thanks)
> 
> 
>  drivers/usb/host/ehci-sched.c | 4 ++++
>  1 file changed, 4 insertions(+)
> 
> diff --git a/drivers/usb/host/ehci-sched.c b/drivers/usb/host/ehci-sched.c
> index f9a3327..de75343 100644
> --- a/drivers/usb/host/ehci-sched.c
> +++ b/drivers/usb/host/ehci-sched.c
> @@ -257,6 +257,8 @@ static void reserve_release_intr_bandwidth(struct ehci_hcd *ehci,
>  	/* FS/LS bus bandwidth */
>  	if (tt_usecs) {
>  		tt = find_tt(qh->ps.udev);
> +		if (IS_ERR_OR_NULL(tt))
> +			return;
>  		if (sign > 0)
>  			list_add_tail(&qh->ps.ps_list, &tt->ps_list);
>  		else
> @@ -1373,6 +1375,8 @@ static void reserve_release_iso_bandwidth(struct ehci_hcd *ehci,
>  		}
>  
>  		tt = find_tt(stream->ps.udev);
> +		if (IS_ERR_OR_NULL(tt))
> +			return;
>  		if (sign > 0)
>  			list_add_tail(&stream->ps.ps_list, &tt->ps_list);
>  		else

This patch isn't needed.  In both reserve_release_intr_bandwidth() and 
reserve_release_iso_bandwidth() it is known that find_tt() will return 
a valid pointer.

This is because each of those functions is called from only one place.  
For example, reserve_release_intr_bandwidth() is called only at the end
of qh_schedule().  But near the start of qh_schedule() there is earlier
call to tt_find(), and there we do test for error pointers.  If the
first call doesn't return an error then the second call won't either.

The same sort of thing happens in reserve_release_iso_bandwidth().

Alan Stern

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [Linux Media]     [Linux Input]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Old Linux USB Devel Archive]

  Powered by Linux