From: David Laight <david.laight.linux@gmail.com>
To: Dmitry Antipov <dmantipov@yandex.ru>
Cc: Nikolay Aleksandrov <razor@blackwall.org>,
Ido Schimmel <idosch@nvidia.com>,
bridge@lists.linux.dev, netdev@vger.kernel.org
Subject: Re: [PATCH] net: bridge: avoid redundant strlen() in show_backup_port()
Date: Wed, 18 Nov 2026 10:19:57 +0000 [thread overview]
Message-ID: <20261118101957.29ffcfd6@pumpkin> (raw)
In-Reply-To: <20261117165106.635733-1-dmantipov@yandex.ru>
On Tue, 17 Nov 2026 19:51:06 +0300
Dmitry Antipov <dmantipov@yandex.ru> wrote:
> In store_backup_port(), prefer strchrnul() over strchr() to
> avoid redundant call to strlen().
For most architectures I think the compiler optimises that strlen()
to a check of buf[0].
So you don't get the function call at all.
David
>
> Signed-off-by: Dmitry Antipov <dmantipov@yandex.ru>
> ---
> net/bridge/br_sysfs_if.c | 6 +++---
> 1 file changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/net/bridge/br_sysfs_if.c b/net/bridge/br_sysfs_if.c
> index 621d62a063d9..03205b3f465f 100644
> --- a/net/bridge/br_sysfs_if.c
> +++ b/net/bridge/br_sysfs_if.c
> @@ -231,12 +231,12 @@ static ssize_t show_backup_port(struct net_bridge_port *p, char *buf)
> static int store_backup_port(struct net_bridge_port *p, char *buf)
> {
> struct net_device *backup_dev = NULL;
> - char *nl = strchr(buf, '\n');
> + char *nl = strchrnul(buf, '\n');
>
> - if (nl)
> + if (*nl != '\0')
> *nl = '\0';
>
> - if (strlen(buf) > 0) {
> + if (nl - buf > 0) {
> backup_dev = __dev_get_by_name(dev_net(p->dev), buf);
> if (!backup_dev)
> return -ENOENT;
prev parent reply other threads:[~2026-11-18 10:20 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-17 16:51 [PATCH] net: bridge: avoid redundant strlen() in show_backup_port() Dmitry Antipov
2026-11-17 17:49 ` Joe Damato
2026-11-17 17:56 ` Ido Schimmel
2026-11-18 10:19 ` David Laight [this message]
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=20261118101957.29ffcfd6@pumpkin \
--to=david.laight.linux@gmail.com \
--cc=bridge@lists.linux.dev \
--cc=dmantipov@yandex.ru \
--cc=idosch@nvidia.com \
--cc=netdev@vger.kernel.org \
--cc=razor@blackwall.org \
/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