]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
lib/configs: eliminate counter variable
authorKarel Zak <kzak@redhat.com>
Wed, 15 Oct 2025 13:15:02 +0000 (15:15 +0200)
committerKarel Zak <kzak@redhat.com>
Wed, 15 Oct 2025 13:15:02 +0000 (15:15 +0200)
Remove the counter variable and return list_count_entries()
directly. This simplifies the code by calculating the count
only when needed (on success path) rather than tracking it
throughout the function.

Signed-off-by: Karel Zak <kzak@redhat.com>
lib/configs.c

index 7ecd69df656d043d6fc29d1d532794d3ead47ddf..87e17fa0cc3537568be9db6ce8742a739ef3fbc1 100644 (file)
@@ -228,7 +228,6 @@ int ul_configs_file_list(struct list_head *file_list,
        struct list_head etc_list;
        struct list_head run_list;
        struct list_head usr_list;
-       int counter = 0;
        int ret;
 
        INIT_LIST_HEAD(file_list);
@@ -295,14 +294,12 @@ int ul_configs_file_list(struct list_head *file_list,
                }
        }
 
-       counter = list_count_entries(file_list);
-
 finish:
        ul_configs_free_list(&etc_list);
        ul_configs_free_list(&run_list);
        ul_configs_free_list(&usr_list);
 
-       return counter;
+       return ret < 0 ? ret : (int) list_count_entries(file_list);
 }
 
 void ul_configs_free_list(struct list_head *file_list)