Received: by 2002:a05:6358:16cc:b0:ea:6187:17c9 with SMTP id r12csp1205406rwl; Thu, 5 Jan 2023 10:04:38 -0800 (PST) X-Google-Smtp-Source: AMrXdXuRXTMgESB2xqlWI+y/Z/bUyYVDohJ43jiDrhT0cxxnZ8JLgrxBoxC7scubdtATgn7zWIvw X-Received: by 2002:a05:6a20:7faa:b0:b3:8808:b93d with SMTP id d42-20020a056a207faa00b000b38808b93dmr51685740pzj.62.1672941878026; Thu, 05 Jan 2023 10:04:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672941878; cv=none; d=google.com; s=arc-20160816; b=s8XHBqz/295Cp+uteekgm4G3lYNzbsSHhtG9sjoqpMDPiX/4SXTIJoBzwAp0cOciN1 V8KEnSc0h2iBTA0x8RG+5FrJLREhDVY+KaUC89+TpLpxXZoNesmnWP9Rx7VYes/IENIQ gpq8MUTbpIoBhHGI0RrqiOHExAHN66r9Nxrwl6404VGlcUEcp16eWWnZQ8pF8sINe33B f5fMw0igIQQ+8gF7zNePl6eN8wZFXZ+kiOyl7vFIlkJ63cvNhIxCgh01Mrkk/WYuiExJ NByqFLc/F7/YIXRqHtTYiQ0JqL9WYnpKW40Rn8MtkPFZY5KaJEsdgDDIRg4z+5srfvyl iTXw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:reply-to:message-id:subject:cc:to:from:date :dkim-signature; bh=smY/TiHugWIUQ/nsVxenxxOu6D5bThHAqOPD+20/BLA=; b=LyNUKyVEnnS/tiJKRs1ZSpN5QcY4YibRKY6Kgp0XsyMrILwuaTes2lBCVtm2M7Z2uI Tiuqqrgc+HeSlKRLVMnK9EB1NmviiKrXvGEGTRn1zGKy6PrizG+64aHkx8QgjjpvfvJD cKp8DJBC2rsKxgxiiHqqo1zoX6qdqhHNaOGnaO8H28dlcAEufLvAfTlQmeAH44IaAL0+ Ze9qP7F20+spRl7EN5+5sxaAgeG0Moh8FV1rY5xA77Y2jxfgqhzjipeyrj/JblCKhHv0 WOLdPrms1++GO3ogD2I6z1PQBp3veynAN9oZfXSsnT/ratTL00X9lo62M14PaKNSCZfq jksw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=KKHkVHlP; 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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id r3-20020a632b03000000b0046b041e1408si38986431pgr.744.2023.01.05.10.04.30; Thu, 05 Jan 2023 10:04:38 -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; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=KKHkVHlP; 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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235245AbjAERtg (ORCPT + 55 others); Thu, 5 Jan 2023 12:49:36 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57816 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235195AbjAERt1 (ORCPT ); Thu, 5 Jan 2023 12:49:27 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 520B550051; Thu, 5 Jan 2023 09:49:26 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id E06A761AC9; Thu, 5 Jan 2023 17:49:25 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 51771C433D2; Thu, 5 Jan 2023 17:49:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1672940965; bh=5TSkYg+2VQLbcORpvH9lpgB7lm5DQeZfI2Us2iHw7U0=; h=Date:From:To:Cc:Subject:Reply-To:References:In-Reply-To:From; b=KKHkVHlPfkdfeDtxEPgHKmZaAhRHO5pyEBeWnCwqwjnGfSdD/VyOBQfT9HKNRQFod NSEOKGbdBdIkb7DDZvYr85k7NQfSi/FiKu8iCqhGsAuGD3dT/9Vx3Jig38OxEHjzQX YEz+53lE1s2+ijrmOnH5zRjV9D101DTPuauA2Ytn+nUAY+ahy1KtgUzfMebLhOP5l4 PCCZpiIt92olf/cxg1lRY2SMZOLocdgcwG3ub3Y02aUR0MNSWCKESkhhzur0kPZsjR PdQbgCbE3kpDIF+yrNoJwWkDV3jyYwymfF588hkRiDi7Dv3xMCtdo0SlZyMBvFxyPy e6FkF8wqUr4kw== Received: by paulmck-ThinkPad-P17-Gen-1.home (Postfix, from userid 1000) id EA8B45C0544; Thu, 5 Jan 2023 09:49:24 -0800 (PST) Date: Thu, 5 Jan 2023 09:49:24 -0800 From: "Paul E. McKenney" To: yang.yang29@zte.com.cn Cc: rostedt@goodmis.org, mhiramat@kernel.org, linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org, xu.panda@zte.com.cn Subject: Re: [PATCH linux-next] rcu/trace: use strscpy() to instead of strncpy() Message-ID: <20230105174924.GD4028633@paulmck-ThinkPad-P17-Gen-1> Reply-To: paulmck@kernel.org References: <202301052017571305723@zte.com.cn> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <202301052017571305723@zte.com.cn> X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, 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 On Thu, Jan 05, 2023 at 08:17:57PM +0800, yang.yang29@zte.com.cn wrote: > 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 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 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 Signed-off-by: Yang Yang Signed-off-by: Paul E. McKenney 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;