From nobody Thu Dec 18 05:58:34 2025 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6088B1D86CF for ; Wed, 4 Sep 2024 12:05:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725451545; cv=none; b=O6GrJ9JknICNOwQOMReK53Et5qpghqPcCFZkfF+H1b5VTnOxGOnvXUzozDbWmdrQ8iOe9mX4chTtb0Bfo+V6solXztFEjOTafUoQPJdOzoqHny5P9crD+THSJmwByqaLlJFxaHo0ybMWHy+KnTsndg/pSZefrVuWkgmGlT2mi1g= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725451545; c=relaxed/simple; bh=sHSHHeqiwQ9YyiIBcZ7gPm0V0NpoQnvRWx5JDy8B2H0=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=WYApT7OzpZx/7XE96Xs3jMezJEZnFcOpFKi99PkhcGRrt4AmrVSgSixg+VQcWddxbfl5JZ2bjPx+Pbc/eFUfy2jNihsFgGX+1Ojfq57DlXWHjnyhmPetibar6gE0xWwjt5wDCbw0QWrllJt2+fvB3m5aA+1loDjz5zVRKv2kogQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=BultgAMM; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=pXTNSqSa; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="BultgAMM"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="pXTNSqSa" From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1725451540; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=4pssUMyVvmFvYT06a6ZnerXY0wPX0oasx1ORdEmVcAU=; b=BultgAMMSDtG/p5udzH+AbLKlbKZPgtMAeCarhNn/XybqLBRHuO0v+O4+h9ifkFWok7+Nz iL+kz/ix5VPkTvZOJ6IkJZaOc4ug/d257cvdHYxlC8oMqFdeXWhiQNth1RkvqoO2hE/0zO VJzTlEu5T+H9BDcenKxtJoHseOccDfIhllAy89FdNh2+XL1xWR/v/20JHTHMqpOyWM+1UX LoimD87ZSrsX+P5YeokIzRF4PpJPDZaSmwh+/5GwnwBBc0liJBHYIXakveyYxxOm+wnjmJ D5hchbA67GFkN6ApFtXUP5TOi10wWouWv4cUp4m3lwsMuAbRlluE+1AIA3GYjA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1725451540; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=4pssUMyVvmFvYT06a6ZnerXY0wPX0oasx1ORdEmVcAU=; b=pXTNSqSa63MLJbQj+lCn92h2c5UgtHTN211wpm8CDVxJ1DtSbL8zTJsXrahRe9XDhEs9C3 cTRgbnG3ae6rv5Cw== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org Subject: [PATCH printk v6 10/17] printk: Provide helper for message prepending Date: Wed, 4 Sep 2024 14:11:29 +0206 Message-Id: <20240904120536.115780-11-john.ogness@linutronix.de> In-Reply-To: <20240904120536.115780-1-john.ogness@linutronix.de> References: <20240904120536.115780-1-john.ogness@linutronix.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" In order to support prepending different texts to printk messages, split out the prepending code into a helper function. Signed-off-by: John Ogness Reviewed-by: Petr Mladek --- kernel/printk/printk.c | 36 +++++++++++++++++++++++++----------- 1 file changed, 25 insertions(+), 11 deletions(-) diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c index 149c3e04c2b5..e9458569bcfd 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -2843,30 +2843,31 @@ static void __console_unlock(void) #ifdef CONFIG_PRINTK =20 /* - * Prepend the message in @pmsg->pbufs->outbuf with a "dropped message". T= his - * is achieved by shifting the existing message over and inserting the dro= pped - * message. + * Prepend the message in @pmsg->pbufs->outbuf. This is achieved by shifti= ng + * the existing message over and inserting the scratchbuf message. * - * @pmsg is the printk message to prepend. - * - * @dropped is the dropped count to report in the dropped message. + * @pmsg is the original printk message. + * @fmt is the printf format of the message which will prepend the existin= g one. * - * If the message text in @pmsg->pbufs->outbuf does not have enough space = for - * the dropped message, the message text will be sufficiently truncated. + * If there is not enough space in @pmsg->pbufs->outbuf, the existing + * message text will be sufficiently truncated. * * If @pmsg->pbufs->outbuf is modified, @pmsg->outbuf_len is updated. */ -void console_prepend_dropped(struct printk_message *pmsg, unsigned long dr= opped) +__printf(2, 3) +static void console_prepend_message(struct printk_message *pmsg, const cha= r *fmt, ...) { struct printk_buffers *pbufs =3D pmsg->pbufs; const size_t scratchbuf_sz =3D sizeof(pbufs->scratchbuf); const size_t outbuf_sz =3D sizeof(pbufs->outbuf); char *scratchbuf =3D &pbufs->scratchbuf[0]; char *outbuf =3D &pbufs->outbuf[0]; + va_list args; size_t len; =20 - len =3D scnprintf(scratchbuf, scratchbuf_sz, - "** %lu printk messages dropped **\n", dropped); + va_start(args, fmt); + len =3D vscnprintf(scratchbuf, scratchbuf_sz, fmt, args); + va_end(args); =20 /* * Make sure outbuf is sufficiently large before prepending. @@ -2888,6 +2889,19 @@ void console_prepend_dropped(struct printk_message *= pmsg, unsigned long dropped) pmsg->outbuf_len +=3D len; } =20 +/* + * Prepend the message in @pmsg->pbufs->outbuf with a "dropped message". + * @pmsg->outbuf_len is updated appropriately. + * + * @pmsg is the printk message to prepend. + * + * @dropped is the dropped count to report in the dropped message. + */ +void console_prepend_dropped(struct printk_message *pmsg, unsigned long dr= opped) +{ + console_prepend_message(pmsg, "** %lu printk messages dropped **\n", drop= ped); +} + /* * Read and format the specified record (or a later record if the specified * record is not available). --=20 2.39.2