Commit eaf35bc6 authored by Breno Leitao's avatar Breno Leitao Committed by Jakub Kicinski
Browse files

netconsole: extract message fragmentation into send_msg_udp()



Extract the message fragmentation logic from write_msg() into a
dedicated send_msg_udp() function. This improves code readability
and prepares for future enhancements.

The new send_msg_udp() function handles splitting messages that
exceed MAX_PRINT_CHUNK into smaller fragments and sending them
sequentially. This function is placed before send_ext_msg_udp()
to maintain a logical ordering of related functions.

No functional changes - this is purely a refactoring commit.

Reviewed-by: default avatarPetr Mladek <pmladek@suse.com>
Reviewed-by: default avatarSimon Horman <horms@kernel.org>
Reviewed-by: default avatarJohn Ogness <john.ogness@linutronix.de>
Signed-off-by: default avatarBreno Leitao <leitao@debian.org>
Link: https://patch.msgid.link/20260206-nbcon-v7-2-62bda69b1b41@debian.org


Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
parent 60325c27
Loading
Loading
Loading
Loading
+15 −9
Original line number Diff line number Diff line
@@ -1876,12 +1876,24 @@ static void write_ext_msg(struct console *con, const char *msg,
	spin_unlock_irqrestore(&target_list_lock, flags);
}

static void send_msg_udp(struct netconsole_target *nt, const char *msg,
			 unsigned int len)
{
	const char *tmp = msg;
	int frag, left = len;

	while (left > 0) {
		frag = min(left, MAX_PRINT_CHUNK);
		send_udp(nt, tmp, frag);
		tmp += frag;
		left -= frag;
	}
}

static void write_msg(struct console *con, const char *msg, unsigned int len)
{
	int frag, left;
	unsigned long flags;
	struct netconsole_target *nt;
	const char *tmp;

	if (oops_only && !oops_in_progress)
		return;
@@ -1899,13 +1911,7 @@ static void write_msg(struct console *con, const char *msg, unsigned int len)
			 * at least one target if we die inside here, instead
			 * of unnecessarily keeping all targets in lock-step.
			 */
			tmp = msg;
			for (left = len; left;) {
				frag = min(left, MAX_PRINT_CHUNK);
				send_udp(nt, tmp, frag);
				tmp += frag;
				left -= frag;
			}
			send_msg_udp(nt, msg, len);
		}
	}
	spin_unlock_irqrestore(&target_list_lock, flags);