Re: [PATCH] USB: complain if userspace resets an active endpoint

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

 



On Wed, Feb 19, 2014 at 03:32:12PM -0500, Alan Stern wrote:
> It is an error for a driver to call usb_clear_halt() or
> usb_reset_endpoint() while there are URBs queued for the endpoint,
> because the end result is not well defined.  At the time the endpoint
> gets reset, it may or may not be actively running.
> 
> As far as I know, no kernel drivers do this.  But some userspace
> drivers do, and it seems like a good idea to bring this error to their
> attention.
> 
> This patch adds a warning to the kernel log whenever a program invokes
> the USBDEVFS_CLEAR_HALT or USBDEVFS_RESETEP ioctls at an inappropriate
> time, and includes the name of the program.  This will make it clear
> that any subsequent errors are not due to the misbehavior of a kernel
> driver.
> 
> Signed-off-by: Alan Stern <stern@xxxxxxxxxxxxxxxxxxx>
> Suggested-by: Bjørn Mork <bjorn@xxxxxxx>
> CC: Stanislaw Gruszka <sgruszka@xxxxxxxxxx>
> 
> ---
> 
> 
> [as1741]
> 
> 
>  drivers/usb/core/devio.c |   16 ++++++++++++++++
>  1 file changed, 16 insertions(+)
> 
> Index: usb-3.14/drivers/usb/core/devio.c
> ===================================================================
> --- usb-3.14.orig/drivers/usb/core/devio.c
> +++ usb-3.14/drivers/usb/core/devio.c
> @@ -1043,6 +1043,20 @@ static int proc_bulk(struct dev_state *p
>  	return ret;
>  }
>  
> +static void check_reset_of_active_ep(struct usb_device *udev,
> +		unsigned int epnum, char *ioctl_name)
> +{
> +	struct usb_host_endpoint **eps;
> +	struct usb_host_endpoint *ep;
> +
> +	eps = (epnum & USB_DIR_IN) ? udev->ep_in : udev->ep_out;
> +	ep = eps[epnum & 0x0f];
> +	if (ep && !list_empty(&ep->urb_list))
> +		pr_warn("Process %d (%s) called USBDEVFS_%s for active endpoint %s ep %02x\n",
> +				task_pid_nr(current), current->comm,
> +				ioctl_name, dev_name(&udev->dev), epnum);
> +}

If you use dev_warn() here, then userspace has a chance to be able to
map that device name/id to the actual device that was being used at the
time, instead of having to dig through the message itself (tools like
journald already handle dev_* messages like this.)

Care to switch this around?

thanks,

greg k-h
--
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