Received: by 10.213.65.68 with SMTP id h4csp417561imn; Tue, 13 Mar 2018 08:25:42 -0700 (PDT) X-Google-Smtp-Source: AG47ELv2YZp4zEiV0XmVX6shlVq0RVun1RAoTBonP2G3hlm8Bs0lU0RbM9VlEEUX/sy8437NIFI5 X-Received: by 10.98.198.92 with SMTP id m89mr990530pfg.73.1520954742535; Tue, 13 Mar 2018 08:25:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1520954742; cv=none; d=google.com; s=arc-20160816; b=ofGMz37UhPSOTwLDZcRHAo4AtNYpckfgxrXlD6ThV6Q0dXr1gXkofn8LTRMgzrPPzp ev1fN1QWRhMCdKFKyv730aO+UxhbbkYlmf8jLgC3JH+lL+Ic1OSQyLQ+G8JvghOWxemM ZhZUZK5x/fIOHuW80emkqWmhluNBci0feLe0f75Jy/+Kx9Sd5M6HhfU29nB6hzlKXBmC Bx77+QIJyWm1qp184k29W2OrGQTvPVcvNgKUKaAJuU0J4KvND0InhWSFnGCVLMjJFH7O kIakdjoJ88iWU2SciJ83S7bE4QfHFhOYVjxu/E42Fbw+OGVFtOsDm1jFkNQQex1FuwWZ Fh+g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:content-disposition :mime-version:message-id:subject:cc:to:from:date :arc-authentication-results; bh=0zq9P7KdgIyN0qYDYUvEX40z2CbImrr92DIiVZU9Mu8=; b=JOEIfMmnusMypsYBcp3ITk6wUZWrTuSR1OzfXVqyT+A5gjbenOcfmZ6h+vgbU8gEkh zdb7VILQMfYWC31+oL4lhH3ky+R+0ifgyvg6H4jr+aEy2L7xmg0zNyhvxIHLHwlED2hh dHBAkQnx7RgyTQHeV16h7kYR1L2XSGUoz+Tzy9k1eIDvQ8453eAqaVES8C1vF3VL7XOL ayxzPKVFiIf4ZaH3HFQeIfGkPEOTrSu05xFewTbrPVQZLD0yG6JUSKsVJDs+4N3qY58N hvUjJFy+SHO7++AIXffKr+buWXFqy6odIWXmR2f1Wwy6pIpjLayhpibP9jYIkiq2Zgt6 P/ow== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g86si312075pfk.94.2018.03.13.08.25.24; Tue, 13 Mar 2018 08:25:42 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752211AbeCMPYA (ORCPT + 99 others); Tue, 13 Mar 2018 11:24:00 -0400 Received: from gateway31.websitewelcome.com ([192.185.144.95]:30086 "EHLO gateway31.websitewelcome.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751970AbeCMPXp (ORCPT ); Tue, 13 Mar 2018 11:23:45 -0400 Received: from cm16.websitewelcome.com (cm16.websitewelcome.com [100.42.49.19]) by gateway31.websitewelcome.com (Postfix) with ESMTP id C0A0B3F5285 for ; Tue, 13 Mar 2018 10:23:44 -0500 (CDT) Received: from gator4166.hostgator.com ([108.167.133.22]) by cmsmtp with SMTP id vlmCeFAZBz11gvlmCerr5P; Tue, 13 Mar 2018 10:23:44 -0500 Received: from [189.175.117.58] (port=56212 helo=embeddedgus) by gator4166.hostgator.com with esmtpa (Exim 4.89_1) (envelope-from ) id 1evlmC-001kPA-8b; Tue, 13 Mar 2018 10:23:44 -0500 Date: Tue, 13 Mar 2018 10:23:43 -0500 From: "Gustavo A. R. Silva" To: Jonathan Cameron , Hartmut Knaack , Lars-Peter Clausen , Peter Meerwald-Stadler Cc: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, "Gustavo A. R. Silva" Subject: [PATCH] iio: potentiometer: ds1803: remove VLA usage Message-ID: <20180313152343.GA31789@embeddedgus> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.5.24 (2015-08-30) X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - gator4166.hostgator.com X-AntiAbuse: Original Domain - vger.kernel.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - embeddedor.com X-BWhitelist: no X-Source-IP: 189.175.117.58 X-Source-L: No X-Exim-ID: 1evlmC-001kPA-8b X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: (embeddedgus) [189.175.117.58]:56212 X-Source-Auth: gustavo@embeddedor.com X-Email-Count: 6 X-Source-Cap: Z3V6aWRpbmU7Z3V6aWRpbmU7Z2F0b3I0MTY2Lmhvc3RnYXRvci5jb20= X-Local-Domain: yes Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org In preparation to enabling -Wvla, remove VLA. In this particular case use macro ARRAY_SIZE so the length of array _result_ can be computed at preprocessing time. The use of stack Variable Length Arrays needs to be avoided, as they can be a vector for stack exhaustion, which can be both a runtime bug or a security flaw. Also, in general, as code evolves it is easy to lose track of how big a VLA can get. Thus, we can end up having runtime failures that are hard to debug. Also, fixed as part of the directive to remove all VLAs from the kernel: https://lkml.org/lkml/2018/3/7/621 Signed-off-by: Gustavo A. R. Silva --- drivers/iio/potentiometer/ds1803.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/iio/potentiometer/ds1803.c b/drivers/iio/potentiometer/ds1803.c index 9b0ff4a..6bf12c9 100644 --- a/drivers/iio/potentiometer/ds1803.c +++ b/drivers/iio/potentiometer/ds1803.c @@ -64,7 +64,7 @@ static int ds1803_read_raw(struct iio_dev *indio_dev, struct ds1803_data *data = iio_priv(indio_dev); int pot = chan->channel; int ret; - u8 result[indio_dev->num_channels]; + u8 result[ARRAY_SIZE(ds1803_channels)]; switch (mask) { case IIO_CHAN_INFO_RAW: -- 2.7.4