From nobody Mon May 25 04:33:42 2026 Received: from out-178.mta1.migadu.com (out-178.mta1.migadu.com [95.215.58.178]) (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 1AE24495519 for ; Mon, 18 May 2026 16:53:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.178 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779123223; cv=none; b=n6Xkur2TWg0fAy6Ky37k0BxxTNvBNtd2E6rCAd8vOOO3vuKDs+vYkTwPFu1e3+4lGEqihmE9sr2N1QF8v2IM6Rf3LHcvkuq9MD+uklgRDkjUwX5YNiEPJ5qsXJcnt7GWtx1jH/OX9Z4djCcxTHqBAWKo89zq5mXMwsruyBzNeVg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779123223; c=relaxed/simple; bh=WnJ4gWii6vGIYcblvWHBrztcZBFygJX95R92ZbX9gzU=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=N/bqNbskyWH+jWmDrdjZY4QKt2BseA4WNEOgADEMJ5k7brvoXaG4a04sr4dnauyjXoHYmYf+r4TDCPTCWX/n8yEF+VzS96VQS/6QVI+jaG4rCEZvdszuAit2nvnLykNH0tJX7qWd0qGRViiDYGBdUlqf/vMQ+aIP5CS21LQZFeE= 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=Rmdk40dc; arc=none smtp.client-ip=95.215.58.178 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="Rmdk40dc" 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=1779123218; 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=dTW70Khpmv4Wv56aPG+Rcr4F5EYvZo6qHkg+0Adldi0=; b=Rmdk40dc5ZaNPRkaQongReyUZboX6Q7x5ZV+6QkCCv+2zKgBu7gaw3/yaK2b6pbtPXlhHX SHQSr0g2fsR5QRlML3addZ9FiRVL5cfGtyslAvtdW6KepIbI7nx9yqnBibef/PiqOjHrQe N1Zq8Firy88d8ikzCmFEhveJ4ui7ST0= From: Thorsten Blum To: Rich Felker , John Paul Adrian Glaubitz Cc: Thorsten Blum , linux-sh@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH RESEND] sh: machvec: clean up and use strscpy in early_parse_mv Date: Mon, 18 May 2026 18:53:25 +0200 Message-ID: <20260518165326.81412-2-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=2508; i=thorsten.blum@linux.dev; h=from:subject; bh=WnJ4gWii6vGIYcblvWHBrztcZBFygJX95R92ZbX9gzU=; b=owGbwMvMwCUWt7pQ4caZUj3G02pJDFncLmxRT2V6xaeGmH9ZdovV+E7/sY2bQ4sYbz3Qnv1/q v1vaQWnjlIWBjEuBlkxRZYHs37M8C2tqdxkErETZg4rE8gQBi5OAZiIcwXDP81vH4xcHv47ocYf e+rWJTUG13kvdziYmP4wCWVsvWv2rZyRoV/y1sqp2y2n9Bz0+rzXrY5hG7e+H9+S93L5Ll4NEk/ j+QA= 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" Use strscpy() to copy the NUL-terminated early parameter to the destination buffer instead of using memcpy() followed by a manual NUL termination. If the early parameter contains a space, use min() to copy only up to that delimiter, otherwise copy the entire string. Drop the now unused mv_len variable. Remove the redundant mv_name initialization because it is immediately populated by strscpy(). Drop mv_comma, which has been unused since commit 9655ad03af2d ("sh: Fixup machvec support."), and remove the dead from =3D mv_end assignment. And since panic() is a __noreturn function, remove the else branch as well. Change machvec_selected from unsigned int to bool and move __initdata after the variable name to silence a checkpatch warning. Signed-off-by: Thorsten Blum --- arch/sh/kernel/machvec.c | 27 ++++++++++----------------- 1 file changed, 10 insertions(+), 17 deletions(-) diff --git a/arch/sh/kernel/machvec.c b/arch/sh/kernel/machvec.c index 57efaf5b82ae..d737a5a560cd 100644 --- a/arch/sh/kernel/machvec.c +++ b/arch/sh/kernel/machvec.c @@ -8,6 +8,7 @@ * Copyright (C) 2002 - 2007 Paul Mundt */ #include +#include #include #include #include @@ -35,29 +36,21 @@ static struct sh_machine_vector * __init get_mv_byname(= const char *name) return NULL; } =20 -static unsigned int __initdata machvec_selected; +static bool machvec_selected __initdata; =20 static int __init early_parse_mv(char *from) { - char mv_name[MV_NAME_SIZE] =3D ""; + char mv_name[MV_NAME_SIZE]; char *mv_end; - char *mv_comma; - int mv_len; struct sh_machine_vector *mvp; =20 mv_end =3D strchr(from, ' '); - if (mv_end =3D=3D NULL) - mv_end =3D from + strlen(from); + if (mv_end) + strscpy(mv_name, from, min(mv_end - from + 1, MV_NAME_SIZE)); + else + strscpy(mv_name, from); =20 - mv_comma =3D strchr(from, ','); - mv_len =3D mv_end - from; - if (mv_len > (MV_NAME_SIZE-1)) - mv_len =3D MV_NAME_SIZE-1; - memcpy(mv_name, from, mv_len); - mv_name[mv_len] =3D '\0'; - from =3D mv_end; - - machvec_selected =3D 1; + machvec_selected =3D true; =20 /* Boot with the generic vector */ if (strcmp(mv_name, "generic") =3D=3D 0) @@ -71,8 +64,8 @@ static int __init early_parse_mv(char *from) pr_cont("\n\n"); panic("Failed to select machvec '%s' -- halting.\n", mv_name); - } else - sh_mv =3D *mvp; + } + sh_mv =3D *mvp; =20 return 0; }