Message ID | 202301052017571305723@zte.com.cn |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp272280wrt; Thu, 5 Jan 2023 04:20:01 -0800 (PST) X-Google-Smtp-Source: AMrXdXvLTdkMYdh6xbHTkMzBiwYx3EHbshxYLtw5UySJz7ByD4rNQQpYM1vHpjPtpzct+F0S0aYW X-Received: by 2002:a62:1ec7:0:b0:56d:1e00:f078 with SMTP id e190-20020a621ec7000000b0056d1e00f078mr46654220pfe.32.1672921201367; Thu, 05 Jan 2023 04:20:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672921201; cv=none; d=google.com; s=arc-20160816; b=g+qxqhRxPus65gdSb8YsJjXLGZrTpmDzfnemcb8E/jhGFwxjAmYkJmhbnm8vGeX1Mn Kc0zrb67uJAlJ5zcD6JomyFD4o+kFBgybfKhFD+W3PPUJyTs5MBSEGE+szoBwhwaCEkv 2zQY2YrUPYndGIAGLAruWBgFy+9YgVf8Brphi5a5zb5Lr6813CKebOLshh9B/X8b+uBF pnT120Bi25DkNiZBUHKoglXRokxgU7EI0di7Ww24U6GzzIVh8lZiS48R/SfSYTJ9NlrB 5kTkLwh6L9cL8BL6xIsOPtbQDk0Lg5f2lbif3m5YQHqeCdeQEa5BalmZI9vPpmShrdFD 3uEg== 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=yW+PWQQSHw8z6SPIl4Y8ml74/CFKQxO5bTQhi+V36G4=; b=h3BRLujJw1iyP8JsxZx6XaN/D617Sy9vDqjajIJZpCghEVftpPnBI9xT2HlmjZrutW kRl9Wphj7yiMzmdv7ETFerNCKCm4KEqCDBaeiPkbj2FSXMPNQVECk5su7wCUpRILexRE iC9Y5oigSad/lsRmpD7qXsjnDfq4VxQq3LpLGBfNaTC0hWy/Q2JMC8Qx1d1TyVoSFSdz /f9wJmK+fkLSwajHrXd3RJg0+jeiDIjdRe0ssDot2P+qLUNFLRHZOOe+dLtngonlkOnZ m//9aLz8P6ovwfB0IX0Bn5kGWwT5yK2n42rb3xAZwok4tnzUUx7u56D/j85BvqVrjKO6 AxBQ== 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 c1-20020aa781c1000000b005731d316830si35063549pfn.23.2023.01.05.04.19.47; Thu, 05 Jan 2023 04:20:01 -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 S232896AbjAEMSU (ORCPT <rfc822;tmhikaru@gmail.com> + 99 others); Thu, 5 Jan 2023 07:18:20 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53558 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233118AbjAEMSE (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Thu, 5 Jan 2023 07:18:04 -0500 Received: from mxhk.zte.com.cn (mxhk.zte.com.cn [63.216.63.35]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5785C4FCE1; Thu, 5 Jan 2023 04:18:03 -0800 (PST) Received: from mse-fl2.zte.com.cn (unknown [10.5.228.133]) (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 4NnlqF4skCz6FK2Q; Thu, 5 Jan 2023 20:18:01 +0800 (CST) Received: from szxlzmapp05.zte.com.cn ([10.5.230.85]) by mse-fl2.zte.com.cn with SMTP id 305CHs0m064884; Thu, 5 Jan 2023 20:17:54 +0800 (+08) (envelope-from yang.yang29@zte.com.cn) Received: from mapi (szxlzmapp01[null]) by mapi (Zmail) with MAPI id mid14; Thu, 5 Jan 2023 20:17:57 +0800 (CST) Date: Thu, 5 Jan 2023 20:17:57 +0800 (CST) X-Zmail-TransId: 2b0363b6bff5ffffffff94a6df4f X-Mailer: Zmail v1.0 Message-ID: <202301052017571305723@zte.com.cn> Mime-Version: 1.0 From: <yang.yang29@zte.com.cn> To: <rostedt@goodmis.org> Cc: <mhiramat@kernel.org>, <paulmck@kernel.org>, <linux-kernel@vger.kernel.org>, <linux-trace-kernel@vger.kernel.org>, <xu.panda@zte.com.cn>, <yang.yang29@zte.com.cn> Subject: =?utf-8?q?=5BPATCH_linux-next=5D_rcu/trace=3A_use_strscpy=28=29_to_?= =?utf-8?q?instead_of_strncpy=28=29?= Content-Type: text/plain; charset="UTF-8" X-MAIL: mse-fl2.zte.com.cn 305CHs0m064884 X-Fangmail-Gw-Spam-Type: 0 X-FangMail-Miltered: at cgslv5.04-192.168.250.138.novalocal with ID 63B6BFF9.000 by FangMail milter! X-FangMail-Envelope: 1672921081/4NnlqF4skCz6FK2Q/63B6BFF9.000/10.5.228.133/[10.5.228.133]/mse-fl2.zte.com.cn/<yang.yang29@zte.com.cn> X-Fangmail-Anti-Spam-Filtered: true X-Fangmail-MID-QID: 63B6BFF9.000/4NnlqF4skCz6FK2Q X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,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: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1754185021543940477?= X-GMAIL-MSGID: =?utf-8?q?1754185021543940477?= |
Series |
[linux-next] rcu/trace: use strscpy() to instead of strncpy()
|
|
Commit Message
Yang Yang
Jan. 5, 2023, 12:17 p.m. UTC
From: Xu Panda <xu.panda@zte.com.cn> 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 <xu.panda@zte.com.cn> Signed-off-by: Yang Yang <yang.yang29@zte.com.cn> --- include/trace/events/rcu.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
Comments
On Thu, Jan 05, 2023 at 08:17:57PM +0800, yang.yang29@zte.com.cn wrote: > From: Xu Panda <xu.panda@zte.com.cn> > > 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 <xu.panda@zte.com.cn> > Signed-off-by: Yang Yang <yang.yang29@zte.com.cn> Queued for testing and additional review, thank you! Please see below for the traditional wordsmithing and please let me know if I messed anything up. Thanx, Paul ------------------------------------------------------------------------ commit 4034fe140e75d6e51b72d1fd16805e053b9b633c Author: Xu Panda <xu.panda@zte.com.cn> Date: Thu Jan 5 20:17:57 2023 +0800 rcu/trace: use strscpy() to instead of strncpy() This commit saves a line of code by switching from strncpy() to strscpy() by permitting the later NUL assignment to be removed. While in the area, save another line by taking advantage of 100 characters. Signed-off-by: Xu Panda <xu.panda@zte.com.cn> Signed-off-by: Yang Yang <yang.yang29@zte.com.cn> Signed-off-by: Paul E. McKenney <paulmck@kernel.org> diff --git a/include/trace/events/rcu.h b/include/trace/events/rcu.h index 90b2fb0292cb1..c19ac1fa8a607 100644 --- a/include/trace/events/rcu.h +++ b/include/trace/events/rcu.h @@ -776,9 +776,7 @@ TRACE_EVENT_RCU(rcu_torture_read, ), TP_fast_assign( - strncpy(__entry->rcutorturename, rcutorturename, - RCUTORTURENAME_LEN); - __entry->rcutorturename[RCUTORTURENAME_LEN - 1] = 0; + strscpy(__entry->rcutorturename, rcutorturename, RCUTORTURENAME_LEN); __entry->rhp = rhp; __entry->secs = secs; __entry->c_old = c_old;
diff --git a/include/trace/events/rcu.h b/include/trace/events/rcu.h index 90b2fb0292cb..2703992edecd 100644 --- a/include/trace/events/rcu.h +++ b/include/trace/events/rcu.h @@ -776,9 +776,8 @@ TRACE_EVENT_RCU(rcu_torture_read, ), TP_fast_assign( - strncpy(__entry->rcutorturename, rcutorturename, + strscpy(__entry->rcutorturename, rcutorturename, RCUTORTURENAME_LEN); - __entry->rcutorturename[RCUTORTURENAME_LEN - 1] = 0; __entry->rhp = rhp; __entry->secs = secs; __entry->c_old = c_old;