summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLucas De Marchi <lucas.demarchi@intel.com>2014-10-09 00:01:45 -0300
committerLucas De Marchi <lucas.demarchi@intel.com>2014-10-09 01:26:39 -0300
commit66bf1a7ff94829d152f146180962bfb079d4561e (patch)
treec3273a4b21da5bb226cf91b2e62b351fa380b93e
parentb95506ff6141aa65a46eef80fa0f0b06f9896712 (diff)
downloadkmod-66bf1a7ff94829d152f146180962bfb079d4561e.tar.gz
Do not rely on prio_to_str() being always inline
This function was declared as always-inline so there was not really a problem in returning prioname, that could possibly point to the local buf[] variable. However static analysis tools are often confused about this and being always-inline was just a workaround to make it work. So, let's move the buffer to the caller. We have only 2 callers so it doesn't matter much. This always reduce the size of log.o, since now the function is not inlined anymore. Below is the size for "-g -O2" with gcc: before: text data bss dec hex filename 1325 4 1 1330 532 tools/log.o after: text data bss dec hex filename 1171 4 1 1176 498 tools/log.o
-rw-r--r--tools/log.c15
1 files changed, 10 insertions, 5 deletions
diff --git a/tools/log.c b/tools/log.c
index 05ff96f..4ae4aed 100644
--- a/tools/log.c
+++ b/tools/log.c
@@ -26,13 +26,14 @@
#include "kmod.h"
+#define PRIO_MAX_SIZE 32
+
static bool log_use_syslog;
static int log_priority = LOG_ERR;
-static _always_inline_ const char *prio_to_str(int prio)
+static const char *prio_to_str(char buf[static PRIO_MAX_SIZE], int prio)
{
const char *prioname;
- char buf[32];
switch (prio) {
case LOG_CRIT:
@@ -54,7 +55,7 @@ static _always_inline_ const char *prio_to_str(int prio)
prioname = "DEBUG";
break;
default:
- snprintf(buf, sizeof(buf), "LOG-%03d", prio);
+ snprintf(buf, PRIO_MAX_SIZE, "LOG-%03d", prio);
prioname = buf;
}
@@ -65,9 +66,12 @@ _printf_format_(6, 0)
static void log_kmod(void *data, int priority, const char *file, int line,
const char *fn, const char *format, va_list args)
{
- const char *prioname = prio_to_str(priority);
+ char buf[PRIO_MAX_SIZE];
+ const char *prioname;
char *str;
+ prioname = prio_to_str(buf, priority);
+
if (vasprintf(&str, format, args) < 0)
return;
@@ -108,6 +112,7 @@ void log_close(void)
void log_printf(int prio, const char *fmt, ...)
{
+ char buf[PRIO_MAX_SIZE];
const char *prioname;
char *msg;
va_list args;
@@ -122,7 +127,7 @@ void log_printf(int prio, const char *fmt, ...)
if (msg == NULL)
return;
- prioname = prio_to_str(prio);
+ prioname = prio_to_str(buf, prio);
if (log_use_syslog)
syslog(prio, "%s: %s", prioname, msg);