Received: by 10.213.65.68 with SMTP id h4csp2155004imn; Mon, 2 Apr 2018 02:06:34 -0700 (PDT) X-Google-Smtp-Source: AIpwx4+020FI3n5WW17XJqyuQDqm7ZpJVMDW4GIMEdymEaWR/Y7WVDbhmivJs+Z8Pq9WXEGHb7be X-Received: by 10.98.227.16 with SMTP id g16mr6615452pfh.171.1522659994041; Mon, 02 Apr 2018 02:06:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1522659994; cv=none; d=google.com; s=arc-20160816; b=uZxZeCgjn+5ixJ+sCdeiwR3CNCbpF3kui+i8cb46ydFBj75c1WwDCWITZI5GLkyGcR Faq8OQtp1l2o3YTiGSC/F1JYQz14eEDzNATa/ToL/JDfN6/tnjy0Og383RrghiZ9v1Ne /V5BHv/vod6oypJgs+on/sCrz1vmXHq3l4e3Iyv6hwFKgsIquzA9jk1UY/5H3xCqG1x6 tYr1rHvX2+n2N6ANAM3tGEMmd/0bzG/f5hw2xAc1TKGp0rKJilAn7PC64AzNbORwuXCC 3fH3iHkQZ5hBQoxzpe2NZdXQpDr2zinXljVQFWGn/SIa9PmJKD5pyC/qDKbMDE2+4IzM 5DOg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :message-id:in-reply-to:subject:cc:to:from:date :arc-authentication-results; bh=VB6l8boct6xCVQ5/Iv5WiHUHKxRBPuR8x3ywqJDq/KI=; b=PyVPwyWsFoU9FHiZZD+x6u+wahDrzr/eHim05gj0Q55JZPtTH8I3QwNUG0eBTRdKwx fgGQJKxfnERQDcWsjDIP3soVJPVyDiDtLLQePd3uR2KKmZElh2qiEfQX6/BKLZhQseLG OnyPpJ0kLiVZCoMJtgEhB9mzsWz94LdtcOMOYuuZGQXbpKoQ2Lb+UuoPZkqYYTHdKWVO NC305n05Mg1yrWi67KGAOnxtxVv/GYNgzdz+UsEEVtMAMrJ5ppCjWPNNy6evnvYyJ9r+ uo/pMBLLSxkm9XR/EMCTLmgBuFUAi9ClP3ziNnOQuYKnd2BUZ5NfbpW+g1xnEBbPFtpt wXqg== 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 x10si9542577pgt.109.2018.04.02.02.06.19; Mon, 02 Apr 2018 02:06:34 -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 S1754222AbeDBJFC (ORCPT + 99 others); Mon, 2 Apr 2018 05:05:02 -0400 Received: from mail3-relais-sop.national.inria.fr ([192.134.164.104]:32795 "EHLO mail3-relais-sop.national.inria.fr" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752011AbeDBJFA (ORCPT ); Mon, 2 Apr 2018 05:05:00 -0400 X-IronPort-AV: E=Sophos;i="5.48,395,1517871600"; d="scan'208";a="260585507" Received: from ip-146.net-89-2-7.rev.numericable.fr (HELO [192.168.0.15]) ([89.2.7.146]) by mail3-relais-sop.national.inria.fr with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 02 Apr 2018 11:04:58 +0200 Date: Mon, 2 Apr 2018 11:04:58 +0200 (CEST) From: Julia Lawall X-X-Sender: jll@hadrien To: Lukas Wunner cc: Laura Abbott , Linus Walleij , kbuild-all@01.org, Kees Cook , linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, kernel-hardening@lists.openwall.com, Rasmus Villemoes , Andy Shevchenko Subject: Re: [PATCH] gpio: fix ifnullfree.cocci warnings In-Reply-To: <20180402083150.GA8013@wunner.de> Message-ID: References: <20180402083150.GA8013@wunner.de> User-Agent: Alpine 2.20 (DEB 67 2015-01-07) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, 2 Apr 2018, Lukas Wunner wrote: > On Fri, Mar 30, 2018 at 08:32:56AM +0200, Julia Lawall wrote: > > --- a/drivers/gpio/gpiolib.c > > +++ b/drivers/gpio/gpiolib.c > > @@ -2774,8 +2773,7 @@ int gpiod_get_array_value_complex(bool r > > trace_gpio_value(desc_to_gpio(desc), 1, value); > > } > > > > - if (slowpath) > > - kfree(slowpath); > > + kfree(slowpath); > > } > > return 0; > > } > > @@ -3020,8 +3018,7 @@ int gpiod_set_array_value_complex(bool r > > if (count != 0) > > gpio_chip_set_multiple(chip, mask, bits); > > > > - if (slowpath) > > - kfree(slowpath); > > + kfree(slowpath); > > } > > return 0; > > } > > The problem I see here is that kfree may not be in L1 cache, > and in that case checking for non-NULL locally in this function > should actually be cheaper. > > Note that kfree() need only be called in the slowpath, which > is the *unlikely* case. Letting the branch predictor assume > that kfree() is not called is the right thing to do here. > > The function is a hot path, on the Revolution Pi open source PLCs > we're calling it every 250 usec to poll digital inputs and update > digital outputs. > > Would "if (unlikely(slowpath))" be sufficient to make coccinelle > happy? That's what I'd suggest then. I think that indeed it would not complain any more in this case. But at least from kbuild, you shouldn't get another report on this, even if you don't change it. Of course, someone else running the script could find the issue again. If it would seem appropriate to you, adding a comment would also at least capture the knowledge that the change is not wanted. julia > > Otherwise "if (unlikely(chip->ngpio > FASTPATH_NGPIO))" could be used, > though that might be minimally slower due to the pointer chasing. > > > > @@ -2758,8 +2758,7 @@ int gpiod_get_array_value_complex(bool r > > > > ret = gpio_chip_get_multiple(chip, mask, bits); > > if (ret) { > > - if (slowpath) > > - kfree(slowpath); > > + kfree(slowpath); > > return ret; > > } > > > > This particular change on the other hand is fine because the kfree() > is occurring in an error path, which we'll normally not enter anyway. > > Thanks, > > Lukas >