This is an automated email from the ASF dual-hosted git repository.

acassis pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git

commit edb7d034671594194c04739532c2cfd5d22cce3f
Author: Justin Hammond <[email protected]>
AuthorDate: Sun Aug 16 16:03:55 2026 +0800

    drivers/usbhost: Allow an xHCI controller with no scratchpad buffers.
    
    HCSPARAMS2 may report zero scratchpad buffers; QEMU's does.  The driver
    sized the array from that count unconditionally and read the NULL from a
    zero byte kmm_memalign() as -ENOMEM, so such a controller never started.
    
    Skip the allocation when no_scratch is zero, leaving DCBAA[0] clear.
    
    Assisted-by: Claude:claude-opus-5
    Signed-off-by: Justin Hammond <[email protected]>
---
 drivers/usbhost/usbhost_xhci_pci.c | 21 +++++++++++++--------
 1 file changed, 13 insertions(+), 8 deletions(-)

diff --git a/drivers/usbhost/usbhost_xhci_pci.c 
b/drivers/usbhost/usbhost_xhci_pci.c
index 68d5e06aa4e..0f31007d9bb 100644
--- a/drivers/usbhost/usbhost_xhci_pci.c
+++ b/drivers/usbhost/usbhost_xhci_pci.c
@@ -4365,17 +4365,22 @@ static int xhci_mem_alloc(FAR struct usbhost_xhci_s 
*priv)
   size_t tmp;
   int    i;
 
-  /* Allocate Scratchpad Buffer Array */
+  /* Allocate the Scratchpad Buffer Array, if one is wanted.  no_scratch
+   * may be zero, and a zero byte allocation returns NULL.
+   */
 
-  tmp = priv->no_scratch * sizeof(uint64_t);
-  priv->pg_sb = kmm_memalign(XHCI_BUF_ALIGN, tmp);
-  if (!priv->pg_sb)
+  if (priv->no_scratch > 0)
     {
-      pcierr("pg_sb malloc failed\n");
-      return -ENOMEM;
-    }
+      tmp = priv->no_scratch * sizeof(uint64_t);
+      priv->pg_sb = kmm_memalign(XHCI_BUF_ALIGN, tmp);
+      if (!priv->pg_sb)
+        {
+          pcierr("pg_sb malloc failed\n");
+          return -ENOMEM;
+        }
 
-  memset(priv->pg_sb, 0, tmp);
+      memset(priv->pg_sb, 0, tmp);
+    }
 
   for (i = 0; i < priv->no_scratch; i++)
     {

Reply via email to