Received: by 10.213.65.68 with SMTP id h4csp187485imn; Tue, 13 Mar 2018 00:24:49 -0700 (PDT) X-Google-Smtp-Source: AG47ELsGRyz5CZXrH0P8Nj+GE9jCWOJVLkDkAP4b/b8PQczfedO1QLpArqVA2A3BvOOiDAAjxrOy X-Received: by 10.101.93.135 with SMTP id f7mr8655870pgt.82.1520925889415; Tue, 13 Mar 2018 00:24:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1520925889; cv=none; d=google.com; s=arc-20160816; b=G+J9iN89sBOv2BjcI1g8Tp4Rv4lFNAJIVibd9FYx1DaOQg0rdXSUT3bpEDOCCRJgcU xKTGQMfZCuP8AlfBTU95VsLaYqIpCCzlsqfDdQbEVICwsNV8uZC5TGJLiJ4qRMfNL+/O HN81zFparBC0KNO9sTA5FTz/iQsu8AIsAiKDXdHScX+Uje4EQceQMSFuCK5fN7rt9eCq Q9CZzXFZddYgbm2DwE7soKPBVTqaP/2afQwHHgoQvp831XdhU1UoQO7uBG2ovQ39Gc+l y/UQXJONkKpH0mcbqLJXlUsT6kDtjNzScEYxsFlidCO6ilXBcO4VDoTzYzVKdN36WziV XjGQ== 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:dkim-signature :arc-authentication-results; bh=5LmFD6ETYVmTmjjoiNX6b19XalHs4Y7DmMY5G6mXyQE=; b=bvBre8k5nwsCXZq0PdNFH3ww1bWqxoiWY+By9cINPqPe2S3B6s5F6x2H1yJXm6tb73 RUnCS1YOVmHazcANUwInkDrAjaBXYXn+kkJ+og2xJB4xm/H8t8bxw/J2uhtndJWTJe+t s2k3cP018LoatwgX9UjROqteTkrRshbEYOcp9WNjl9OKxsXGYEzqK5y6c5pT2q1Lu0NP O9ZJY0zLMCQJjw6evq1Qe9p3Nyu77c4esBznMnfg/P4UUOEX9wohb3Jj+e+vooljuCfS yDjvOIPpZUE0ZGhsuhTlLIsx0EMmMI/X8B94D4ZCLJf6CZ1+hLX+7AEvpx8A84m8qA4G YaLQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@rasmusvillemoes.dk header.s=google header.b=TwlgBBDq; 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 l64si6192893pgl.485.2018.03.13.00.24.34; Tue, 13 Mar 2018 00:24:49 -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=@rasmusvillemoes.dk header.s=google header.b=TwlgBBDq; 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 S1752034AbeCMHX2 (ORCPT + 99 others); Tue, 13 Mar 2018 03:23:28 -0400 Received: from mail-lf0-f43.google.com ([209.85.215.43]:46633 "EHLO mail-lf0-f43.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751647AbeCMHX0 (ORCPT ); Tue, 13 Mar 2018 03:23:26 -0400 Received: by mail-lf0-f43.google.com with SMTP id w16-v6so6049196lfc.13 for ; Tue, 13 Mar 2018 00:23:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rasmusvillemoes.dk; s=google; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=5LmFD6ETYVmTmjjoiNX6b19XalHs4Y7DmMY5G6mXyQE=; b=TwlgBBDqzFWD8IQzuoLkLWTy8P2T8t4i/BlLhKNssoNxWdBGYLEdfPZ2DmyAT+Ymcd fFJRoBWEbYQNpaUchH+JXHY6usqqscaPF7Z6a3NA8C4/al96QtmMWbaOtqHDuK076UNp oEVbcSQq9eyCvDxdHbtI7oczEGVNnHBQOFlFY= 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=5LmFD6ETYVmTmjjoiNX6b19XalHs4Y7DmMY5G6mXyQE=; b=mLTRpxxHy3zf3KF0dLWI/UvAE/2liedq4lF0LiofttMDUPAByT+1Tl87aH+qGHSRwQ fq4yzfiHJ00S9GfpyF2lY7xHWYjHx0c/6ifEKCwMGJSJtyTKkeC+lW8flRNeHg+m0oy0 Nk/ET6B1r/44q9fGg78EXOsP4guvQ7eAEqj7S7zd5MCqG1ngVB6ukm+GBXdGo1fgbaiF 6osbyb62wQOF1rwHkSMeVyECrCn9N6kXZoke+oDLPLO5Prh//0Yn9LocRBMS/QWj+Tua HB6Y0lryTZsrLXBp1Qp72xn4kXMJvPyOcQrBdeR3Lq+k3vwClMcNjbK7Lv1O5ISjuwG5 MXOg== X-Gm-Message-State: AElRT7HM1rV6YyOm/wAmxeXRTtnhcej3YOqBFnwu+K/yugR3HQ2RdHCm bL/NF9SgRw7kZbEDEhkK1rIIrA== X-Received: by 2002:a19:2c10:: with SMTP id s16-v6mr6781829lfs.15.1520925804427; Tue, 13 Mar 2018 00:23:24 -0700 (PDT) Received: from [172.16.11.22] ([81.216.59.226]) by smtp.gmail.com with ESMTPSA id o192-v6sm834594lfo.17.2018.03.13.00.23.23 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 13 Mar 2018 00:23:23 -0700 (PDT) Subject: Re: [PATCH 1/4] gpio: Remove VLA from gpiolib To: Laura Abbott , Rasmus Villemoes , Linus Walleij , Kees Cook Cc: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, kernel-hardening@lists.openwall.com, Lukas Wunner , Mathias Duckeck , Nandor Han , Semi Malinen , Patrice Chotard References: <20180310001021.6437-1-labbott@redhat.com> <20180310001021.6437-2-labbott@redhat.com> <301ecaf7-62a4-14af-3a5b-7bd76a49c4f6@redhat.com> From: Rasmus Villemoes Message-ID: Date: Tue, 13 Mar 2018 08:23:22 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.6.0 MIME-Version: 1.0 In-Reply-To: <301ecaf7-62a4-14af-3a5b-7bd76a49c4f6@redhat.com> Content-Type: text/plain; charset=utf-8 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 2018-03-13 00:40, Laura Abbott wrote: > On 03/12/2018 08:00 AM, Rasmus Villemoes wrote: >> >> Hm, it seems you're now only clearing the first word of mask, not the >> entire allocation. Why not just use kcalloc() instead of kmalloc_array >> to have it automatically cleared? > > Bleh, I didn't think through that carefully. I'll just switch > to kcalloc, especially since it calls kmalloc_array. > >> Other random thoughts: maybe two allocations for each loop iteration is >> a bit much. Maybe do a first pass over the array and collect the maximal >> chip->ngpio, do the memory allocation and freeing outside the loop (then >> you'd of course need to preserve the memset() with appropriate length >> computed). And maybe even just do one allocation, making bits point at >> the second half. >> > > I was trying to make minimal changes and match the existing code. Well, textually you may be making the minimal changes (though the error handling adds some "boilerplate" kfree()s etc.), but semantically adding two kmallocs in a loop could be a big deal. Dunno, maybe in practice all the gpios (almost always) belong to the same chip, so there's only one iteration through the loop anyway. > Is this likely to be an actual hot path to optimize? No idea, it was just a drive-by comment, so also... >> Does the set function need to be updated to return an int to be able to >> inform the caller that memory allocation failed? > > That would involve changing the public API. I don't have a problem > doing so if that's what you want. ... I don't "want" anything, that'll be for the gpio maintainers to decide. Rasmus