Skip to contentSkip to conversation

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

PATCH New Yang Yingliang 1 participant 1 message Nov 25, 2022 USB

lore
Share & tools
lore
#0 lore raw

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

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")
---
 drivers/usb/core/hcd.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/usb/core/hcd.c +5 -1
index faeaace0d197..8300baedafd2 100644
@@ -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));
Signature · 1 line
2.25.1