From patchwork Mon Dec 5 11:42:08 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yang Yang X-Patchwork-Id: 29656 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp2201343wrr; Mon, 5 Dec 2022 03:54:15 -0800 (PST) X-Google-Smtp-Source: AA0mqf5AFm5PbxCcXIwRiKzgx5TTX8MfXeoa/mpdUP0OkxbH4808U6INi73bgbvUlB9PQu6HzzK6 X-Received: by 2002:a17:902:ab8d:b0:187:1e83:2505 with SMTP id f13-20020a170902ab8d00b001871e832505mr69947588plr.132.1670241254960; Mon, 05 Dec 2022 03:54:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670241254; cv=none; d=google.com; s=arc-20160816; b=l/wNtR2Qg1hk7wb6yCgzRAzwAsy3Dovi2OIpoA5b8PVhB+4JOiZdt4eeQLiRfXJZbA gKGlT7iU33/bwdxOcmWCXZ6P3gUd8OPB7D7sEGBw0FVWBKEVpippcz+ltp0/R3LVpKt9 IDoLwCHxtgSEVHWyhhtZWWU4o8Vy73OT2m8+JRFUzMhaCGCARe7/4F8iN+mBBmyeVxx8 dl/CQWSfBp1/k8nbJoqSOtvFjCPxnQ6mNcfYk5ZSkl3/JKJbn5va2LDJmTtDhZLtTAVr Dfu+WV8ju8yomWe3WMXSZ4q1tTF3yoaDhFv/rAyrQ7douwXBJyJg5rzvCPMIk5a0n8I2 F37w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:subject:cc:to:from:mime-version:message-id:date; bh=GuLgUHbXLStKbqczWJizrWRjthdRFoJH/JGiqEkxvcY=; b=k3z9cx3vjMiNM5KTR8sMlHUBXUQk2m/WoOB0otD0d3OiwIIr/lDalZhBu4WJQMLeY9 +3WsWU98FyZVFt5SLxvDKsQ/1wBQfNBwcAC6dZmthCYolGRJEnaE2xu5OdVeqiiSeqlB dlX3ckbcgJCMpr9tnFdLAZ1lp2toVpQoCN3qKNZZfjIAmMOyrJvdZFelgtv1FmJbYtaA vJxj2KgyFOl5G0O+DRNQHX8Sdvg0BK3j4sWkIacZl+R0H/jFFlwVAZoEBh5Td76EJG1L lVUR6vgNeu2DhwXxfvqiLAekoeoMdYKFrMAuUKWuB0UbUz8zQ30jxC7aZJkXXnxHxtjI YCww== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=zte.com.cn Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id x15-20020a056a00188f00b0056dc16897d7si17064081pfh.15.2022.12.05.03.54.01; Mon, 05 Dec 2022 03:54:14 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=zte.com.cn Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231375AbiLELnE (ORCPT + 99 others); Mon, 5 Dec 2022 06:43:04 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54558 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231421AbiLELmV (ORCPT ); Mon, 5 Dec 2022 06:42:21 -0500 Received: from mxhk.zte.com.cn (mxhk.zte.com.cn [63.216.63.40]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B609A1A212; Mon, 5 Dec 2022 03:42:10 -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 4NQhV92nnZz8RTZG; Mon, 5 Dec 2022 19:42:09 +0800 (CST) Received: from szxlzmapp07.zte.com.cn ([10.5.230.251]) by mse-fl1.zte.com.cn with SMTP id 2B5Bg4xo053795; Mon, 5 Dec 2022 19:42:04 +0800 (+08) (envelope-from yang.yang29@zte.com.cn) Received: from mapi (szxlzmapp02[null]) by mapi (Zmail) with MAPI id mid14; Mon, 5 Dec 2022 19:42:08 +0800 (CST) Date: Mon, 5 Dec 2022 19:42:08 +0800 (CST) X-Zmail-TransId: 2b04638dd91003fa7628 X-Mailer: Zmail v1.0 Message-ID: <202212051942082259437@zte.com.cn> Mime-Version: 1.0 From: To: Cc: , , , , , , , , , , , , , , , Subject: =?utf-8?q?=5BPATCH_linux-next_v2=5D_x86/platform/uv=3A_use_strscpy_?= =?utf-8?q?to_instead_of_strncpy=28=29?= X-MAIL: mse-fl1.zte.com.cn 2B5Bg4xo053795 X-Fangmail-Gw-Spam-Type: 0 X-FangMail-Miltered: at cgslv5.04-192.168.250.137.novalocal with ID 638DD911.001 by FangMail milter! X-FangMail-Envelope: 1670240529/4NQhV92nnZz8RTZG/638DD911.001/10.5.228.132/[10.5.228.132]/mse-fl1.zte.com.cn/ X-Fangmail-Anti-Spam-Filtered: true X-Fangmail-MID-QID: 638DD911.001/4NQhV92nnZz8RTZG X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,RCVD_IN_MSPIKE_H2, SPF_HELO_NONE,SPF_PASS,UNPARSEABLE_RELAY autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1751374894563587102?= X-GMAIL-MSGID: =?utf-8?q?1751374894563587102?= From: Xu Panda The implementation of strscpy() is more robust and safer. That's now the recommended way to copy NUL terminated strings. --- change for v2 - fix the mistake and make the code better and simpler, thanks to Andy Shevchenko. --- Signed-off-by: Xu Panda Signed-off-by: Yang Yang Signed-off-by: Andy Shevchenko --- arch/x86/platform/uv/uv_nmi.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/arch/x86/platform/uv/uv_nmi.c b/arch/x86/platform/uv/uv_nmi.c index a60af0230e27..d94140842aa3 100644 --- a/arch/x86/platform/uv/uv_nmi.c +++ b/arch/x86/platform/uv/uv_nmi.c @@ -205,11 +205,7 @@ static int param_set_action(const char *val, const struct kernel_param *kp) char arg[ACTION_LEN], *p; /* (remove possible '\n') */ - strncpy(arg, val, ACTION_LEN - 1); - arg[ACTION_LEN - 1] = '\0'; - p = strchr(arg, '\n'); - if (p) - *p = '\0'; + strscpy(arg, val, strnchrnul(val, ACTION_LEN, '\n') - val); for (i = 0; i < n; i++) if (!strcmp(arg, valid_acts[i].action))