Received: by 10.213.65.68 with SMTP id h4csp1041897imn; Wed, 4 Apr 2018 11:33:23 -0700 (PDT) X-Google-Smtp-Source: AIpwx489umbx+Fk0Amo0ldoaXz+c41vP2leEXWxilx9y7PVQGmaT/+2dQHbQK6ZmeKgaGq129vQN X-Received: by 2002:a17:902:1665:: with SMTP id g92-v6mr19151608plg.195.1522866803402; Wed, 04 Apr 2018 11:33:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1522866803; cv=none; d=google.com; s=arc-20160816; b=kqRuimS6IKumLseH+fFg89TGktLwVpT5lDDVUBpYJA8b/x9+PA4WTjc/1SN5bL9Brn fZ/UlbbirNNARKS21wDqc5Ijd8SP6lrEZJcIceM3xp1v2/a+o+mo3ygAgvXYHEQhzRx1 Bx3ZXlqTtdrolBd5tGEDBILWJNMx+nEZ/26gm2cFF7dHYUcV+WlApku+p4Z9mMzGSCmN jgg+ItRiVBZqsxHh52Rdu++Kr+qYO4MYf7mL0A+/8HkfSxNg3OqYLC1IhvDorxwK4G6q VExotI1rbkSDi+8N7Hb+/AzAp93lxZSbQ0kDVakMaQAhiavJrYfBkbl9XRZ+QySKANXP fagg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:arc-authentication-results; bh=vpoRiENI9SfFPVdel6/XYsgsUfH2NBNOOe7jF53InkA=; b=nLxtWYaVE7YOyQVnQlnq4PRHROiLjwRq2b4j7I5zb+tG31Ag2nweiN0auvHF4K6ajf uzC82NQLkJWoMzTY3FJVk8zVFPzJfg2/ovyGSpsfFll8YpgJcy2Cv9saL5l/O/geIiy1 0vxgegpovjLT22euCLSnjnyk2s4mokJRxFLpGuMcjQSCIkFIn6PhQ3iXtMJcyJoVIDKG s977v6rzLyRhnhtrH7UKkvxnMJv5G1JtfvkDXBcTQJryDlmUPM4IDE88HjroPt6nbPhn 90kUDK2OcuoL7JCwg4yLi4xPxbtS7QqPYDN3VDdyTJiSm327pQNiLY7iKimWuVB3SrWi UybA== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id r20si4605941pfk.224.2018.04.04.11.33.09; Wed, 04 Apr 2018 11:33:23 -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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751517AbeDDSbq (ORCPT + 99 others); Wed, 4 Apr 2018 14:31:46 -0400 Received: from mail-oi0-f67.google.com ([209.85.218.67]:33687 "EHLO mail-oi0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751312AbeDDSbo (ORCPT ); Wed, 4 Apr 2018 14:31:44 -0400 Received: by mail-oi0-f67.google.com with SMTP id 126-v6so20176070oig.0 for ; Wed, 04 Apr 2018 11:31:44 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=vpoRiENI9SfFPVdel6/XYsgsUfH2NBNOOe7jF53InkA=; b=AnuRTUxedJk5PUtUWXs460x5s/bXvCep6AgOPbxaNZbBtg6fKsvTP/5TdjdoUM754d cZbae+/OROEFuDgjJ1HgyZS03PMaZme6J8bP7oDJi9fub2b/apHKKNOc8yJmJdq+RpNQ xTHYOox9nvQY7y25gfbWS2ShXXo8Rih7J4X1YJkLRZwd72KVgvjWqUYdhBulx5SGD+5f zgFEz9WLAjgzIn/d13L36J/no+VNyy+5fd1Q4efxl3Ugg8P4beQXIFUQg4yYcoc9BdH+ D7QjJOOB7+7NWEJoty6FWdNWyozDXdqe/JVs4ForQaW/6zUv/GwPfUsdZZE3OoMOpgHW jmnA== X-Gm-Message-State: ALQs6tBjHBeW5FFCuOqvDtMlyx9tKSSagDfe8wgelJ37JNmlJgUJ5QE0 c5O+xd+2N8yb1/Sf53HyRiHXSA== X-Received: by 2002:aca:be46:: with SMTP id o67-v6mr11172864oif.103.1522866703881; Wed, 04 Apr 2018 11:31:43 -0700 (PDT) Received: from ?IPv6:2601:602:9802:a8dc::1082? ([2601:602:9802:a8dc::1082]) by smtp.gmail.com with ESMTPSA id h132-v6sm3292738oib.45.2018.04.04.11.31.41 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 04 Apr 2018 11:31:42 -0700 (PDT) Subject: Re: [PATCHv3] gpio: Remove VLA from gpiolib To: Andy Shevchenko Cc: Linus Walleij , Kees Cook , Lukas Wunner , "open list:GPIO SUBSYSTEM" , Linux Kernel Mailing List , kernel-hardening@lists.openwall.com, Rasmus Villemoes References: <20180328181809.24505-1-labbott@redhat.com> From: Laura Abbott Message-ID: <2c191bd2-9df5-ecc1-1bf3-5ad19bea9138@redhat.com> Date: Wed, 4 Apr 2018 11:31:41 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.7.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 03/30/2018 07:33 AM, Andy Shevchenko wrote: > On Wed, Mar 28, 2018 at 9:18 PM, Laura Abbott wrote: >> The new challenge is to remove VLAs from the kernel >> (see https://lkml.org/lkml/2018/3/7/621) to eventually >> turn on -Wvla. >> >> Using a kmalloc array is the easy way to fix this but kmalloc is still >> more expensive than stack allocation. Introduce a fast path with a >> fixed size stack array to cover most chip with gpios below some fixed >> amount. The slow path dynamically allocates an array to cover those >> chips with a large number of gpios. > >> + ret = gpiod_set_array_value_complex(false, >> true, >> lh->numdescs, >> lh->descs, >> vals); >> + if (ret) >> + return ret; >> + >> return 0; > > Can't we > > return gpiod_set_array_value_complex(); ? > > Yeah I'll clean that up for v4. >> + slowpath = kcalloc(2 * BITS_TO_LONGS(chip->ngpio), >> + sizeof(*slowpath), >> + can_sleep ? GFP_KERNEL : GFP_ATOMIC); > > >> + if (slowpath) >> + kfree(slowpath); > >> + if (slowpath) >> + kfree(slowpath); > > Since slowpath is a pointer, conditionals above are redundant. > >> + slowpath = kcalloc(2 * BITS_TO_LONGS(chip->ngpio), >> + sizeof(*slowpath), >> + can_sleep ? GFP_KERNEL : GFP_ATOMIC); > >> + if (slowpath) >> + kfree(slowpath); > > Ditto. > This was caught by a coccinelle script via 0-day but I think the request was to not do it. I'll add a comment explaining why we are going against style. Thanks, Laura