syslog: Check sc_flush in't NULL before invocation

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
This commit is contained in:
Xiang Xiao 2020-04-27 12:23:42 +08:00 committed by patacongo
parent 67b10fea09
commit ac55fab44d
2 changed files with 7 additions and 13 deletions

View File

@ -72,7 +72,6 @@
#ifdef NEED_LOWPUTC
static int syslog_default_putc(int ch);
#endif
static int syslog_default_flush(void);
/****************************************************************************
* Public Data
@ -83,7 +82,6 @@ static const struct syslog_channel_s g_default_channel =
{
ramlog_putc,
ramlog_putc,
syslog_default_flush
};
#elif defined(CONFIG_SYSLOG_RPMSG)
static const struct syslog_channel_s g_default_channel =
@ -98,14 +96,12 @@ static const struct syslog_channel_s g_default_channel =
{
up_putc,
up_putc,
syslog_default_flush
};
#else
static const struct syslog_channel_s g_default_channel =
{
syslog_default_putc,
syslog_default_putc,
syslog_default_flush
};
#endif
@ -132,11 +128,6 @@ static int syslog_default_putc(int ch)
}
#endif
static int syslog_default_flush(void)
{
return OK;
}
/****************************************************************************
* Public Functions
****************************************************************************/
@ -163,8 +154,7 @@ int syslog_channel(FAR const struct syslog_channel_s *channel)
if (channel != NULL)
{
DEBUGASSERT(channel->sc_putc != NULL && channel->sc_force != NULL &&
channel->sc_flush != NULL);
DEBUGASSERT(channel->sc_putc != NULL && channel->sc_force != NULL);
g_syslog_channel = channel;
return OK;

View File

@ -91,6 +91,10 @@ int syslog_flush(void)
/* Then flush all of the buffered output to the SYSLOG device */
DEBUGASSERT(g_syslog_channel->sc_flush != NULL);
if (g_syslog_channel->sc_flush != NULL)
{
return g_syslog_channel->sc_flush();
}
return OK;
}