From nobody Thu Sep 18 07:19:06 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 75A5BC10F1B for ; Fri, 9 Dec 2022 07:35:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229482AbiLIHfD (ORCPT ); Fri, 9 Dec 2022 02:35:03 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41242 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229550AbiLIHfA (ORCPT ); Fri, 9 Dec 2022 02:35:00 -0500 Received: from mxhk.zte.com.cn (mxhk.zte.com.cn [63.216.63.40]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 51BBA195; Thu, 8 Dec 2022 23:34:59 -0800 (PST) Received: from mse-fl1.zte.com.cn (unknown [10.5.228.132]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mxhk.zte.com.cn (FangMail) with ESMTPS id 4NT2q60Hj0z8R039; Fri, 9 Dec 2022 15:34:58 +0800 (CST) Received: from szxlzmapp07.zte.com.cn ([10.5.230.251]) by mse-fl1.zte.com.cn with SMTP id 2B97Yk6Y033797; Fri, 9 Dec 2022 15:34:46 +0800 (+08) (envelope-from yang.yang29@zte.com.cn) Received: from mapi (szxlzmapp04[null]) by mapi (Zmail) with MAPI id mid14; Fri, 9 Dec 2022 15:34:49 +0800 (CST) Date: Fri, 9 Dec 2022 15:34:49 +0800 (CST) X-Zmail-TransId: 2b066392e519360cae99 X-Mailer: Zmail v1.0 Message-ID: <202212091534493764895@zte.com.cn> Mime-Version: 1.0 From: To: Cc: , , , , , , , , , Subject: =?UTF-8?B?W1BBVENIIG5ldC1uZXh0IHYyXSBsaXF1aWRpbzogdXNlIHN0cnNjcHkoKSB0byBpbnN0ZWFkIG9mIHN0cm5jcHkoKQ==?= X-MAIL: mse-fl1.zte.com.cn 2B97Yk6Y033797 X-Fangmail-Gw-Spam-Type: 0 X-FangMail-Miltered: at cgslv5.04-192.168.250.137.novalocal with ID 6392E522.000 by FangMail milter! X-FangMail-Envelope: 1670571298/4NT2q60Hj0z8R039/6392E522.000/10.5.228.132/[10.5.228.132]/mse-fl1.zte.com.cn/ X-Fangmail-Anti-Spam-Filtered: true X-Fangmail-MID-QID: 6392E522.000/4NT2q60Hj0z8R039 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Xu Panda The implementation of strscpy() is more robust and safer. That's now the recommended way to copy NUL terminated strings. Signed-off-by: Xu Panda Signed-off-by: Yang Yang Reviewed-by: Jiri Pirko --- change for v2 - change the subject, replace linux-next with net-next. --- drivers/net/ethernet/cavium/liquidio/octeon_console.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/drivers/net/ethernet/cavium/liquidio/octeon_console.c b/driver= s/net/ethernet/cavium/liquidio/octeon_console.c index 28feabec8fbb..67c3570f875f 100644 --- a/drivers/net/ethernet/cavium/liquidio/octeon_console.c +++ b/drivers/net/ethernet/cavium/liquidio/octeon_console.c @@ -247,8 +247,7 @@ static const struct cvmx_bootmem_named_block_desc struct cvmx_bootmem_named_block_desc, size)); - strncpy(desc->name, name, sizeof(desc->name)); - desc->name[sizeof(desc->name) - 1] =3D 0; + strscpy(desc->name, name, sizeof(desc->name)); return &oct->bootmem_named_block_desc; } else { return NULL; @@ -471,8 +470,8 @@ static void output_console_line(struct octeon_device *o= ct, if (line !=3D &console_buffer[bytes_read]) { console_buffer[bytes_read] =3D '\0'; len =3D strlen(console->leftover); - strncpy(&console->leftover[len], line, - sizeof(console->leftover) - len); + strscpy(&console->leftover[len], line, + sizeof(console->leftover) - len + 1); } } --=20 2.15.2