Received: by 10.213.65.68 with SMTP id h4csp2133200imn; Mon, 2 Apr 2018 01:33:12 -0700 (PDT) X-Google-Smtp-Source: AIpwx49I0iqo9zJp+TBa5HKSVQYUBAiSJ5v7or6sdyvrjZXrat99bhLitS4e0jXyaq1p/EpO9fG6 X-Received: by 2002:a17:902:33a5:: with SMTP id b34-v6mr8970966plc.232.1522657992447; Mon, 02 Apr 2018 01:33:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1522657992; cv=none; d=google.com; s=arc-20160816; b=SYYGkn/JaI0SxnlJnh21UW54Wn7FlMRTXhFfm4CEA0FmAxZZR0QAaguKZH5VTsDn3Q RPnshg5gm9SLo/E0T98/0wvI3ELwdedihEIn3n1WRSEQBV+x+rzEi8URlyP+9l+7ZgAe kX/hFl1RqIDcNrHcwQA970TrsFmauY6kFSdAA1aXx2RpeIo5lDYD5+dlVMLv23iK1Y5v CcwKNRrylwITDGL/X1IA3eWTxYQJOg8QZoLjr1G6WzuORKvfYW24K65VYNDD9XWtcveq UaMhhQ8MkUGNpmqhVF64u2OqV1VcCfVJZIyYOCqmHar3zdebStgPRUkvv3+BVa19rH1D 4zUQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:arc-authentication-results; bh=3lDJHsG6MMVh5IRSGZJKTQwgystZk4PBNaWNub81rVc=; b=kGvNPuMlqnFhgZwE7lIgucZoLLrEh1ZZgGixO8GA6kQ1Hvo16lO2dzrYeTILqGI0q/ Rq8IX8LVDUm3DIt23CYC4J8+u56DzbK43RiuOFDpNec2HhQ22DEFPBShRrpJyjeuZLn+ t1rPG1np9Qq7gagJgn59YmI4MrXYURHGMaK56jMc05UgW6tAbLLb73k++8B2TSAvqIvq qKsdNFApOQWY4a/HCLMNJtmvvTN63gNCSvS4dSlG296WN5/ARyu1ylB95xLtLLzgK0jK 6cjIHcF5B5WthG76u5gfud2tSt2MfoRADV9kWrlmcyFnSgaf3sO+yeJXcHiowNwDyeqJ jMOw== 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 p7si10422504pff.118.2018.04.02.01.32.58; Mon, 02 Apr 2018 01:33:12 -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 S1754144AbeDBIby (ORCPT + 99 others); Mon, 2 Apr 2018 04:31:54 -0400 Received: from bmailout2.hostsharing.net ([83.223.90.240]:52413 "EHLO bmailout2.hostsharing.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752257AbeDBIbw (ORCPT ); Mon, 2 Apr 2018 04:31:52 -0400 Received: from h08.hostsharing.net (h08.hostsharing.net [83.223.95.28]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "*.hostsharing.net", Issuer "COMODO RSA Domain Validation Secure Server CA" (not verified)) by bmailout2.hostsharing.net (Postfix) with ESMTPS id 81FAA280161AA; Mon, 2 Apr 2018 10:31:50 +0200 (CEST) Received: by h08.hostsharing.net (Postfix, from userid 100393) id 2608C22434; Mon, 2 Apr 2018 10:31:50 +0200 (CEST) Date: Mon, 2 Apr 2018 10:31:50 +0200 From: Lukas Wunner To: Julia Lawall 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 Message-ID: <20180402083150.GA8013@wunner.de> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.23 (2014-03-12) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. 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