From nobody Tue Dec 16 19:58:53 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0FE88C83003 for ; Thu, 24 Aug 2023 20:13:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243481AbjHXUNO (ORCPT ); Thu, 24 Aug 2023 16:13:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44536 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243472AbjHXUM4 (ORCPT ); Thu, 24 Aug 2023 16:12:56 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A67B41BCD; Thu, 24 Aug 2023 13:12:54 -0700 (PDT) Date: Thu, 24 Aug 2023 20:12:52 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1692907973; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=oXTQ2wqGEq8Pz6yTwF/JEdPBqKNqe6nRDvBoVDyPzTQ=; b=4Z7clyBSL7da6Yggng7uxjBXzvwVfRWuPzqQyd3TlC1rz4xD2pNMQ85vPKBspx9TdyKmK3 1/vF2Zgs0Sm2Q0FO8yGpJ8OGgMJ4miSiswBvYVqG3vRFIrMavhRdNggiEPXwdDLWkUuomO +hlhAjpFkopRtK1Zs+RM9j0QtFhawsBfveqvLLTTNGEXs/yYT3dALSoMdSx2Zyu1zgYpAJ DJXbw/q+Prj5PBTOG7RHZmvrjLByLAmvswEtt+qdY/go+w5xdwDv57Uvawds9Y3g4u617c G4CrvqrKp5/B7E8hqTTrFZCae3QLtF2gS46+JrxVhY/iRqb/45bSaXvZst3j1A== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1692907973; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=oXTQ2wqGEq8Pz6yTwF/JEdPBqKNqe6nRDvBoVDyPzTQ=; b=kXd+GBrW+zDPcxYKvbwTBEl2R4cy5iP+IgLywRn3r9yS174VivPTicuDMjvLWNRuHiIFG3 jutIaJfXUdEySkAA== From: "tip-bot2 for Justin Stitt" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: x86/cleanups] x86/platform/uv: Refactor code using deprecated strncpy() interface to use strscpy() Cc: Justin Stitt , Ingo Molnar , Andy Shevchenko , Kees Cook , Dimitri Sivanich , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: =?utf-8?q?=3C20230822-strncpy-arch-x86-kernel-apic-x2apic=5Fu?= =?utf-8?q?v=5Fx-v1-1-91d681d0b3f3=40google=2Ecom=3E?= References: =?utf-8?q?=3C20230822-strncpy-arch-x86-kernel-apic-x2apic=5Fuv?= =?utf-8?q?=5Fx-v1-1-91d681d0b3f3=40google=2Ecom=3E?= MIME-Version: 1.0 Message-ID: <169290797270.27769.5277467952297102028.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The following commit has been merged into the x86/cleanups branch of tip: Commit-ID: 212f07a21622cbd4bb271b558b2d3ae0652e9875 Gitweb: https://git.kernel.org/tip/212f07a21622cbd4bb271b558b2d3ae06= 52e9875 Author: Justin Stitt AuthorDate: Tue, 22 Aug 2023 22:05:30=20 Committer: Ingo Molnar CommitterDate: Thu, 24 Aug 2023 21:22:50 +02:00 x86/platform/uv: Refactor code using deprecated strncpy() interface to use = strscpy() `strncpy` is deprecated for use on NUL-terminated destination strings [1]. A suitable replacement is `strscpy` [2] due to the fact that it guarantees NUL-termination on its destination buffer argument which is _not_ the case for `strncpy`! In this case, it means we can drop the `...-1` from: | strncpy(to, from, len-1); as well as remove the comment mentioning NUL-termination as `strscpy` implicitly grants us this behavior. There should be no functional change as I don't believe the padding from `strncpy` is needed here. If it turns out that the padding is necessary we should use `strscpy_pad` as a direct replacement. Signed-off-by: Justin Stitt Signed-off-by: Ingo Molnar Cc: Andy Shevchenko Cc: Kees Cook Cc: Dimitri Sivanich Link: www.kernel.org/doc/html/latest/process/deprecated.html#strncpy-on-nul= -terminated-strings[1] Link: https://manpages.debian.org/testing/linux-manual-4.8/strscpy.9.en.htm= l [2] Link: https://github.com/KSPP/linux/issues/90 Link: https://lore.kernel.org/r/20230822-strncpy-arch-x86-kernel-apic-x2api= c_uv_x-v1-1-91d681d0b3f3@google.com --- arch/x86/kernel/apic/x2apic_uv_x.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/arch/x86/kernel/apic/x2apic_uv_x.c b/arch/x86/kernel/apic/x2ap= ic_uv_x.c index d9384d5..b524dee 100644 --- a/arch/x86/kernel/apic/x2apic_uv_x.c +++ b/arch/x86/kernel/apic/x2apic_uv_x.c @@ -294,8 +294,7 @@ static void __init early_get_apic_socketid_shift(void) =20 static void __init uv_stringify(int len, char *to, char *from) { - /* Relies on 'to' being NULL chars so result will be NULL terminated */ - strncpy(to, from, len-1); + strscpy(to, from, len); =20 /* Trim trailing spaces */ (void)strim(to); @@ -1013,7 +1012,7 @@ static void __init calc_mmioh_map(enum mmioh_arch ind= ex, =20 /* One (UV2) mapping */ if (index =3D=3D UV2_MMIOH) { - strncpy(id, "MMIOH", sizeof(id)); + strscpy(id, "MMIOH", sizeof(id)); max_io =3D max_pnode; mapped =3D 0; goto map_exit;