Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752454AbdCEVNF (ORCPT ); Sun, 5 Mar 2017 16:13:05 -0500 Received: from out4-smtp.messagingengine.com ([66.111.4.28]:42309 "EHLO out4-smtp.messagingengine.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752213AbdCEVNE (ORCPT ); Sun, 5 Mar 2017 16:13:04 -0500 X-ME-Sender: X-Sasl-enc: Fyhn2GsqzQgACzPPAea4ObpRCPO6hsGdbeTQzMPzgVxQ 1488748382 Date: Sun, 5 Mar 2017 18:12:54 -0300 From: Henrique de Moraes Holschuh To: =?iso-8859-1?Q?M=E5ns_Rullg=E5rd?= Cc: Tomas Winkler , "linux-kernel@vger.kernel.org" , sparse@vger.kernel.org Subject: Re: Arrays of variable length Message-ID: <20170305211254.GA3220@khazad-dum.debian.net> References: MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: X-GPG-Fingerprint1: 4096R/0x0BD9E81139CB4807: C467 A717 507B BAFE D3C1 6092 0BD9 E811 39CB 4807 User-Agent: Mutt/1.5.23 (2014-03-12) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1196 Lines: 29 On Sun, 05 Mar 2017, M?ns Rullg?rd wrote: > Tomas Winkler writes: > > Sparse complains for arrays declared with variable length > > > > 'warning: Variable length array is used' > > > > Prior to c99 this was not allowed but lgcc (c99) doesn't have problem > > with that https://gcc.gnu.org/onlinedocs/gcc/Variable-Length.html. > > And also Linux kernel compilation with W=1 doesn't complain. > > > > Since sparse is used extensively would like to ask what is the correct > > usage of arrays of variable length > > within Linux Kernel. > > Variable-length arrays are a very bad idea. Don't use them, ever. > If the size has a sane upper bound, just use that value statically. > Otherwise, you have a stack overflow waiting to happen and should be > using some kind of dynamic allocation instead. > > Furthermore, use of VLAs generally results in less efficient code. For > instance, it forces gcc to waste a register for the frame pointer, and > it often prevents inlining. Well, if we're going to forbid VLAs in the kernel, IMHO the kernel build system should call gcc with -Werror=vla to get that point across early, and flush out any offenders. -- Henrique Holschuh