Linux USB
 help / color / mirror / Atom feed
* [PATCH] usb: xhci: Check kcalloc_node() when allocating interrupter array in xhci_mem_init()
@ 2025-09-18 13:08 Guangshuo Li
  2025-09-18 15:38 ` Michal Pecio
  2025-11-03  8:40 ` Michal Pecio
  0 siblings, 2 replies; 6+ messages in thread
From: Guangshuo Li @ 2025-09-18 13:08 UTC (permalink / raw)
  To: Mathias Nyman, Greg Kroah-Hartman, Wesley Cheng, linux-usb,
	linux-kernel
  Cc: Guangshuo Li, stable

kcalloc_node() may fail. When the interrupter array allocation returns
NULL, subsequent code uses xhci->interrupters (e.g. in xhci_add_interrupter()
and in cleanup paths), leading to a potential NULL pointer dereference.

Check the allocation and bail out to the existing fail path to avoid
the NULL dereference.

Fixes: c99b38c412343 ("xhci: add support to allocate several interrupters")
Cc: stable@vger.kernel.org
Signed-off-by: Guangshuo Li <lgs201920130244@gmail.com>
---
 drivers/usb/host/xhci-mem.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/usb/host/xhci-mem.c b/drivers/usb/host/xhci-mem.c
index d698095fc88d..da257856e864 100644
--- a/drivers/usb/host/xhci-mem.c
+++ b/drivers/usb/host/xhci-mem.c
@@ -2505,7 +2505,8 @@ int xhci_mem_init(struct xhci_hcd *xhci, gfp_t flags)
 		       "Allocating primary event ring");
 	xhci->interrupters = kcalloc_node(xhci->max_interrupters, sizeof(*xhci->interrupters),
 					  flags, dev_to_node(dev));
-
+	if (!xhci->interrupters)
+		goto fail;
 	ir = xhci_alloc_interrupter(xhci, 0, flags);
 	if (!ir)
 		goto fail;
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2025-11-03 11:49 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-09-18 13:08 [PATCH] usb: xhci: Check kcalloc_node() when allocating interrupter array in xhci_mem_init() Guangshuo Li
2025-09-18 15:38 ` Michal Pecio
2025-11-03  8:40 ` Michal Pecio
2025-11-03 11:02   ` Mathias Nyman
2025-11-03 11:23     ` Michal Pecio
2025-11-03 11:49   ` Greg Kroah-Hartman

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox