[PATCH] net: bridge: avoid redundant strlen() in show_backup_port()

From
Dmitry Antipov <hidden>
Date
2026-11-17 16:51:21
Also in
bridge
In store_backup_port(), prefer strchrnul() over strchr() to
avoid redundant call to strlen().

Signed-off-by: Dmitry Antipov <redacted>
---
 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;
-- 
2.56.1
Thread (4 messages) 4 messages, 4 authors, last reply 3d ago
Keyboard shortcuts
hback out one level
jnext message in thread / next series-diff position
kprevious message in thread / previous series-diff position
ldrill in
Escclose help / fold thread tree
?toggle this help