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 <justin@dynam.ac>
This commit is contained in:
Justin Hammond 2026-08-16 16:03:55 +08:00 committed by Alan C. Assis
parent 24132be56e
commit edb7d03467

View file

@ -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++)
{