From mboxrd@z Thu Jan 1 00:00:00 1970 From: Kalle Valo Subject: Re: [PATCH wireless-drivers] mt76x0: Remove VLA usage Date: Wed, 08 Aug 2018 12:46:54 +0300 Message-ID: <871sb942cx.fsf@kamboji.qca.qualcomm.com> References: <20180807225040.GA2164@beast> <20180808092450.GA25772@redhat.com> Mime-Version: 1.0 Content-Type: text/plain Cc: Kees Cook , "David S. Miller" , linux-wireless-u79uwXL29TY76Z2rM5mHXA@public.gmane.org, netdev-u79uwXL29TY76Z2rM5mHXA@public.gmane.org, linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org To: Stanislaw Gruszka Return-path: In-Reply-To: <20180808092450.GA25772-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org> (Stanislaw Gruszka's message of "Wed, 8 Aug 2018 11:24:52 +0200") Sender: linux-wireless-owner-u79uwXL29TY76Z2rM5mHXA@public.gmane.org List-Id: netdev.vger.kernel.org Stanislaw Gruszka writes: > On Tue, Aug 07, 2018 at 03:50:40PM -0700, Kees Cook wrote: >> Even with "const" variables, the compiler will generate warnings about >> VLA usage. In the quest to remove all VLAs from the kernel[1], this uses >> a #define instead of a const to do the array sizing. >> >> [1] >> https://lkml.kernel.org/r/CA+55aFzCG-zNmZwX4A2FQpadafLfEzK6CC=qPXydAacU1RqZWA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org >> >> Fixes: e87b5039511a ("mt76x0: eeprom files") >> Signed-off-by: Kees Cook >> --- >> Please include this for the v4.19 merge window. The VLA was introduced >> with the new source file (which I also note is missing a SPDX line), so > > I thought SPDX line is needed only if file has no license and eeprom.c > file and other mt76x0 files have specified the license. Is SPDX still > needed in that case ? > >> +#define MT_MAP_READS DIV_ROUND_UP(MT_EFUSE_USAGE_MAP_SIZE, 16) >> static int >> mt76x0_efuse_physical_size_check(struct mt76x0_dev *dev) >> { >> - const int map_reads = DIV_ROUND_UP(MT_EFUSE_USAGE_MAP_SIZE, 16); >> - u8 data[map_reads * 16]; > > Why this is variable length array? DIV_ROUND_UP can not be calculated > at compile time? But if so, macro do not change the situation either. The commit log mentioned: "Even with "const" variables, the compiler will generate warnings about VLA usage." So I guess the compiler (gcc?) is just not smart enough in this case? -- Kalle Valo