modpost: rename merror() to error()
authorMasahiro Yamada <masahiroy@kernel.org>
Tue, 1 Dec 2020 10:34:14 +0000 (19:34 +0900)
committerMasahiro Yamada <masahiroy@kernel.org>
Mon, 21 Dec 2020 04:57:08 +0000 (13:57 +0900)
The log function names, warn(), merror(), fatal() are inconsistent.

Commit 2a11665945d5 ("kbuild: distinguish between errors and warnings
in modpost") intentionally chose merror() to avoid the conflict with
the library function error(). See man page of error(3).

But, we are already causing the conflict with warn() because it is also
a library function. See man page of warn(3). err() would be a problem
for the same reason.

The common technique to work around name conflicts is to use macros.
For example:

    /* in a header */
    #define error(fmt, ...)  __error(fmt, ##__VA_ARGS__)
    #define warn(fmt, ...)   __warn(fmt, ##__VA_ARGS__)

    /* function definition */
    void __error(const char *fmt, ...)
    {
            <our implementation>
    }

    void __warn(const char *fmt, ...)
    {
            <our implementation>
    }

In this way, we can implement our own warn() and error(), still we can
include <error.h> and <err.h> with no problem.

And, commit 93c95e526a4e ("modpost: rework and consolidate logging
interface") already did that.

Since the log functions are all macros, we can use error() without
causing "conflicting types" errors.

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
scripts/mod/modpost.c
scripts/mod/modpost.h

index f882ce0..337f6ca 100644 (file)
@@ -403,8 +403,8 @@ static void sym_update_namespace(const char *symname, const char *namespace)
         * actually an assertion.
         */
        if (!s) {
         * actually an assertion.
         */
        if (!s) {
-               merror("Could not update namespace(%s) for symbol %s\n",
-                      namespace, symname);
+               error("Could not update namespace(%s) for symbol %s\n",
+                     namespace, symname);
                return;
        }
 
                return;
        }
 
@@ -2226,7 +2226,7 @@ static int check_modname_len(struct module *mod)
        else
                mod_name++;
        if (strlen(mod_name) >= MODULE_NAME_LEN) {
        else
                mod_name++;
        if (strlen(mod_name) >= MODULE_NAME_LEN) {
-               merror("module name is too long [%s.ko]\n", mod->name);
+               error("module name is too long [%s.ko]\n", mod->name);
                return 1;
        }
 
                return 1;
        }
 
@@ -2319,8 +2319,8 @@ static int add_versions(struct buffer *b, struct module *mod)
                        continue;
                }
                if (strlen(s->name) >= MODULE_NAME_LEN) {
                        continue;
                }
                if (strlen(s->name) >= MODULE_NAME_LEN) {
-                       merror("too long symbol \"%s\" [%s.ko]\n",
-                              s->name, mod->name);
+                       error("too long symbol \"%s\" [%s.ko]\n",
+                             s->name, mod->name);
                        err = 1;
                        break;
                }
                        err = 1;
                        break;
                }
index 3aa0527..f453504 100644 (file)
@@ -202,5 +202,5 @@ enum loglevel {
 void modpost_log(enum loglevel loglevel, const char *fmt, ...);
 
 #define warn(fmt, args...)     modpost_log(LOG_WARN, fmt, ##args)
 void modpost_log(enum loglevel loglevel, const char *fmt, ...);
 
 #define warn(fmt, args...)     modpost_log(LOG_WARN, fmt, ##args)
-#define merror(fmt, args...)   modpost_log(LOG_ERROR, fmt, ##args)
+#define error(fmt, args...)    modpost_log(LOG_ERROR, fmt, ##args)
 #define fatal(fmt, args...)    modpost_log(LOG_FATAL, fmt, ##args)
 #define fatal(fmt, args...)    modpost_log(LOG_FATAL, fmt, ##args)