From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35170) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1adGeG-0000gM-GE for qemu-devel@nongnu.org; Tue, 08 Mar 2016 07:22:01 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1adGeC-0007aP-Bb for qemu-devel@nongnu.org; Tue, 08 Mar 2016 07:22:00 -0500 Received: from mx1.redhat.com ([209.132.183.28]:48921) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1adGeC-0007aL-6R for qemu-devel@nongnu.org; Tue, 08 Mar 2016 07:21:56 -0500 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (Postfix) with ESMTPS id D0565388B75 for ; Tue, 8 Mar 2016 12:21:55 +0000 (UTC) References: <1457420446-25276-1-git-send-email-peterx@redhat.com> <1457420446-25276-5-git-send-email-peterx@redhat.com> From: Paolo Bonzini Message-ID: <56DEC3E0.1010404@redhat.com> Date: Tue, 8 Mar 2016 13:21:52 +0100 MIME-Version: 1.0 In-Reply-To: <1457420446-25276-5-git-send-email-peterx@redhat.com> Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH 4/8] usb: fix unbounded stack for xhci_dma_write_u32s List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Peter Xu , qemu-devel@nongnu.org Cc: Gerd Hoffmann On 08/03/2016 08:00, Peter Xu wrote: > First of all, this function cannot be inlined even with always_inline, > so removing inline. Why? always_inline fixes the error for me. > int i; > - uint32_t tmp[len / sizeof(uint32_t)]; > + uint32_t n = len / sizeof(uint32_t); > +#define __BUF_SIZE (12) > + uint32_t tmp[__BUF_SIZE]; > > + assert(__BUF_SIZE >= n); Instead of a #define, you can use ARRAY_SIZE(tmp). Paolo > assert((len % sizeof(uint32_t)) == 0); > > - 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); > +#undef __BUF_SIZE > } > > static XHCIPort *xhci_lookup_port(XHCIState *xhci, struct USBPort *uport) >