diff mbox series

usb: core: hcd: Fix return value check in usb_hcd_setup_local_mem()

Message ID 20221125064120.2842452-1-yangyingliang@huawei.com
State New
Headers show
Series usb: core: hcd: Fix return value check in usb_hcd_setup_local_mem() | expand

Commit Message

Yang Yingliang Nov. 25, 2022, 6:41 a.m. UTC
If dmam_alloc_attrs() fails, it returns NULL pointer and never
return ERR_PTR(), so repleace IS_ERR() with IS_ERR_OR_NULL()
and if it's NULL, returns -ENOMEM.

Fixes: 9ba26f5cecd8 ("ARM: sa1100/assabet: move dmabounce hack to ohci driver")
Signed-off-by: Yang Yingliang <yangyingliang@huawei.com>
---
 drivers/usb/core/hcd.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c
index faeaace0d197..8300baedafd2 100644
--- a/drivers/usb/core/hcd.c
+++ b/drivers/usb/core/hcd.c
@@ -3128,18 +3128,22 @@  int usb_hcd_setup_local_mem(struct usb_hcd *hcd, phys_addr_t phys_addr,
 	if (phys_addr)
 		local_mem = devm_memremap(hcd->self.sysdev, phys_addr,
 					  size, MEMREMAP_WC);
 	else
 		local_mem = dmam_alloc_attrs(hcd->self.sysdev, size, &dma,
 					     GFP_KERNEL,
 					     DMA_ATTR_WRITE_COMBINE);
 
-	if (IS_ERR(local_mem))
+	if (IS_ERR_OR_NULL(local_mem)) {
+		if (!local_mem)
+			return -ENOMEM;
+
 		return PTR_ERR(local_mem);
+	}
 
 	/*
 	 * Here we pass a dma_addr_t but the arg type is a phys_addr_t.
 	 * It's not backed by system memory and thus there's no kernel mapping
 	 * for it.
 	 */
 	err = gen_pool_add_virt(hcd->localmem_pool, (unsigned long)local_mem,
 				dma, size, dev_to_node(hcd->self.sysdev));