]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
net: netconsole: Eliminate redundant setting of enabled field
authorBreno Leitao <leitao@debian.org>
Tue, 9 Jul 2024 14:44:00 +0000 (07:44 -0700)
committerJakub Kicinski <kuba@kernel.org>
Fri, 12 Jul 2024 01:32:48 +0000 (18:32 -0700)
When disabling a netconsole target, enabled_store() is called with
enabled=false. Currently, this results in updating the nt->enabled
field twice:

1. Inside the if/else block, with the target_list_lock spinlock held
2. Later, without the target_list_lock

This patch eliminates the redundancy by setting the field only once,
improving efficiency and reducing potential race conditions.

Signed-off-by: Breno Leitao <leitao@debian.org>
Link: https://patch.msgid.link/20240709144403.544099-3-leitao@debian.org
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
drivers/net/netconsole.c

index de0d89e4e4e2a47fbce6e40b40b1a018d7d7a313..5ef680cf994a0c10f23295d8b72aa7edf149a45a 100644 (file)
@@ -369,6 +369,7 @@ static ssize_t enabled_store(struct config_item *item,
                if (err)
                        goto out_unlock;
 
+               nt->enabled = true;
                pr_info("network logging started\n");
        } else {        /* false */
                /* We need to disable the netconsole before cleaning it up
@@ -381,8 +382,6 @@ static ssize_t enabled_store(struct config_item *item,
                netpoll_cleanup(&nt->np);
        }
 
-       nt->enabled = enabled;
-
        mutex_unlock(&dynamic_netconsole_mutex);
        return strnlen(buf, count);
 out_unlock: