]> git.ipfire.org Git - thirdparty/kmod.git/commitdiff
libkmod: use strstartswith() over memcmp()
authorEmil Velikov <emil.l.velikov@gmail.com>
Sat, 24 May 2025 11:33:36 +0000 (12:33 +0100)
committerLucas De Marchi <lucas.de.marchi@gmail.com>
Thu, 29 May 2025 22:10:16 +0000 (17:10 -0500)
In the cases where we have a string literal, we can use our helper
without adding performance overhead.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/354
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
libkmod/libkmod-config.c
libkmod/libkmod-signature.c

index 38b162d5f284b4832542f1f195fed948dee0fb4a..9ca9d2f2b0476add7e56c69f6df7e52b613292b6 100644 (file)
@@ -267,10 +267,9 @@ static int kmod_config_add_softdep(struct kmod_config *config, const char *modna
                }
                plen = s - p;
 
-               if (plen == strlen("pre:") && memcmp(p, "pre:", strlen("pre:")) == 0)
+               if (plen == strlen("pre:") && strstartswith(p, "pre:"))
                        mode = S_PRE;
-               else if (plen == strlen("post:") &&
-                        memcmp(p, "post:", strlen("post:")) == 0)
+               else if (plen == strlen("post:") && strstartswith(p, "post:"))
                        mode = S_POST;
                else if (*s != '\0' || (*s == '\0' && !was_space)) {
                        if (mode == S_PRE) {
@@ -351,10 +350,9 @@ static int kmod_config_add_softdep(struct kmod_config *config, const char *modna
                }
                plen = s - p;
 
-               if (plen == strlen("pre:") && memcmp(p, "pre:", strlen("pre:")) == 0)
+               if (plen == strlen("pre:") && strstartswith(p, "pre:"))
                        mode = S_PRE;
-               else if (plen == strlen("post:") &&
-                        memcmp(p, "post:", strlen("post:")) == 0)
+               else if (plen == strlen("post:") && strstartswith(p, "post:"))
                        mode = S_POST;
                else if (*s != '\0' || (*s == '\0' && !was_space)) {
                        if (mode == S_PRE) {
index 4f5023edb993023e55116f7ee6987630bd96140e..2cb67f6efbbfb300580dfea134330f5dd32de52a 100644 (file)
@@ -314,7 +314,7 @@ bool kmod_module_signature_info(const struct kmod_file *file,
        if (size < (off_t)strlen(SIG_MAGIC))
                return false;
        size -= strlen(SIG_MAGIC);
-       if (memcmp(SIG_MAGIC, mem + size, strlen(SIG_MAGIC)) != 0)
+       if (!strstartswith(mem + size, SIG_MAGIC))
                return false;
 
        if (size < (off_t)sizeof(struct module_signature))