From patchwork Thu Mar 10 02:11:54 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 595598 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 69466140783 for ; Thu, 10 Mar 2016 13:12:31 +1100 (AEDT) Received: from localhost ([::1]:45689 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1adq5V-0003iv-7v for incoming@patchwork.ozlabs.org; Wed, 09 Mar 2016 21:12:29 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59040) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1adq5E-0003Pu-PE for qemu-devel@nongnu.org; Wed, 09 Mar 2016 21:12:13 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1adq59-00005C-OG for qemu-devel@nongnu.org; Wed, 09 Mar 2016 21:12:12 -0500 Received: from mx1.redhat.com ([209.132.183.28]:52564) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1adq59-000058-IU for qemu-devel@nongnu.org; Wed, 09 Mar 2016 21:12:07 -0500 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (Postfix) with ESMTPS id 4DAF8C0005D8 for ; Thu, 10 Mar 2016 02:12:07 +0000 (UTC) Received: from pxdev.xzpeter.org.com (vpn1-6-29.pek2.redhat.com [10.72.6.29]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u2A2C1NQ030375; Wed, 9 Mar 2016 21:12:03 -0500 From: Peter Xu To: qemu-devel@nongnu.org Date: Thu, 10 Mar 2016 10:11:54 +0800 Message-Id: <1457575914-15581-1-git-send-email-peterx@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: pbonzini@redhat.com, kraxel@redhat.com, peterx@redhat.com Subject: [Qemu-devel] [PATCH] usb: fix unbounded stack warning for xhci_dma_write_u32s X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org 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..d15918f 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[12]; + 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);