From patchwork Mon Dec 5 11:33:50 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yang Yang X-Patchwork-Id: 29650 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp2195820wrr; Mon, 5 Dec 2022 03:39:58 -0800 (PST) X-Google-Smtp-Source: AA0mqf5lThv1t6a4g9DCU8Wi8Nh9dlrZ9NfH1khuT1yjgYIXb4u05P1B4Jf9ehZhKhr1PzjssWsC X-Received: by 2002:a17:902:848d:b0:17a:b11:3c5 with SMTP id c13-20020a170902848d00b0017a0b1103c5mr62584443plo.22.1670240397721; Mon, 05 Dec 2022 03:39:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670240397; cv=none; d=google.com; s=arc-20160816; b=i0SZ9eRDtpjzMCz1FfyFnCglZO9tlMdcGRCmMjrvzLTFjQuhuBwzllW3UCxuvWv5SK Os0SB29zv2U3qQLjLsqtfgJUy3q2mkp4EbtxDHcE9Vg2AsbcRYDuprb+0wOd78fnKB+c XHqut7oCZiqCyFHwoEEvDmzS+s4B3EGrCq4yi6XPmQYMigUMwSYeahylSitrsY49dFTq omClOkXqdd1eedfOp4ydU8UoWDX0A2RRr29EoTh+RwSHERanxYvFbk50BZNb/KjSDmSy QXah6pUl8mSA+d4y/JB6Be/LjL2bE0f9yb6KUTZ+yyt01rVQhctTPUeRi/Y9ncXPISOP NwDw== 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=c135bsxN81pmfK8SohkMpnWHfIerwYAsB99v6em89Y4=; b=UoBSBxg1BVztwKKgcXW/kRKY/hHxEiQ5LPhpHsbpP8+EZo825iT/ydrtZpoyAX2ywg JgE5yWhz43xcX36mfA4aKEdUB+Bi5SJykBr5/Jkuz+F72MBSkdG+SxgaNOs2pxUUX09V wrPA4R4DRg0Zsz6fi1biMwB8MejYydCk+8iXmNfD0+z1segIGo7echgjkdl7ueG3e01S LeQc5kSjQ7wu/7hZmZSUnVmEYQI9g3EOuV1/5HQDAI6+SheX/79xPky8aw9k/bBFn006 +CIL+Z0lCWvyq7SNVpeTGc9z4RM7ELmd7GGjJbt4FAfrqIN+t1Uq6OJVGmnBTfYRaNJU cZPg== 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 c4-20020a63d144000000b00478d43abd0dsi110547pgj.248.2022.12.05.03.39.44; Mon, 05 Dec 2022 03:39:57 -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 S230465AbiLELd6 (ORCPT + 99 others); Mon, 5 Dec 2022 06:33:58 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48230 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230110AbiLELd4 (ORCPT ); Mon, 5 Dec 2022 06:33:56 -0500 Received: from mxhk.zte.com.cn (mxhk.zte.com.cn [63.216.63.35]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 070EE6367 for ; Mon, 5 Dec 2022 03:33:56 -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 4NQhJf5HRvz5BNRf; Mon, 5 Dec 2022 19:33:54 +0800 (CST) Received: from szxlzmapp06.zte.com.cn ([10.5.230.252]) by mse-fl2.zte.com.cn with SMTP id 2B5BXmkP074067; Mon, 5 Dec 2022 19:33:48 +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:33:50 +0800 (CST) Date: Mon, 5 Dec 2022 19:33:50 +0800 (CST) X-Zmail-TransId: 2b04638dd71e1939a789 X-Mailer: Zmail v1.0 Message-ID: <202212051933509509270@zte.com.cn> Mime-Version: 1.0 From: To: Cc: , , , Subject: =?utf-8?q?=5BPATCH_linux-next=5D_bus=3A_fsl-mc=3A_use_strscpy=28=29?= =?utf-8?q?_to_instead_of_strncpy=28=29?= X-MAIL: mse-fl2.zte.com.cn 2B5BXmkP074067 X-Fangmail-Gw-Spam-Type: 0 X-FangMail-Miltered: at cgslv5.04-192.168.250.138.novalocal with ID 638DD722.000 by FangMail milter! X-FangMail-Envelope: 1670240034/4NQhJf5HRvz5BNRf/638DD722.000/10.5.228.133/[10.5.228.133]/mse-fl2.zte.com.cn/ X-Fangmail-Anti-Spam-Filtered: true X-Fangmail-MID-QID: 638DD722.000/4NQhJf5HRvz5BNRf 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: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1751373995000151337?= X-GMAIL-MSGID: =?utf-8?q?1751373995000151337?= 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 --- drivers/bus/fsl-mc/dprc.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/drivers/bus/fsl-mc/dprc.c b/drivers/bus/fsl-mc/dprc.c index d129338b8bc0..d095d1e044e7 100644 --- a/drivers/bus/fsl-mc/dprc.c +++ b/drivers/bus/fsl-mc/dprc.c @@ -450,10 +450,8 @@ int dprc_get_obj(struct fsl_mc_io *mc_io, obj_desc->ver_major = le16_to_cpu(rsp_params->version_major); obj_desc->ver_minor = le16_to_cpu(rsp_params->version_minor); obj_desc->flags = le16_to_cpu(rsp_params->flags); - strncpy(obj_desc->type, rsp_params->type, 16); - obj_desc->type[15] = '\0'; - strncpy(obj_desc->label, rsp_params->label, 16); - obj_desc->label[15] = '\0'; + strscpy(obj_desc->type, rsp_params->type, 16); + strscpy(obj_desc->label, rsp_params->label, 16); return 0; } EXPORT_SYMBOL_GPL(dprc_get_obj); @@ -491,8 +489,7 @@ int dprc_set_obj_irq(struct fsl_mc_io *mc_io, cmd_params->irq_addr = cpu_to_le64(irq_cfg->paddr); cmd_params->irq_num = cpu_to_le32(irq_cfg->irq_num); cmd_params->obj_id = cpu_to_le32(obj_id); - strncpy(cmd_params->obj_type, obj_type, 16); - cmd_params->obj_type[15] = '\0'; + strscpy(cmd_params->obj_type, obj_type, 16); /* send command to mc*/ return mc_send_command(mc_io, &cmd); @@ -564,8 +561,7 @@ int dprc_get_obj_region(struct fsl_mc_io *mc_io, cmd_params = (struct dprc_cmd_get_obj_region *)cmd.params; cmd_params->obj_id = cpu_to_le32(obj_id); cmd_params->region_index = region_index; - strncpy(cmd_params->obj_type, obj_type, 16); - cmd_params->obj_type[15] = '\0'; + strscpy(cmd_params->obj_type, obj_type, 16); /* send command to mc*/ err = mc_send_command(mc_io, &cmd);