All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/1] log: mute messages generated by log drivers
@ 2020-09-14  8:01 Heinrich Schuchardt
  2020-09-17  1:10 ` Simon Glass
  2020-09-27  1:59 ` Simon Glass
  0 siblings, 2 replies; 3+ messages in thread
From: Heinrich Schuchardt @ 2020-09-14  8:01 UTC (permalink / raw)
  To: u-boot

When a message is written by a log driver (e.g. via the network stack) this
may result in the generation of further messages. We cannot allow these
additional messages to be emitted as this might result in an infinite
recursion.

Up to now only the syslog driver was safeguarded. We should safeguard all
log drivers instead.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
---
 common/log.c        | 13 ++++++++++++-
 common/log_syslog.c |  8 --------
 2 files changed, 12 insertions(+), 9 deletions(-)

diff --git a/common/log.c b/common/log.c
index 734d26de4a..9a5f100da3 100644
--- a/common/log.c
+++ b/common/log.c
@@ -191,12 +191,23 @@ static bool log_passes_filters(struct log_device *ldev, struct log_rec *rec)
 static int log_dispatch(struct log_rec *rec)
 {
 	struct log_device *ldev;
+	static int processing_msg;

+	/*
+	 * When a log driver writes messages (e.g. via the network stack) this
+	 * may result in further generated messages. We cannot process them here
+	 * as this might result in infinite recursion.
+	 */
+	if (processing_msg)
+		return 0;
+
+	/* Emit message */
+	processing_msg = 1;
 	list_for_each_entry(ldev, &gd->log_head, sibling_node) {
 		if (log_passes_filters(ldev, rec))
 			ldev->drv->emit(ldev, rec);
 	}
-
+	processing_msg = 0;
 	return 0;
 }

diff --git a/common/log_syslog.c b/common/log_syslog.c
index 149ff5af31..2ae703fed7 100644
--- a/common/log_syslog.c
+++ b/common/log_syslog.c
@@ -35,16 +35,9 @@ static int log_syslog_emit(struct log_device *ldev, struct log_rec *rec)
 	char *log_msg;
 	int eth_hdr_size;
 	struct in_addr bcast_ip;
-	static int processing_msg;
 	unsigned int log_level;
 	char *log_hostname;

-	/* Fend off messages from the network stack while writing a message */
-	if (processing_msg)
-		return 0;
-
-	processing_msg = 1;
-
 	/* Setup packet buffers */
 	net_init();
 	/* Disable hardware and put it into the reset state */
@@ -108,7 +101,6 @@ static int log_syslog_emit(struct log_device *ldev, struct log_rec *rec)
 	net_send_packet((uchar *)msg, ptr - msg);

 out:
-	processing_msg = 0;
 	return ret;
 }

--
2.28.0

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [PATCH 1/1] log: mute messages generated by log drivers
  2020-09-14  8:01 [PATCH 1/1] log: mute messages generated by log drivers Heinrich Schuchardt
@ 2020-09-17  1:10 ` Simon Glass
  2020-09-27  1:59 ` Simon Glass
  1 sibling, 0 replies; 3+ messages in thread
From: Simon Glass @ 2020-09-17  1:10 UTC (permalink / raw)
  To: u-boot

On Mon, 14 Sep 2020 at 02:01, Heinrich Schuchardt <xypron.glpk@gmx.de> wrote:
>
> When a message is written by a log driver (e.g. via the network stack) this
> may result in the generation of further messages. We cannot allow these
> additional messages to be emitted as this might result in an infinite
> recursion.
>
> Up to now only the syslog driver was safeguarded. We should safeguard all
> log drivers instead.
>
> Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
> ---
>  common/log.c        | 13 ++++++++++++-
>  common/log_syslog.c |  8 --------
>  2 files changed, 12 insertions(+), 9 deletions(-)

Reviewed-by: Simon Glass <sjg@chromium.org>

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH 1/1] log: mute messages generated by log drivers
  2020-09-14  8:01 [PATCH 1/1] log: mute messages generated by log drivers Heinrich Schuchardt
  2020-09-17  1:10 ` Simon Glass
@ 2020-09-27  1:59 ` Simon Glass
  1 sibling, 0 replies; 3+ messages in thread
From: Simon Glass @ 2020-09-27  1:59 UTC (permalink / raw)
  To: u-boot

On Mon, 14 Sep 2020 at 02:01, Heinrich Schuchardt <xypron.glpk@gmx.de> wrote:
>
> When a message is written by a log driver (e.g. via the network stack) this
> may result in the generation of further messages. We cannot allow these
> additional messages to be emitted as this might result in an infinite
> recursion.
>
> Up to now only the syslog driver was safeguarded. We should safeguard all
> log drivers instead.
>
> Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
> ---
>  common/log.c        | 13 ++++++++++++-
>  common/log_syslog.c |  8 --------
>  2 files changed, 12 insertions(+), 9 deletions(-)

Reviewed-by: Simon Glass <sjg@chromium.org>

Applied to u-boot-dm/next, thanks!

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2020-09-27  1:59 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-09-14  8:01 [PATCH 1/1] log: mute messages generated by log drivers Heinrich Schuchardt
2020-09-17  1:10 ` Simon Glass
2020-09-27  1:59 ` Simon Glass

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.