diff mbox series

[13/23] hw/usb/hcd-xhci: Avoid dynamic stack allocation

Message ID 20210505211047.1496765-14-philmd@redhat.com (mailing list archive)
State New, archived
Headers show
Series misc: Remove variable-length arrays on the stack | expand

Commit Message

Philippe Mathieu-Daudé May 5, 2021, 9:10 p.m. UTC
Use autofree heap allocation instead of variable-length
array on the stack.

Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
---
 hw/usb/hcd-xhci.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Richard Henderson May 7, 2021, 4:34 p.m. UTC | #1
On 5/5/21 2:10 PM, Philippe Mathieu-Daudé wrote:
> Use autofree heap allocation instead of variable-length
> array on the stack.
> 
> Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
> ---
>   hw/usb/hcd-xhci.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/hw/usb/hcd-xhci.c b/hw/usb/hcd-xhci.c
> index 7acfb8137bc..59a267e3c8b 100644
> --- a/hw/usb/hcd-xhci.c
> +++ b/hw/usb/hcd-xhci.c
> @@ -2387,7 +2387,7 @@ static void xhci_detach_slot(XHCIState *xhci, USBPort *uport)
>   static TRBCCode xhci_get_port_bandwidth(XHCIState *xhci, uint64_t pctx)
>   {
>       dma_addr_t ctx;
> -    uint8_t bw_ctx[xhci->numports+1];
> +    g_autofree uint8_t *bw_ctx = g_malloc(xhci->numports + 1);


There is a later use of sizeof(bw_ctx), which is now broken.

Also, I think you might as well remove this buffer entirely and use the address 
space memset routine you recently added.


r~
diff mbox series

Patch

diff --git a/hw/usb/hcd-xhci.c b/hw/usb/hcd-xhci.c
index 7acfb8137bc..59a267e3c8b 100644
--- a/hw/usb/hcd-xhci.c
+++ b/hw/usb/hcd-xhci.c
@@ -2387,7 +2387,7 @@  static void xhci_detach_slot(XHCIState *xhci, USBPort *uport)
 static TRBCCode xhci_get_port_bandwidth(XHCIState *xhci, uint64_t pctx)
 {
     dma_addr_t ctx;
-    uint8_t bw_ctx[xhci->numports+1];
+    g_autofree uint8_t *bw_ctx = g_malloc(xhci->numports + 1);
 
     DPRINTF("xhci_get_port_bandwidth()\n");