Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752582AbdCEV4Z (ORCPT ); Sun, 5 Mar 2017 16:56:25 -0500 Received: from mail-ot0-f171.google.com ([74.125.82.171]:35220 "EHLO mail-ot0-f171.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752421AbdCEV4Y (ORCPT ); Sun, 5 Mar 2017 16:56:24 -0500 MIME-Version: 1.0 In-Reply-To: <20170305211254.GA3220@khazad-dum.debian.net> References: <20170305211254.GA3220@khazad-dum.debian.net> From: Richard Weinberger Date: Sun, 5 Mar 2017 22:49:40 +0100 Message-ID: Subject: Re: Arrays of variable length To: Henrique de Moraes Holschuh Cc: =?UTF-8?B?TcOlbnMgUnVsbGfDpXJk?= , Tomas Winkler , "linux-kernel@vger.kernel.org" , sparse@vger.kernel.org Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: 8bit X-MIME-Autoconverted: from quoted-printable to 8bit by mail.home.local id v25LuZjj003285 Content-Length: 1375 Lines: 34 On Sun, Mar 5, 2017 at 10:12 PM, Henrique de Moraes Holschuh wrote: > 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. First we'd have to fix all existing offenders which are a few... -- Thanks, //richard