Received: by 2002:a05:6358:16cc:b0:ea:6187:17c9 with SMTP id r12csp7202825rwl; Mon, 9 Jan 2023 20:02:31 -0800 (PST) X-Google-Smtp-Source: AMrXdXuoT7+1yVWn1H8m1GX236E5ubok7JDMOOjmPMLE9qBzSB9f1wnuWBqL02vD6iDyiuzc8AgN X-Received: by 2002:a17:907:a4c3:b0:84d:150d:5006 with SMTP id vq3-20020a170907a4c300b0084d150d5006mr14794530ejc.49.1673323351361; Mon, 09 Jan 2023 20:02:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673323351; cv=none; d=google.com; s=arc-20160816; b=loV0sleBW3WNwkMscy7ld2CcDTo15VOkKzcl5TMq09k2O9cWrfsgDgfYiAidIsVuVW sbSnfEwKiK6XuGhfr5CTzWNe1dd0j+Y4KBpt2IpqxPfSLaWJwAD+FJC0LppLVZ+Zs57v L2pPJaEanAQwhtabtDRUPtm/Gzp0Ey1ySeshexsNucMUvbR4ZoGz0T862fBpoPCKmv7n Ht+XiHkVOM7e2n+Sj6yd+ShCx4c4X3BwtJutner5RXy0hmVtkZwTnwImFaWxRo1fuGlw 0zNwvJ4fdxushvSdcp5yowIcoRD2cC17WMZ3ZqhtlAx0cxCnH5IQIyOEXlHYaTFenSCx ejLg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date :dkim-signature; bh=IOpWXw/PUPAiySp3N5AvLCEifU72qRjExu2n83qFsaA=; b=YGMYuQomnCfPpenqIBaKJ2II/lcULIE6O3kKMrYRS99bolvOEEiB129fAVQrk+6urW nWuZAR7BLLqKPvY0z++cTNCrgvjR9CPudM7OXKgZrx/Ot1aHZzArfcU4qtckjvKa6+xa 11l9/NfZyoMukE0nMZMu7vc1Hv5w7XAdQ8+6nWb4/uAA/L+BafbmGZVOQ9eCG6KZPzX0 e7cdZcDQkYuKye1rAqR+0DW53K5ckUMgcMZ2h+BStwbm8xmB2bFeZUV39NsRvmMCr04I 0A7fsV6Xu83/C9UyZoRE0bB9AHc774u6H594TcWYRjAi+DhQjuqz1qCOJE8vAp7sc5IF jO7w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=TebNgjhw; 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 xe6-20020a170907318600b0084cbde35b2fsi11224017ejb.465.2023.01.09.20.02.18; Mon, 09 Jan 2023 20:02:31 -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=TebNgjhw; 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 S230086AbjAJDsl (ORCPT + 55 others); Mon, 9 Jan 2023 22:48:41 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54596 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229559AbjAJDsh (ORCPT ); Mon, 9 Jan 2023 22:48:37 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E37AE3892; Mon, 9 Jan 2023 19:48:36 -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 731B5614D0; Tue, 10 Jan 2023 03:48:36 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 41766C433D2; Tue, 10 Jan 2023 03:48:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1673322515; bh=k0oxUAg3YrKMFiDeGEKXfTN+oirhrrPZOBzv4qz4G3U=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=TebNgjhwXV4rK4gud4NX6oOD9b43IzZZzbI6TTND1KHLjTQj82pm7zY6x7avwmF8n fga6Lwtc0etfXzgyAi6JyZNavfYiQRA0SsqODGOL2ADmgosQDOLHf6yYmnBZ7A2c+E T0vUZgee1+uz1ExL9F3TyI56XD1VEvnP+FvxFPYq1FMj5fsVeSs2E/bJCGzwehAMrQ tgazYHyo/zTI9mPUSd3TCrYii1CYYUYJm4D+BebAqCvHXkIM29DDDr3ppou1J0a8Ar ZrLzANVIW40tcrB/XhjHUNheRnRnodMi2PECFHIonHHdv+sOWumd7a4lsSbeu2y6Dw nBr3VM7MxBrzQ== Date: Mon, 9 Jan 2023 19:48:34 -0800 From: Jakub Kicinski To: Cc: , , , , , , , , Subject: Re: [PATCH net-next] net/rds: use strscpy() to instead of strncpy() Message-ID: <20230109194834.24e06def@kernel.org> In-Reply-To: <202301091948433010050@zte.com.cn> References: <202301091948433010050@zte.com.cn> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit 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 Mon, 9 Jan 2023 19:48:43 +0800 (CST) yang.yang29@zte.com.cn wrote: > BUG_ON(strlen(names[i]) >= sizeof(ctr.name)); > - strncpy(ctr.name, names[i], sizeof(ctr.name) - 1); > - ctr.name[sizeof(ctr.name) - 1] = '\0'; > + strscpy(ctr.name, names[i], sizeof(ctr.name)); You can make use of the fact that strscpy returns useful information and the copy and the preceding BUG_ON() together.