Received: by 2002:a05:6358:c692:b0:131:369:b2a3 with SMTP id fe18csp381742rwb; Thu, 27 Jul 2023 14:24:20 -0700 (PDT) X-Google-Smtp-Source: APBJJlFg0X4exUwUq2uWZhH+Yk7vTk0ZQubydO6tcOOvGHRni/P+GlANO1Z55yHD8nDsAkU1ifaI X-Received: by 2002:a05:6a00:2288:b0:686:24e1:d12e with SMTP id f8-20020a056a00228800b0068624e1d12emr453711pfe.30.1690493059794; Thu, 27 Jul 2023 14:24:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690493059; cv=none; d=google.com; s=arc-20160816; b=pg5+LOi62clHZzgrZsNOGPUuC3hKbL+Sm2RSEIJwSYl5S5mIN47vN3Sx8K5g/hXceU YEQXyXJqWTvUcK84NAJ8nbNeqWykiRdNHzfHUteSOxSXDhps6rU1rywzNnoLvYH2EElR 3PlmCGlyKnWiKfiYxlNA2ynm68V1UUGpmxXI6IsKyANFcRZVBeCqmGMzKknITS+32LKT Plr9bHvXruixk8YISAxl8c7i+MZPqgUbv1TWYhDVSPY3xNXeVR0VjVvA+2bdj9AbHksm aUJxDprx3hiG63bybfauigRoLMSjOLqQSQta9oxPT174o2WEXbXkAyT35YIWvo5g4AIN gUuA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:dkim-signature; bh=lEKw26+6RZdhI/anFRn58wCKq7xAbjFEyn0dAkNnpG0=; fh=WA15SYOSujuJHEgMiw7VPEQx+mVlLLZ6lDpWRZZScnM=; b=g5f6ZUF2gdOo7kZ5WSDU0tZMt5qVsO28MoSopJQdCmpKwpsO0TclLop8htmk/ESKls kM5dczBnI0l8qfoXtYZ7eP9+drRc5DkRR0YwkbQM25JoQ4loWx8ThZGUNowvDwBMQVjC RxbScKCKzHxqwFL57OfdC8lvc51nURHduzLhS+tB59UNDyASt+mVV2AW8iFg/YHSYrJL htpodM1eDjfXLzbBEwXQQhYN/oicK9lpxkAPCiswDpQRaywHyfPSwkgauTNesgb+uWpy 5dQn9QrHkxmntDLBLbxdVdZnOrgCjPcbH3uju+H/IeHZ/1LxVdh3+i0mHYXVtS9k3rwL NkCQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=JQC4MlN3; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id d1-20020a056a0024c100b00686dd813934si1906095pfv.82.2023.07.27.14.24.06; Thu, 27 Jul 2023 14:24:19 -0700 (PDT) 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=@google.com header.s=20221208 header.b=JQC4MlN3; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231206AbjG0UbK (ORCPT + 99 others); Thu, 27 Jul 2023 16:31:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55750 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231295AbjG0UbF (ORCPT ); Thu, 27 Jul 2023 16:31:05 -0400 Received: from mail-yb1-xb49.google.com (mail-yb1-xb49.google.com [IPv6:2607:f8b0:4864:20::b49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 52D68271C for ; Thu, 27 Jul 2023 13:30:55 -0700 (PDT) Received: by mail-yb1-xb49.google.com with SMTP id 3f1490d57ef6-d087ffcc43cso1308475276.3 for ; Thu, 27 Jul 2023 13:30:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1690489854; x=1691094654; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=lEKw26+6RZdhI/anFRn58wCKq7xAbjFEyn0dAkNnpG0=; b=JQC4MlN38CgOxQdZXvHWUw5mbVGP5ZPWx3/5G8h/aF0HPkdXFJcNXoEoXMLjnMoF+x 4Hu7uggmX2FpspBq6lxF6wv2JjPXaPL+uGbaW+Nd7y8gpo8X88P8w29kKuvtOUw19yXA zphnSGDV8E05vxXMRCAAt9K2cv2wVtwHz4LUJ5smBonEAlaEnG7uioYbPbvxaUBOgFyn f9D0nZZnJcuVdYQjNi024aRj9xHd9AEX9poOXq/xImJab3PtyMVu7Znmvks/rO0yWHkY cFEs01yQ6Z2Gh4IzSHsnInDvM54A6RIJuGDOnwXLr9ngP2bmUs2Orsu+Gx7Slb7I84Di fGSw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690489854; x=1691094654; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=lEKw26+6RZdhI/anFRn58wCKq7xAbjFEyn0dAkNnpG0=; b=RyT5AgVcCbbk6ikitpUFLdJgkeokjrBIFBna2UeK2F/BfRtOwjGp2rqJQryv4l5RWt eX5PRZleQ2zKGyEq8ZFc0e5noeyDcQlWf95jgH98Cx6HfFK+T0vGjuDV5dKxfpZ/4uq8 4EluRD3szN+xLqZCdfD0hbv2uXUVrDuGCISNQ2y8uLy2ruOqQLPjuP8rk4WIyM3fzD7I AP2dOZ6/OS+5idhMbZyGseJWtEx1HgT2uYPZDqNj+4HRRieqZTOR5Fsitdxd7YOBYctH t7zLvZ41Neg8FlPx0b3TpDlbvADDnkifNtemku55u/sjBGIX8FhQYwgXqumkuSsTr5nQ Tw6A== X-Gm-Message-State: ABy/qLbsYxW5kcUL+smRUWQG8R42U9R+T1nemWJaZSJwgS0Ym20H32fN zmkYy2s9U2zcTF4KyvbFX9iiGuRNUdQ6elniog== X-Received: from jstitt-linux1.c.googlers.com ([fda3:e722:ac3:cc00:2b:ff92:c0a8:23b5]) (user=justinstitt job=sendgmr) by 2002:a25:c0cd:0:b0:d0f:dec4:87a0 with SMTP id c196-20020a25c0cd000000b00d0fdec487a0mr2722ybf.2.1690489854578; Thu, 27 Jul 2023 13:30:54 -0700 (PDT) Date: Thu, 27 Jul 2023 20:30:18 +0000 In-Reply-To: <20230726-asoc-intel-skylake-remove-deprecated-strncpy-v1-1-020e04184c7d@google.com> Mime-Version: 1.0 References: <20230726-asoc-intel-skylake-remove-deprecated-strncpy-v1-1-020e04184c7d@google.com> X-Developer-Key: i=justinstitt@google.com; a=ed25519; pk=tC3hNkJQTpNX/gLKxTNQKDmiQl6QjBNCGKJINqAdJsE= X-Developer-Signature: v=1; a=ed25519-sha256; t=1690489451; l=2099; i=justinstitt@google.com; s=20230717; h=from:subject:message-id; bh=ekRYz8xbmy5B35whJHZOKa2NN55Pqt6uzdTr4Owj6tU=; b=ZHerNq4/0/izYJjYC4OPRwRQsf1JjGaWzyKG1n6tatiOox8osMHj5IC5H3w7pomkovsRZW+Mr ZalieCCjJkOBFVxsodA8i2CfMpi8W7SOSDjFdBjxoR32Os1IBvPaV8a X-Mailer: b4 0.12.3 Message-ID: <20230727-asoc-intel-skylake-remove-deprecated-strncpy-v2-1-152830093921@google.com> Subject: [PATCH v2] ASoC: Intel: Skylake: replace deprecated strncpy with strscpy From: Justin Stitt To: Cezary Rojewski , Pierre-Louis Bossart , Liam Girdwood , Peter Ujfalusi , Bard Liao , Ranjani Sridharan , Kai Vehmanen , Mark Brown , Jaroslav Kysela , Takashi Iwai Cc: Justin Stitt , Kees Cook , Nathan Chancellor , alsa-devel@alsa-project.org, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL 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 `strncpy` is deprecated for use on NUL-terminated destination strings [1]. A suitable replacement is `strscpy` [2] due to the fact that it guarantees NUL-termination on its destination buffer argument which is _not_ the case for `strncpy`! It was pretty difficult, in this case, to try and figure out whether or not the destination buffer was zero-initialized. If it is and this behavior is relied on then perhaps `strscpy_pad` is the preferred option here. Kees was able to help me out and identify the following code snippet which seems to show that the destination buffer is zero-initialized. | skl = devm_kzalloc(&pci->dev, sizeof(*skl), GFP_KERNEL); With this information, I opted for `strscpy` since padding is seemingly not required. [1]: www.kernel.org/doc/html/latest/process/deprecated.html#strncpy-on-nul-terminated-strings [2]: manpages.debian.org/testing/linux-manual-4.8/strscpy.9.en.html Link: https://github.com/KSPP/linux/issues/90 Suggested-by: Kees Cook Signed-off-by: Justin Stitt --- Changes in v2: - Remove extraneous logic change (thanks Kees) - Link to v1: https://lore.kernel.org/r/20230726-asoc-intel-skylake-remove-deprecated-strncpy-v1-1-020e04184c7d@google.com --- sound/soc/intel/skylake/skl-topology.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sound/soc/intel/skylake/skl-topology.c b/sound/soc/intel/skylake/skl-topology.c index 96cfebded072..0ead3ea605cd 100644 --- a/sound/soc/intel/skylake/skl-topology.c +++ b/sound/soc/intel/skylake/skl-topology.c @@ -3159,7 +3159,7 @@ static int skl_tplg_fill_str_mfest_tkn(struct device *dev, return -EINVAL; } - strncpy(skl->lib_info[ref_count].name, + strscpy(skl->lib_info[ref_count].name, str_elem->string, ARRAY_SIZE(skl->lib_info[ref_count].name)); ref_count++; --- base-commit: 0b4a9fdc9317440a71d4d4c264a5650bf4a90f3c change-id: 20230726-asoc-intel-skylake-remove-deprecated-strncpy-9dbcfc26040c Best regards, -- Justin Stitt