From patchwork Mon Jan 9 11:45:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yang Yang X-Patchwork-Id: 13093314 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 alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id C6EDCC5479D for ; Mon, 9 Jan 2023 11:46:58 +0000 (UTC) Received: from alsa1.perex.cz (alsa1.perex.cz [207.180.221.201]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by alsa0.perex.cz (Postfix) with ESMTPS id B74508795; Mon, 9 Jan 2023 12:46:05 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz B74508795 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1673264815; bh=TWXrDp6wc6c+1LGrMS6uW9fPmX8fcsp1olfwDkyNu+M=; h=Date:From:To:Subject:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:Cc:From; b=lVO++iY+zreR+n2ywOrLAUBo1P7ni5AKaRcdGYSe95aSSGSNwnc8j2LyU1tBsDyOp dVmXMBtxvsTyd8gqxZaY87pNoLffw84u5YnsceBR8v8d/Fyafbch9f4TYn19HcIGjY LX1jgIQ/vA2zzbAHRF9PodVqnVVDTf2qHpshtCNs= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id 6ECA9F802BE; Mon, 9 Jan 2023 12:46:05 +0100 (CET) Received: by alsa1.perex.cz (Postfix, from userid 50401) id 6E77DF803DC; Mon, 9 Jan 2023 12:46:04 +0100 (CET) Received: from mxhk.zte.com.cn (mxhk.zte.com.cn [63.216.63.35]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by alsa1.perex.cz (Postfix) with ESMTPS id 00CE4F8030F for ; Mon, 9 Jan 2023 12:46:01 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz 00CE4F8030F Received: from mse-fl1.zte.com.cn (unknown [10.5.228.132]) (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 4NrBwM51jlz6FK2T; Mon, 9 Jan 2023 19:45:55 +0800 (CST) Received: from szxlzmapp02.zte.com.cn ([10.5.231.79]) by mse-fl1.zte.com.cn with SMTP id 309Bjmri092787; Mon, 9 Jan 2023 19:45:48 +0800 (+08) (envelope-from yang.yang29@zte.com.cn) Received: from mapi (szxlzmapp01[null]) by mapi (Zmail) with MAPI id mid14; Mon, 9 Jan 2023 19:45:51 +0800 (CST) Date: Mon, 9 Jan 2023 19:45:51 +0800 (CST) X-Zmail-TransId: 2b0363bbfe6fffffffff89cdc856 X-Mailer: Zmail v1.0 Message-ID: <202301091945513559977@zte.com.cn> Mime-Version: 1.0 From: To: Subject: =?utf-8?q?=5BPATCH_linux-next=5D_ALSA=3A_control-led=3A_use_strscpy?= =?utf-8?q?=28=29_to_instead_of_strncpy=28=29?= X-MAIL: mse-fl1.zte.com.cn 309Bjmri092787 X-Fangmail-Gw-Spam-Type: 0 X-FangMail-Miltered: at cgslv5.04-192.168.250.138.novalocal with ID 63BBFE73.000 by FangMail milter! X-FangMail-Envelope: 1673264755/4NrBwM51jlz6FK2T/63BBFE73.000/10.5.228.132/[10.5.228.132]/mse-fl1.zte.com.cn/ X-Fangmail-Anti-Spam-Filtered: true X-Fangmail-MID-QID: 63BBFE73.000/4NrBwM51jlz6FK2T X-BeenThere: alsa-devel@alsa-project.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: yang.yang29@zte.com.cn, xu.panda@zte.com.cn, alsa-devel@alsa-project.org, tiwai@suse.com, linux-kernel@vger.kernel.org Errors-To: alsa-devel-bounces@alsa-project.org Sender: "Alsa-devel" 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 --- sound/core/control_led.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/sound/core/control_led.c b/sound/core/control_led.c index f975cc85772b..c88653c205eb 100644 --- a/sound/core/control_led.c +++ b/sound/core/control_led.c @@ -534,8 +534,7 @@ static ssize_t set_led_id(struct snd_ctl_led_card *led_card, const char *buf, si struct snd_ctl_elem_id id; int err; - strncpy(buf2, buf, len); - buf2[len] = '\0'; + strncpy(buf2, buf, len + 1); memset(&id, 0, sizeof(id)); id.iface = SNDRV_CTL_ELEM_IFACE_MIXER; s = buf2;