From patchwork Wed Jan 18 01:29:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bo Liu X-Patchwork-Id: 44908 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp2082059wrn; Tue, 17 Jan 2023 17:32:30 -0800 (PST) X-Google-Smtp-Source: AMrXdXsfffMRsrpD+k9AJXLaMlANy1A1zCkywv+UDoZy2hPpUG5r1BLhLkVRwoWco1N8PcigTErf X-Received: by 2002:aa7:c917:0:b0:483:5e56:7bc5 with SMTP id b23-20020aa7c917000000b004835e567bc5mr5241361edt.40.1674005550554; Tue, 17 Jan 2023 17:32:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1674005550; cv=none; d=google.com; s=arc-20160816; b=RxZZkrxz/iMxUGjFQ71570/yiS8B0mHfVwTVrhMLkfUv+AGUoubcd+BQRdpIOIg6GQ VkmQan8DXjXQjLAGvqJoj5VFFRphY2YZIN5gu2jYAgJqFnP+rQBuzyhi7hrl4ZcmSQq3 U9RI9rhjhtgkqu8tYChv7s39I5e7GQWwixCab4pW8k3peO/QTYpGnKrgL+zxlpN3lfRY omRpRygF/zFnMYOTiLBj9uPQ0FvG/Q9y0iaqkx4rMIXGjJlZPkWKN1ry4SrvFrblmClY AaNya7iZCPIgNQM9VLVouMUQL7KRTDBsgxSln56Zr97SJPiFWt6Oif3hUBTXFb0KMPRA m1Mg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:abuse-reports-to:tuid:mime-version:message-id :date:subject:cc:to:from; bh=yNgR3Xw23Xvj0ApE6pKeYEkGlu5kQWRN1sio/UvbaPU=; b=TNIs361bqf+jX14Z0UGbAjeHbE2YAsHWi9K+19LW0hH40XTAv9dAhRoWlmOdHrwdcg r9wrmF3m8XKNIGt/ml9yjArDXkro3c7QB/e1A/qS+XhcAX0d6I1eT6C86ElWV1sqgdoX HPKj1WBU18MUXEZh0RuTCwi8Ed+X2IOyoCRCaZmz8BX9uV3SrnEfZJeUi2E9w0lutOau FEjtmz53S12uTjUOLp17Bj9IwEBTBy9EpXrVWaH79kmVgGLS9OKRNRJ9q+i4tmRZ/D1Z nOK66+LCElJt5GKGG8Y81bSrRSx0cQecYVd8bpPFU+JxLJz6IoB+i5FiqIPG6y85c2TK NPNQ== 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id eb14-20020a0564020d0e00b0047ff112ee12si39611587edb.101.2023.01.17.17.32.06; Tue, 17 Jan 2023 17:32:30 -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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229548AbjARB3S (ORCPT + 99 others); Tue, 17 Jan 2023 20:29:18 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49366 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229483AbjARB3O (ORCPT ); Tue, 17 Jan 2023 20:29:14 -0500 Received: from ssh248.corpemail.net (ssh248.corpemail.net [210.51.61.248]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 428AC3D937; Tue, 17 Jan 2023 17:29:13 -0800 (PST) Received: from ([60.208.111.195]) by ssh248.corpemail.net ((D)) with ASMTP (SSL) id NSV00010; Wed, 18 Jan 2023 09:29:10 +0800 Received: from localhost.localdomain (10.200.104.97) by jtjnmail201612.home.langchao.com (10.100.2.12) with Microsoft SMTP Server id 15.1.2507.16; Wed, 18 Jan 2023 09:29:10 +0800 From: Bo Liu To: , , , , CC: , , Bo Liu Subject: [PATCH] EDAC/mc_sysfs: use strscpy() to instead of strncpy() Date: Tue, 17 Jan 2023 20:29:06 -0500 Message-ID: <20230118012906.2376-1-liubo03@inspur.com> X-Mailer: git-send-email 2.18.2 MIME-Version: 1.0 X-Originating-IP: [10.200.104.97] tUid: 2023118092910b4e327ae6b9546c5955db50b9c2564f4 X-Abuse-Reports-To: service@corp-email.com Abuse-Reports-To: service@corp-email.com X-Complaints-To: service@corp-email.com X-Report-Abuse-To: service@corp-email.com X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,RCVD_IN_MSPIKE_H2, SPF_HELO_NONE,SPF_PASS 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?1755322043766811377?= X-GMAIL-MSGID: =?utf-8?q?1755322043766811377?= The implementation of strscpy() is more robust and safer. That's now the recommended way to copy NUL terminated strings. Signed-off-by: Bo Liu --- drivers/edac/edac_mc_sysfs.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/drivers/edac/edac_mc_sysfs.c b/drivers/edac/edac_mc_sysfs.c index 15f63452a9be..b709cbe8dcf9 100644 --- a/drivers/edac/edac_mc_sysfs.c +++ b/drivers/edac/edac_mc_sysfs.c @@ -229,8 +229,7 @@ static ssize_t channel_dimm_label_store(struct device *dev, if (copy_count == 0 || copy_count >= sizeof(rank->dimm->label)) return -EINVAL; - strncpy(rank->dimm->label, data, copy_count); - rank->dimm->label[copy_count] = '\0'; + strscpy(rank->dimm->label, data, copy_count + 1); return count; } @@ -535,8 +534,7 @@ static ssize_t dimmdev_label_store(struct device *dev, if (copy_count == 0 || copy_count >= sizeof(dimm->label)) return -EINVAL; - strncpy(dimm->label, data, copy_count); - dimm->label[copy_count] = '\0'; + strscpy(dimm->label, data, copy_count + 1); return count; }