From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38962) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aeCFF-0002iV-A0 for qemu-devel@nongnu.org; Thu, 10 Mar 2016 20:52:02 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aeCFC-0006xH-4F for qemu-devel@nongnu.org; Thu, 10 Mar 2016 20:52:01 -0500 Received: from mx1.redhat.com ([209.132.183.28]:57566) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aeCFB-0006xA-V4 for qemu-devel@nongnu.org; Thu, 10 Mar 2016 20:51:58 -0500 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by mx1.redhat.com (Postfix) with ESMTPS id 6BFF2254E for ; Fri, 11 Mar 2016 01:51:57 +0000 (UTC) From: Peter Xu Date: Fri, 11 Mar 2016 09:51:46 +0800 Message-Id: <1457661106-9569-1-git-send-email-peterx@redhat.com> Subject: [Qemu-devel] [PATCH v2] usb: fix unbounded stack warning for xhci_dma_write_u32s List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: pbonzini@redhat.com, kraxel@redhat.com, peterx@redhat.com All the callers for xhci_dma_write_u32s() are using mostly 5 * uint32_t in len. To avoid unbound stack warning for the function, make it statically allocated, and assert when it's not big enough in the future. Signed-off-by: Peter Xu --- hw/usb/hcd-xhci.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/hw/usb/hcd-xhci.c b/hw/usb/hcd-xhci.c index 44b6f8c..bcde8a2 100644 --- a/hw/usb/hcd-xhci.c +++ b/hw/usb/hcd-xhci.c @@ -698,11 +698,13 @@ static inline void xhci_dma_write_u32s(XHCIState *xhci, dma_addr_t addr, uint32_t *buf, size_t len) { int i; - uint32_t tmp[len / sizeof(uint32_t)]; + uint32_t tmp[5]; + uint32_t n = len / sizeof(uint32_t); assert((len % sizeof(uint32_t)) == 0); + assert(n <= ARRAY_SIZE(tmp)); - for (i = 0; i < (len / sizeof(uint32_t)); i++) { + for (i = 0; i < n; i++) { tmp[i] = cpu_to_le32(buf[i]); } pci_dma_write(PCI_DEVICE(xhci), addr, tmp, len); -- 2.4.3