Message ID | 20230727-sound-soc-fsl-v1-1-4fc0ed7e0366@google.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:918b:0:b0:3e4:2afc:c1 with SMTP id s11csp48700vqg; Thu, 27 Jul 2023 15:34:26 -0700 (PDT) X-Google-Smtp-Source: APBJJlG0ebHQ3U597wa9DuX97yzo0LHy7aqfzLCHt3UitrAmLBdRmRbp2ocx5enEtKXBrZN/YmhJ X-Received: by 2002:a05:6512:340d:b0:4fe:819:b0ed with SMTP id i13-20020a056512340d00b004fe0819b0edmr350898lfr.46.1690497266628; Thu, 27 Jul 2023 15:34:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690497266; cv=none; d=google.com; s=arc-20160816; b=KotUxrcQ83QlvvCpmjrGL5FjlDLh6/z0HSOtRUyJNl0ubJmZCMH/tsDAWYQo4ZmMFY 4ZTvzScvftKfbZAeT5oFoLp8crroT9a+vxPtHr5o1HjiuqO+UG0NggW0/6bWv2/rCZVI ysso+GS1V43RMM/1scDQVuU1a+g9tO0XrO4oGwq11YLVsKon6gPeRiNlI5aIyw3bPeuU CEkkBvwcAVwzf7tPa/YnGETBEag/VNO/e3a478dpekyaEqkIQOLgplAVccpCerp+eijK Ql4ywWl0nO0yzZ/nInmecYepQOg055l9vxuJyovjiYJbGWvQdLXoxPcgRQuFW5/AlYPO AVwQ== 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:mime-version:date :dkim-signature; bh=Y8k3rjyBf0fojb2EPgR8sOqghPhE9G594McR+LDMAVU=; fh=rB/1zmeWm3oDFGkGbzCvrMTCfsGqMpqFe8I+xAYii28=; b=QnfsbsjW99GTubFRZzNgi2I1T7Rn7sMm2NEMbskghgfBazxqop4MuM3XnfEO7Bkp1H iEwRsdWm6K8bEWnv2TXinACIScF/MI1I7zHED5ZICRFWLg1Ao1Nf0u4nzeQMBVLm9mss S8PcMGji7VxRp5IteA7QRV6419B5za0jCEbfw2YS5knIEMgk6U0FMB/ysu4CaZqaKe8G Ps/tphRvYigEWczJXDoOAhUpTMcI0GdANS1JJ5jQgUERDm2Fx8khtWz1/WkxBDWPonH2 ZnXyF9/h5O0Onnk5yGEHjYG2pv2CnMu00cey0M/pDLEiazGwDdQEF5kxZkR0iTpJS+d9 Nueg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=D8uvkEu4; 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: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id q4-20020aa7d444000000b005223b462b62si1550483edr.639.2023.07.27.15.33.43; Thu, 27 Jul 2023 15:34:26 -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=D8uvkEu4; 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 S232217AbjG0W06 (ORCPT <rfc822;kloczko.tomasz@gmail.com> + 99 others); Thu, 27 Jul 2023 18:26:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44512 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231161AbjG0W0y (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Thu, 27 Jul 2023 18:26:54 -0400 Received: from mail-oa1-x49.google.com (mail-oa1-x49.google.com [IPv6:2001:4860:4864:20::49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 331A0F0 for <linux-kernel@vger.kernel.org>; Thu, 27 Jul 2023 15:26:53 -0700 (PDT) Received: by mail-oa1-x49.google.com with SMTP id 586e51a60fabf-1bb91fb58f2so2681977fac.2 for <linux-kernel@vger.kernel.org>; Thu, 27 Jul 2023 15:26:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1690496812; x=1691101612; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=Y8k3rjyBf0fojb2EPgR8sOqghPhE9G594McR+LDMAVU=; b=D8uvkEu4/smEbpJTeMq90Bq5KeP1e5xIGLkQWzLEkXeN8AQU0NkbUy0zuQd+TUDBSx k3+CzER9oXoVsUCZvuh9ZIN4VObo+hEN4Z+y+rd2eVuE4GcNw/Ge5AGR5mdVOQA76bwG RNF1S8VERGMdefiESkMUi5anwpf8ky6b04huvSD7HuzDBWA7L1zc9uqa9vXivFgWWNuz Iho8dePREXhDWuWuG/4dhsZjV+1VOiSIAAkrXITi6ge7gaLlbxA3VbqTOo3LaknExZlo ubzzY+BjDM4VT64nFYkLUAMdC3XqpY8qwN3NTMwuL/P/ctD0iXxag6tLvhN2RzQTBur3 Dk+Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690496812; x=1691101612; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=Y8k3rjyBf0fojb2EPgR8sOqghPhE9G594McR+LDMAVU=; b=ewucLlnjTv1uwSdV9YZXHHbDIOo1OOEMvsHmuy2O3uMlX8M2JoteU7Qj/2lEE2TsE1 dRUe8CSYKoNTfa+WvpNdOZN3E0Q0+WMJVXfh5+iTsMcnFgsc4aUf3P1xiG6n86lU2kmE 1sBHCoBhQjdXyl6EQIz4oSV0i2x12xE3tj1nUTbluwjfp0qEmcwirETMt/yo8HZyrSVT ggijOnNheflkB0KOWaP7HHXZmx3o+sImAxkjtqpWYaPOsuyRAcXEL9VEDeh6gn6IfIg6 sjKbUbMiQukXogAzZJLbnn/T7wvHFJW7Z7CHYxUkfVEtpaYM1oql5ZjZDWth+/IaOiHY XPCw== X-Gm-Message-State: ABy/qLZl9hBoEw8DP/BvkNpqzYQNH97ktoTEIHgNH5lGPLO+YEK7F/cT ewKQOR0E+e2oGX1wTS9wMjvPBUYvAt1ewFLrPQ== X-Received: from jstitt-linux1.c.googlers.com ([fda3:e722:ac3:cc00:2b:ff92:c0a8:23b5]) (user=justinstitt job=sendgmr) by 2002:a05:6870:5b0d:b0:1bb:785d:7436 with SMTP id ds13-20020a0568705b0d00b001bb785d7436mr961489oab.10.1690496812558; Thu, 27 Jul 2023 15:26:52 -0700 (PDT) Date: Thu, 27 Jul 2023 22:26:41 +0000 Mime-Version: 1.0 X-B4-Tracking: v=1; b=H4sIACDvwmQC/6tWKk4tykwtVrJSqFYqSi3LLM7MzwNyDHUUlJIzE vPSU3UzU4B8JSMDI2MDcyNz3eL80rwUIJmsm1aco2uSlmxqamaZYm5umKoE1FNQlJqWWQE2Lzq 2thYAMKv4Nl8AAAA= X-Developer-Key: i=justinstitt@google.com; a=ed25519; pk=tC3hNkJQTpNX/gLKxTNQKDmiQl6QjBNCGKJINqAdJsE= X-Developer-Signature: v=1; a=ed25519-sha256; t=1690496811; l=2165; i=justinstitt@google.com; s=20230717; h=from:subject:message-id; bh=xEnu5xQr3cyZZvwQfMubiCiEuFBVC3Uk0Y9589JdUxw=; b=hmOqBlRYlYKaC3Yr5Zy8g3r9+9++L/pbK5ub/HORCIbyUCI0NGjnrADamWXFeaNB3CVKyg4I+ L5n1tag1LikDFx+k0EHDanF323xxdNABjjW0T5SEFnG7vM0e2joX6sH X-Mailer: b4 0.12.3 Message-ID: <20230727-sound-soc-fsl-v1-1-4fc0ed7e0366@google.com> Subject: [PATCH] ASoC: fsl_micfil: refactor deprecated strncpy From: Justin Stitt <justinstitt@google.com> To: Shengjiu Wang <shengjiu.wang@gmail.com>, Xiubo Li <Xiubo.Lee@gmail.com>, Fabio Estevam <festevam@gmail.com>, Nicolin Chen <nicoleotsuka@gmail.com>, Liam Girdwood <lgirdwood@gmail.com>, Mark Brown <broonie@kernel.org>, Jaroslav Kysela <perex@perex.cz>, Takashi Iwai <tiwai@suse.com> Cc: alsa-devel@alsa-project.org, linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org, Kees Cook <keescook@chromium.org>, Justin Stitt <justinstitt@google.com> 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: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1772614861762872588 X-GMAIL-MSGID: 1772614861762872588 |
Series |
ASoC: fsl_micfil: refactor deprecated strncpy
|
|
Commit Message
Justin Stitt
July 27, 2023, 10:26 p.m. UTC
`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_ always the case for `strncpy`!
In this case, though, there was great care taken to ensure that the
destination buffer would be NUL-terminated through the use of `len - 1`
ensuring that the previously zero-initialized buffer would not overwrite
the last NUL byte. This means that there's no bug here.
However, `strscpy` will add a mandatory NUL byte to the destination
buffer as promised by the following `strscpy` implementation [3]:
| /* Hit buffer length without finding a NUL; force NUL-termination. */
| if (res)
| dest[res-1] = '\0';
This means we can lose the `- 1` which clears up whats happening here.
All the while, we get one step closer to eliminating the ambiguous
`strncpy` api in favor of its less ambiguous replacement like `strscpy`,
`strscpy_pad`, `strtomem` and `strtomem_pad` amongst others.
[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
[3]: https://elixir.bootlin.com/linux/v6.3/source/lib/string.c#L183
Link: https://github.com/KSPP/linux/issues/90
Signed-off-by: Justin Stitt <justinstitt@google.com>
---
sound/soc/fsl/fsl_micfil.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
---
base-commit: 57012c57536f8814dec92e74197ee96c3498d24e
change-id: 20230727-sound-soc-fsl-4fc5569d771e
Best regards,
--
Justin Stitt <justinstitt@google.com>
Comments
On Thu, 27 Jul 2023 22:26:41 +0000, Justin Stitt wrote: > `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_ always the case for `strncpy`! > > In this case, though, there was great care taken to ensure that the > destination buffer would be NUL-terminated through the use of `len - 1` > ensuring that the previously zero-initialized buffer would not overwrite > the last NUL byte. This means that there's no bug here. > > [...] Applied to https://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git for-next Thanks! [1/1] ASoC: fsl_micfil: refactor deprecated strncpy commit: 7eb10bfbbae6025cb7b4bba3db0c1281eac05862 All being well this means that it will be integrated into the linux-next tree (usually sometime in the next 24 hours) and sent to Linus during the next merge window (or sooner if it is a bug fix), however if problems are discovered then the patch may be dropped or reverted. You may get further e-mails resulting from automated or manual testing and review of the tree, please engage with people reporting problems and send followup patches addressing any issues that are reported if needed. If any updates are required or you are submitting further changes they should be sent as incremental updates against current git, existing patches will not be replaced. Please add any relevant lists and maintainers to the CCs when replying to this mail. Thanks, Mark
diff --git a/sound/soc/fsl/fsl_micfil.c b/sound/soc/fsl/fsl_micfil.c index 3f08082a55be..fe28b27e50d0 100644 --- a/sound/soc/fsl/fsl_micfil.c +++ b/sound/soc/fsl/fsl_micfil.c @@ -1044,7 +1044,7 @@ static int fsl_micfil_probe(struct platform_device *pdev) return -ENOMEM; micfil->pdev = pdev; - strncpy(micfil->name, np->name, sizeof(micfil->name) - 1); + strscpy(micfil->name, np->name, sizeof(micfil->name)); micfil->soc = of_device_get_match_data(&pdev->dev);