From 01a0d1ea31c485ff434aa8d1cbcbfc89f724fff9 Mon Sep 17 00:00:00 2001 From: "J. Avila" Date: Tue, 13 Apr 2021 19:24:57 +0000 Subject: [PATCH] ANDROID: usb: host: Use old init scheme when hook unavailable In cases where the new xhci hooks are unimplemented, ctx->bytes may never be initialized, leading to null pointer crashes. Fix this by only calling xhci_vendor_alloc/free_container_ctx when the corresponding hook is present. Bug: 185191548 Signed-off-by: J. Avila Change-Id: Ia77b0815ddc8bc340a286731558c754c779e883a --- drivers/usb/host/xhci-mem.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/drivers/usb/host/xhci-mem.c b/drivers/usb/host/xhci-mem.c index 6eda84e51138..b5bd2ce37445 100644 --- a/drivers/usb/host/xhci-mem.c +++ b/drivers/usb/host/xhci-mem.c @@ -528,6 +528,7 @@ struct xhci_container_ctx *xhci_alloc_container_ctx(struct xhci_hcd *xhci, { struct xhci_container_ctx *ctx; struct device *dev = xhci_to_hcd(xhci)->self.sysdev; + struct xhci_vendor_ops *ops = xhci_vendor_get_ops(xhci); if ((type != XHCI_CTX_TYPE_DEVICE) && (type != XHCI_CTX_TYPE_INPUT)) return NULL; @@ -541,7 +542,8 @@ struct xhci_container_ctx *xhci_alloc_container_ctx(struct xhci_hcd *xhci, if (type == XHCI_CTX_TYPE_INPUT) ctx->size += CTX_SIZE(xhci->hcc_params); - if (xhci_vendor_is_usb_offload_enabled(xhci, NULL, 0)) + if (xhci_vendor_is_usb_offload_enabled(xhci, NULL, 0) && + (ops && ops->alloc_container_ctx)) xhci_vendor_alloc_container_ctx(xhci, ctx, type, flags); else ctx->bytes = dma_pool_zalloc(xhci->device_pool, flags, &ctx->dma); @@ -556,9 +558,12 @@ struct xhci_container_ctx *xhci_alloc_container_ctx(struct xhci_hcd *xhci, void xhci_free_container_ctx(struct xhci_hcd *xhci, struct xhci_container_ctx *ctx) { + struct xhci_vendor_ops *ops = xhci_vendor_get_ops(xhci); + if (!ctx) return; - if (xhci_vendor_is_usb_offload_enabled(xhci, NULL, 0)) + if (xhci_vendor_is_usb_offload_enabled(xhci, NULL, 0) && + (ops && ops->free_container_ctx)) xhci_vendor_free_container_ctx(xhci, ctx); else dma_pool_free(xhci->device_pool, ctx->bytes, ctx->dma);