Re: [RFC 2/6] xhci: Remove BUG_ON in xhci_get_input_control_ctx.

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

 



On Fri, May 24, 2013 at 05:42:56PM -0700, Sarah Sharp wrote:
> Fail gracefully, instead of causing the kernel to panic, if the input
> control context doesn't have the right type (XHCI_CTX_TYPE_INPUT).  Push
> finding the pointer to the input control context up into functions that
> can fail.
> 
> This patch should be backported to kernels as old as 2.6.31, that
> contain the commit d115b04818e57bdbc7ccde4d0660b15e33013dc8 "USB: xhci:
> Support for 64-byte contexts".
> 
> Signed-off-by: Sarah Sharp <sarah.a.sharp@xxxxxxxxxxxxxxx>
> Cc: John Youn <johnyoun@xxxxxxxxxxxx>
> Cc: stable@xxxxxxxxxxxxxxx
> ---
>  drivers/usb/host/xhci-dbg.c  |    5 ++
>  drivers/usb/host/xhci-mem.c  |    4 +-
>  drivers/usb/host/xhci-ring.c |    4 +
>  drivers/usb/host/xhci.c      |  148 ++++++++++++++++++++++++++++++++----------
>  4 files changed, 126 insertions(+), 35 deletions(-)
> 
> diff --git a/drivers/usb/host/xhci-dbg.c b/drivers/usb/host/xhci-dbg.c
> index 5f3a7c7..8e0be37 100644
> --- a/drivers/usb/host/xhci-dbg.c
> +++ b/drivers/usb/host/xhci-dbg.c
> @@ -550,6 +550,11 @@ void xhci_dbg_ctx(struct xhci_hcd *xhci,
>  	if (ctx->type == XHCI_CTX_TYPE_INPUT) {
>  		struct xhci_input_control_ctx *ctrl_ctx =
>  			xhci_get_input_control_ctx(xhci, ctx);
> +		if (!ctrl_ctx) {
> +			xhci_warn(xhci, "Could not get input context, bad type.\n");
> +			return;
> +		}
> +
>  		xhci_dbg(xhci, "@%p (virt) @%08llx (dma) %#08x - drop flags\n",
>  			 &ctrl_ctx->drop_flags, (unsigned long long)dma,
>  			 ctrl_ctx->drop_flags);
> diff --git a/drivers/usb/host/xhci-mem.c b/drivers/usb/host/xhci-mem.c
> index 1a2052d..e68aafe 100644
> --- a/drivers/usb/host/xhci-mem.c
> +++ b/drivers/usb/host/xhci-mem.c
> @@ -389,7 +389,9 @@ static void xhci_free_container_ctx(struct xhci_hcd *xhci,
>  struct xhci_input_control_ctx *xhci_get_input_control_ctx(struct xhci_hcd *xhci,
>  					      struct xhci_container_ctx *ctx)
>  {
> -	BUG_ON(ctx->type != XHCI_CTX_TYPE_INPUT);
> +	if (ctx->type != XHCI_CTX_TYPE_INPUT)
> +		return NULL;

How can a non-input pointer be passed here?

> +
>  	return (struct xhci_input_control_ctx *)ctx->bytes;

What?  Why isn't "bytes" this structure already?  How about an anonymous
union if you want to, but void * aren't nice to have.

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