From patchwork Mon Dec 26 11:01:55 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yang Yang X-Patchwork-Id: 636960 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 689C6C4167B for ; Mon, 26 Dec 2022 11:02:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231861AbiLZLCD (ORCPT ); Mon, 26 Dec 2022 06:02:03 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53046 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231777AbiLZLCB (ORCPT ); Mon, 26 Dec 2022 06:02:01 -0500 Received: from mxhk.zte.com.cn (mxhk.zte.com.cn [63.216.63.40]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 23FC2111A; Mon, 26 Dec 2022 03:02:00 -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 4NgZc64BqMz8QrkZ; Mon, 26 Dec 2022 19:01:58 +0800 (CST) Received: from szxlzmapp05.zte.com.cn ([10.5.230.85]) by mse-fl2.zte.com.cn with SMTP id 2BQB1qBG066734; Mon, 26 Dec 2022 19:01:52 +0800 (+08) (envelope-from yang.yang29@zte.com.cn) Received: from mapi (szxlzmapp01[null]) by mapi (Zmail) with MAPI id mid14; Mon, 26 Dec 2022 19:01:55 +0800 (CST) Date: Mon, 26 Dec 2022 19:01:55 +0800 (CST) X-Zmail-TransId: 2b0363a97f23ffffffffc970d89d X-Mailer: Zmail v1.0 Message-ID: <202212261901554408949@zte.com.cn> Mime-Version: 1.0 From: To: Cc: , , , , , , Subject: =?utf-8?q?=5BPATCH_linux-next=5D_scsi=3A_smartpqi=3A_use_strscpy=28?= =?utf-8?q?=29_to_instead_of_strncpy=28=29?= X-MAIL: mse-fl2.zte.com.cn 2BQB1qBG066734 X-Fangmail-Gw-Spam-Type: 0 X-FangMail-Miltered: at cgslv5.04-192.168.250.137.novalocal with ID 63A97F26.000 by FangMail milter! X-FangMail-Envelope: 1672052518/4NgZc64BqMz8QrkZ/63A97F26.000/10.5.228.133/[10.5.228.133]/mse-fl2.zte.com.cn/ X-Fangmail-Anti-Spam-Filtered: true X-Fangmail-MID-QID: 63A97F26.000/4NgZc64BqMz8QrkZ Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org 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/scsi/smartpqi/smartpqi_init.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/drivers/scsi/smartpqi/smartpqi_init.c b/drivers/scsi/smartpqi/smartpqi_init.c index d0446d4d4465..1f8f3aee37b6 100644 --- a/drivers/scsi/smartpqi/smartpqi_init.c +++ b/drivers/scsi/smartpqi/smartpqi_init.c @@ -996,9 +996,8 @@ static int pqi_write_driver_version_to_host_wellness( buffer->driver_version_tag[1] = 'V'; put_unaligned_le16(sizeof(buffer->driver_version), &buffer->driver_version_length); - strncpy(buffer->driver_version, "Linux " DRIVER_VERSION, - sizeof(buffer->driver_version) - 1); - buffer->driver_version[sizeof(buffer->driver_version) - 1] = '\0'; + strscpy(buffer->driver_version, "Linux " DRIVER_VERSION, + sizeof(buffer->driver_version)); buffer->dont_write_tag[0] = 'D'; buffer->dont_write_tag[1] = 'W'; buffer->end_tag[0] = 'Z';