]> Pileus Git - ~andy/linux/commitdiff
xhci: Remove BUG_ON() in xhci_alloc_container_ctx.
authorSarah Sharp <sarah.a.sharp@linux.intel.com>
Tue, 23 Apr 2013 22:49:47 +0000 (15:49 -0700)
committerSarah Sharp <sarah.a.sharp@linux.intel.com>
Fri, 14 Jun 2013 20:43:43 +0000 (13:43 -0700)
It's horrible coding style to panic the kernel when someone passes you
an argument value you didn't expect.  In the future, we may want to add
additional context types, so it's better to gracefully handle additional
context types instead of panicking.

Signed-off-by: Sarah Sharp <sarah.a.sharp@linux.intel.com>
Cc: John Youn <johnyoun@synopsys.com>
drivers/usb/host/xhci-mem.c

index 8c0e119efa4e9384a7e58736674b402f46a16b5f..cc1b3efd5d76935a479cc448cab7ae37adbea255 100644 (file)
@@ -358,11 +358,15 @@ int xhci_ring_expansion(struct xhci_hcd *xhci, struct xhci_ring *ring,
 static struct xhci_container_ctx *xhci_alloc_container_ctx(struct xhci_hcd *xhci,
                                                    int type, gfp_t flags)
 {
-       struct xhci_container_ctx *ctx = kzalloc(sizeof(*ctx), flags);
+       struct xhci_container_ctx *ctx;
+
+       if ((type != XHCI_CTX_TYPE_DEVICE) && (type != XHCI_CTX_TYPE_INPUT))
+               return NULL;
+
+       ctx = kzalloc(sizeof(*ctx), flags);
        if (!ctx)
                return NULL;
 
-       BUG_ON((type != XHCI_CTX_TYPE_DEVICE) && (type != XHCI_CTX_TYPE_INPUT));
        ctx->type = type;
        ctx->size = HCC_64BYTE_CONTEXT(xhci->hcc_params) ? 2048 : 1024;
        if (type == XHCI_CTX_TYPE_INPUT)