From ac55fab44d514355334e95dc18cbe5d3a3b2e0f6 Mon Sep 17 00:00:00 2001 From: Xiang Xiao Date: Mon, 27 Apr 2020 12:23:42 +0800 Subject: [PATCH] syslog: Check sc_flush in't NULL before invocation Signed-off-by: Xiang Xiao --- drivers/syslog/syslog_channel.c | 12 +----------- drivers/syslog/syslog_flush.c | 8 ++++++-- 2 files changed, 7 insertions(+), 13 deletions(-) diff --git a/drivers/syslog/syslog_channel.c b/drivers/syslog/syslog_channel.c index c731aae951..2a8fd1c838 100644 --- a/drivers/syslog/syslog_channel.c +++ b/drivers/syslog/syslog_channel.c @@ -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; diff --git a/drivers/syslog/syslog_flush.c b/drivers/syslog/syslog_flush.c index 24e6f49736..89e874f441 100644 --- a/drivers/syslog/syslog_flush.c +++ b/drivers/syslog/syslog_flush.c @@ -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); - return g_syslog_channel->sc_flush(); + if (g_syslog_channel->sc_flush != NULL) + { + return g_syslog_channel->sc_flush(); + } + + return OK; }