From: Lukas Wunner <lukas@wunner.de>
To: Julia Lawall <julia.lawall@lip6.fr>
Cc: Laura Abbott <labbott@redhat.com>,
Linus Walleij <linus.walleij@linaro.org>,
kbuild-all@01.org, Kees Cook <keescook@chromium.org>,
linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org,
kernel-hardening@lists.openwall.com,
Rasmus Villemoes <linux@rasmusvillemoes.dk>,
Andy Shevchenko <andy.shevchenko@gmail.com>
Subject: Re: [PATCH] gpio: fix ifnullfree.cocci warnings
Date: Mon, 2 Apr 2018 10:31:50 +0200 [thread overview]
Message-ID: <20180402083150.GA8013@wunner.de> (raw)
In-Reply-To: <alpine.DEB.2.20.1803300829580.2870@hadrien>
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
next prev parent reply other threads:[~2018-04-02 8:31 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-03-30 6:32 [PATCH] gpio: fix ifnullfree.cocci warnings (fwd) Julia Lawall
2018-04-02 8:31 ` Lukas Wunner [this message]
2018-04-02 9:04 ` [PATCH] gpio: fix ifnullfree.cocci warnings Julia Lawall
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20180402083150.GA8013@wunner.de \
--to=lukas@wunner.de \
--cc=andy.shevchenko@gmail.com \
--cc=julia.lawall@lip6.fr \
--cc=kbuild-all@01.org \
--cc=keescook@chromium.org \
--cc=kernel-hardening@lists.openwall.com \
--cc=labbott@redhat.com \
--cc=linus.walleij@linaro.org \
--cc=linux-gpio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@rasmusvillemoes.dk \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).