The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: Sakari Ailus <sakari.ailus@linux.intel.com>
To: hariconscious@gmail.com
Cc: cezary.rojewski@intel.com, liam.r.girdwood@linux.intel.com,
	peter.ujfalusi@linux.intel.com, yung-chuan.liao@linux.intel.com,
	ranjani.sridharan@linux.intel.com, kai.vehmanen@linux.intel.com,
	pierre-louis.bossart@linux.dev, broonie@kernel.org,
	perex@perex.cz, tiwai@suse.com,
	amadeuszx.slawinski@linux.intel.com, khalid@kernel.org,
	shuah@kernel.org, david.hunter.linux@gmail.com,
	linux-sound@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] ASoC: Intel: avs: Replace snprintf() with scnprintf()
Date: Wed, 12 Nov 2025 15:37:49 +0200	[thread overview]
Message-ID: <aRSNrXnmPTElmx5H@kekkonen.localdomain> (raw)
In-Reply-To: <20251112120235.54328-2-hariconscious@gmail.com>

Hi HariKrishna,

On Wed, Nov 12, 2025 at 05:32:35PM +0530, hariconscious@gmail.com wrote:
> From: HariKrishna Sagala <hariconscious@gmail.com>
> 
> As per the C99 standard snprintf() returns the length of the data
> that *would have been* written if there were enough space for it.
> It's generally considered safer to use the scnprintf() variant.

Not only that, but the code assumes scnprintf() behaviour to function
correctly. This should be reflected in the commit message. I.e. this is a
bugfix and should probably be cc'd to stable. Could you provide a Fixes:
tag as well?

The change itself seems fine to me, apart from indentation.

> 
> Link: https://github.com/KSPP/linux/issues/105
> Signed-off-by: HariKrishna Sagala <hariconscious@gmail.com>
> ---
> This patch replaces snprintf() varaint with scnprintf() in
> scenario to know the actual length of the data rather than *would
> have been* written data of snprintf().
> No functional changes intended.
> Reference Links:
> https://lwn.net/Articles/69419/
> https://www.kernel.org/doc/html/latest/core-api/kernel-api.html#c.snprintf
> 
> Note:
> Compile & boot tested with necessary config parameters.
> Other areas of AVS uses scnprintf() variant.
> 
>  sound/soc/intel/avs/debugfs.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/sound/soc/intel/avs/debugfs.c b/sound/soc/intel/avs/debugfs.c
> index 3534de46f9e4..100b95bfcd78 100644
> --- a/sound/soc/intel/avs/debugfs.c
> +++ b/sound/soc/intel/avs/debugfs.c
> @@ -119,7 +119,7 @@ static ssize_t probe_points_read(struct file *file, char __user *to, size_t coun
>  	}
>  
>  	for (i = 0; i < num_desc; i++) {
> -		ret = snprintf(buf + len, PAGE_SIZE - len,
> +		ret = scnprintf(buf + len, PAGE_SIZE - len,
>  			       "Id: %#010x  Purpose: %d  Node id: %#x\n",
>  			       desc[i].id.value, desc[i].purpose, desc[i].node_id.val);
>  		if (ret < 0)
> 
> base-commit: 24172e0d79900908cf5ebf366600616d29c9b417

-- 
Kind regards,

Sakari Ailus

  reply	other threads:[~2025-11-12 13:37 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-11-12 12:02 [PATCH] ASoC: Intel: avs: Replace snprintf() with scnprintf() hariconscious
2025-11-12 13:37 ` Sakari Ailus [this message]
2025-11-12 13:50 ` David Laight
2025-11-12 15:06   ` Cezary Rojewski

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=aRSNrXnmPTElmx5H@kekkonen.localdomain \
    --to=sakari.ailus@linux.intel.com \
    --cc=amadeuszx.slawinski@linux.intel.com \
    --cc=broonie@kernel.org \
    --cc=cezary.rojewski@intel.com \
    --cc=david.hunter.linux@gmail.com \
    --cc=hariconscious@gmail.com \
    --cc=kai.vehmanen@linux.intel.com \
    --cc=khalid@kernel.org \
    --cc=liam.r.girdwood@linux.intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-sound@vger.kernel.org \
    --cc=perex@perex.cz \
    --cc=peter.ujfalusi@linux.intel.com \
    --cc=pierre-louis.bossart@linux.dev \
    --cc=ranjani.sridharan@linux.intel.com \
    --cc=shuah@kernel.org \
    --cc=tiwai@suse.com \
    --cc=yung-chuan.liao@linux.intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox