From nobody Mon Jun 8 19:46:39 2026 Received: from out-170.mta0.migadu.com (out-170.mta0.migadu.com [91.218.175.170]) (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 DC99121D590 for ; Wed, 27 May 2026 00:02:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.170 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779840128; cv=none; b=rsa4Xxh3T3+ele6ExKkpDEBYI/qSTDcEFfN05zKvhRckJZ15Nxjx83rbLJHzhPbCNOkFeQanoUK8uwCAd2rUZ4n4idoIR0Gt014FT+fJcSlWmcL/a/vp37PLuZbhOyp1VhHrA1MO5wxnE0FaTAuEM1pi6fYOvn7G0lt7XNsWD84= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779840128; c=relaxed/simple; bh=nd5yPR8MeFvqegyDZWdCPUoqwQ5AW3bnIbMhUoTcHU4=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=ulAybhkZt/ZKxv2XsGFgTw/6eLN80qSl5VtdthBf92LPp3gnKy2qXaBTNKikPcJgQMzQuEpwy53LhXUh6ic2DrK0/h9z9+dvqIGuu7u8e+AZeMG/A6BQ+Uri1LTqnGwnc1rXrIcLTYVqm91lYLMLBmRX/QPxmeeuDvC0NpSmras= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=aiDVxuzl; arc=none smtp.client-ip=91.218.175.170 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="aiDVxuzl" X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1779840115; 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; bh=/mUNYVbQO7WzMBWFoPK4p8GJoNAcMMtkwfQmm2mOiPc=; b=aiDVxuzl6xKnDyhylyilTBRa4eKJJuAAspqZ1pYorXNyi3Is14v7Nc1tfCbSQMT+44oOVT E21FZmqM92RYCQriQAlXtxgLflm433Nh3tOiyBIUinAwnUqHV48efb9wrNOPUD7yne0Wwf 7NKdMrqxKZnGSNodudsmCPyV9Mgi3eo= From: Thorsten Blum To: Madhavan Srinivasan , Michael Ellerman , Nicholas Piggin , "Christophe Leroy (CS GROUP)" Cc: Thorsten Blum , linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org Subject: [PATCH] powerpc/kexec_file: use snprintf to simplify setup_kdump_cmdline Date: Wed, 27 May 2026 02:01:06 +0200 Message-ID: <20260527000105.1081651-3-thorsten.blum@linux.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=1702; i=thorsten.blum@linux.dev; h=from:subject; bh=nd5yPR8MeFvqegyDZWdCPUoqwQ5AW3bnIbMhUoTcHU4=; b=owGbwMvMwCUWt7pQ4caZUj3G02pJDFliJo5vHnEJ3FidsGN3RNvaLLWtXdHdvm/fpszq6Yp8x Z2r8NOmo5SFQYyLQVZMkeXBrB8zfEtrKjeZROyEmcPKBDKEgYtTACZyt4Xhf8ivSyx72sMX3Ig9 6/jsQ63QrDz1vwmTKk02VySGv/xoGMjwi+m1+Q6m36v8uSem1Z04/euj60L/A8mtX9WXhpYYSZZ r8QMA X-Developer-Key: i=thorsten.blum@linux.dev; a=openpgp; fpr=1D60735E8AEF3BE473B69D84733678FD8DFEEAD4 Content-Transfer-Encoding: quoted-printable X-Migadu-Flow: FLOW_OUT Content-Type: text/plain; charset="utf-8" Replace the manual string length accounting, memcpy(), and NUL termination with a single snprintf() call to prepend the elfcorehdr=3D address and to detect string truncation at the same time. Use kmalloc() to avoid unnecessarily zeroing the memory. While at it, also use "prepending" instead of "appending" in the error message. Signed-off-by: Thorsten Blum --- arch/powerpc/kexec/file_load.c | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/arch/powerpc/kexec/file_load.c b/arch/powerpc/kexec/file_load.c index 4284f76cbef5..597998235136 100644 --- a/arch/powerpc/kexec/file_load.c +++ b/arch/powerpc/kexec/file_load.c @@ -36,25 +36,19 @@ char *setup_kdump_cmdline(struct kimage *image, char *cmdline, unsigned long cmdline_len) { - int elfcorehdr_strlen; char *cmdline_ptr; =20 - cmdline_ptr =3D kzalloc(COMMAND_LINE_SIZE, GFP_KERNEL); + cmdline_ptr =3D kmalloc(COMMAND_LINE_SIZE, GFP_KERNEL); if (!cmdline_ptr) return NULL; =20 - elfcorehdr_strlen =3D sprintf(cmdline_ptr, "elfcorehdr=3D0x%lx ", - image->elf_load_addr); - - if (elfcorehdr_strlen + cmdline_len > COMMAND_LINE_SIZE) { - pr_err("Appending elfcorehdr=3D exceeds cmdline size\n"); + if (snprintf(cmdline_ptr, COMMAND_LINE_SIZE, "elfcorehdr=3D0x%lx %s", + image->elf_load_addr, cmdline_len ? cmdline : "") >=3D COMMAND_LINE= _SIZE) { + pr_err("Prepending elfcorehdr=3D exceeds cmdline size\n"); kfree(cmdline_ptr); return NULL; } =20 - memcpy(cmdline_ptr + elfcorehdr_strlen, cmdline, cmdline_len); - // Ensure it's nul terminated - cmdline_ptr[COMMAND_LINE_SIZE - 1] =3D '\0'; return cmdline_ptr; }