Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp4927069imm; Fri, 18 May 2018 13:07:44 -0700 (PDT) X-Google-Smtp-Source: AB8JxZqiwV+tiy/Srn2WTR2gqa/xgO102hKEBuTdQxKKGmaFCy4BbenD7FoLemNVEMI5/ERxleAF X-Received: by 2002:a62:ecdc:: with SMTP id e89-v6mr10798963pfm.33.1526674064851; Fri, 18 May 2018 13:07:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526674064; cv=none; d=google.com; s=arc-20160816; b=rUMCAroUzCoNTIefafUnPgW1Cz/8LekmK84weJui+JzbAMmWGJN2N50S9Vh21rzG9f TS12+HS9+kux7JmwQEd7s4TAyBR0b3hDIkTaUzdZYrZCJW/h22eR5uMp7tREomjnz+pq ICM4YXwdLzDGUcKWGt8umbTbA4wESQjXE7t/B4Z8hEbx9EiJDl/nNBX71QDUplFS7lLH boSa5oswDDlgPc+IudWkzLL4qTQb7Fosk5W1QU1a2wcFGSzxQ9xp3muYKYdE9A5jm/6g XZkxg4xi1VLUv/H1n33LogBTEsOo5uJKr4tChKIaBbuPqobr1QY9tRacPka1uKHe/G2T pEwg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :references:in-reply-to:mime-version:dkim-signature :arc-authentication-results; bh=pzLNwYPvHP/tk9C1vef/J1O5mvGtL/zKj+D1XYwaKf0=; b=MFbr9lAUJ+zQrbpsITiOP2Y5JxGaAcnrEH/EOnDm/HvwMh3A1lznEZOjE5uPc+7mNN c4ypOmUcv0OxQR0Y1obWhm4Qzt0Ow1L6PrtoI8HNn1CGr+iWndmBGc+qaZ77B3JgePQv v6pGPKC2HrjhsDbTu4ToDTLO0E5r0KX99okwZOw8gUdKERQVNi3OsRz8YPl9naZHk7by WV6Hoj3bsIBuEJtTrS60OkCojF/56/R/T1yIQI3+bPuGDkuuGphZMaiNAG1gnTFzzBFz Iy4XaD5FMYLABaFbcBFfkRGZwgz7iXJmo1cckvV0x0Y/BXiehJk9wn28BdQDMF27R39b KHbA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=BaEaxZMu; 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=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y199-v6si8455911pfb.284.2018.05.18.13.07.30; Fri, 18 May 2018 13:07:44 -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; dkim=pass header.i=@gmail.com header.s=20161025 header.b=BaEaxZMu; 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=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752173AbeERUHH (ORCPT + 99 others); Fri, 18 May 2018 16:07:07 -0400 Received: from mail-qt0-f193.google.com ([209.85.216.193]:39590 "EHLO mail-qt0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751405AbeERUHF (ORCPT ); Fri, 18 May 2018 16:07:05 -0400 Received: by mail-qt0-f193.google.com with SMTP id f1-v6so11868716qtj.6; Fri, 18 May 2018 13:07:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=pzLNwYPvHP/tk9C1vef/J1O5mvGtL/zKj+D1XYwaKf0=; b=BaEaxZMuff/NP1On8FYjm5udcutNqua8bf4+7Oqp8jbIJDnit2DKvOPAPhQuSVGGaX orxmLP5EZBtu2MsHNtHaoRbkAcKHPtkUdz6gvPhHxKlWOv/c5sHEvXrsJXGN8Ax4oGTO 7viJ3TOWGsA+vUDs0ldZ5toL7kA8aktMkjVtHYm03y+l0jXANfJZ310yFjsT3+dpQNe+ HBGC3+cSlctlWDJoTdI+b4oNe2Qx8IokTGjHl1fiLKIZFvQSHrVaJSGWxjV+m45nHKlq RtSEPHcM/g0j5/riEYt2/PD1VPR/vYjPrIoopJM3/mgZ6P01MDhCkbBqY37SjzujOg8o R+EQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=pzLNwYPvHP/tk9C1vef/J1O5mvGtL/zKj+D1XYwaKf0=; b=VoSXcTJKkT4WfnGugoQUGvg0cH5Oef9UuPlVlq479vDNdtgcJxne2A3z/jF7DOt24I 1HW6C2Dbcntjnn9Gq3n0iKzHNvTqEIQyyz9Y5e7NEEGQYCNJKchSXPO82HVhbn2Otpwh unZ9o3xM89XEXQDFkl/tkdEJn62Q+sBLa2O0vJ3p2UlOUiv6p2iR+dvJK7EiefWTBf2a m0YUEzNMd6FvWhwotilP6dfZzFJMq9/WtFF/wMnBPEvKjD4npp7WvenIIVaDgwUOTZFM y900B1Zepq0w5mh7OW2CPkxkMV5BPr8TJP8glLjG1ZGGzcmAiK1JEtL3t+B2i/NqHT6T k+cg== X-Gm-Message-State: ALKqPwdFj4Se7HU7oAB02VshSmsnuIkgVE+2zGWBVpLqOIqTQZjnrVYJ ecm3YeaI/RF1T31VYWgISE+00cEhrCbV6I0t41AO+A== X-Received: by 2002:ac8:3488:: with SMTP id w8-v6mr11049187qtb.278.1526674025051; Fri, 18 May 2018 13:07:05 -0700 (PDT) MIME-Version: 1.0 Received: by 10.12.152.150 with HTTP; Fri, 18 May 2018 13:07:04 -0700 (PDT) In-Reply-To: <20180518175304.20414-1-labbott@redhat.com> References: <20180518175304.20414-1-labbott@redhat.com> From: Andy Shevchenko Date: Fri, 18 May 2018 23:07:04 +0300 Message-ID: Subject: Re: [PATCHv8] gpio: Remove VLA from gpiolib To: Laura Abbott Cc: Linus Walleij , Kees Cook , Lukas Wunner , Rasmus Villemoes , "open list:GPIO SUBSYSTEM" , Linux Kernel Mailing List , kernel-hardening@lists.openwall.com, Phil Reid , Geert Uytterhoeven Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, May 18, 2018 at 8:53 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. > + unsigned long fastpath[2 * BITS_TO_LONGS(FASTPATH_NGPIO)]; > + unsigned long *mask, *bits; > int first, j, ret; > > + if (likely(chip->ngpio <= FASTPATH_NGPIO)) { > + mask = fastpath; > + } else { > + mask = kmalloc_array(2 * BITS_TO_LONGS(chip->ngpio), > + sizeof(*mask), > + can_sleep ? GFP_KERNEL : GFP_ATOMIC); > + if (!mask) > + return -ENOMEM; > + } > + > + bits = mask + BITS_TO_LONGS(chip->ngpio); > + memset(mask, 0, BITS_TO_LONGS(chip->ngpio) * sizeof(*mask)); Wouldn't be better bitmap_zero(mask, chip->ngpio); ? > + bits = mask + BITS_TO_LONGS(chip->ngpio); > + memset(mask, 0, BITS_TO_LONGS(chip->ngpio) * sizeof(*mask)); Ditto. -- With Best Regards, Andy Shevchenko