mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: hariconscious@gmail.com
To: 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
Cc: perex@perex.cz, tiwai@suse.com,
	amadeuszx.slawinski@linux.intel.com,
	sakari.ailus@linux.intel.com, khalid@kernel.org,
	shuah@kernel.org, david.hunter.linux@gmail.com,
	linux-sound@vger.kernel.org, linux-kernel@vger.kernel.org,
	HariKrishna Sagala <hariconscious@gmail.com>
Subject: [PATCH v3] ASoC: Intel: avs: Replace snprintf() with scnprintf()
Date: Thu, 13 Nov 2025 19:56:38 +0530	[thread overview]
Message-ID: <20251113142637.259737-2-hariconscious@gmail.com> (raw)

From: HariKrishna Sagala <hariconscious@gmail.com>

snprintf() as defined by the C99 standard,returns the
number of characters that *would have been* written if
enough space were available.Use scnprintf() that returns
the actual number of characters written.

Link: https://github.com/KSPP/linux/issues/105
Signed-off-by: HariKrishna Sagala <hariconscious@gmail.com>
---
Thank you all for the valuable feedback and suggestions.

This patch updates usage of snprintf() with scnprintf(). 
As in accordance with the C99 standard, snprintf() returns
the number of characters that would have been written if
enough space were available.With scnprintf(),the return value
reflects the actual number of characters written.
Change log:
V3:
Dropped the Fixes, stable tag & updated the commit message.
scnprintf doesn't return the negative values as per the contract.
Hence removed the check of ret < 0 as it is unreachable.
https://www.kernel.org/doc/html/latest/core-api/kernel-api.html#c.scnprintf
V2:
https://lore.kernel.org/all/20251112181851.13450-1-hariconscious@gmail.com/
V1:
https://lore.kernel.org/all/20251112120235.54328-2-hariconscious@gmail.com/

 sound/soc/intel/avs/debugfs.c | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)

diff --git a/sound/soc/intel/avs/debugfs.c b/sound/soc/intel/avs/debugfs.c
index 3534de46f9e4..d224b25323be 100644
--- a/sound/soc/intel/avs/debugfs.c
+++ b/sound/soc/intel/avs/debugfs.c
@@ -119,16 +119,13 @@ 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,
-			       "Id: %#010x  Purpose: %d  Node id: %#x\n",
-			       desc[i].id.value, desc[i].purpose, desc[i].node_id.val);
-		if (ret < 0)
-			goto free_desc;
+		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);
 		len += ret;
 	}
 
 	ret = simple_read_from_buffer(to, count, ppos, buf, len);
-free_desc:
 	kfree(desc);
 exit:
 	kfree(buf);

base-commit: 24172e0d79900908cf5ebf366600616d29c9b417
-- 
2.43.0


             reply	other threads:[~2025-11-13 14:27 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-11-13 14:26 hariconscious [this message]
2025-11-21 21:27 ` Mark Brown

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=20251113142637.259737-2-hariconscious@gmail.com \
    --to=hariconscious@gmail.com \
    --cc=amadeuszx.slawinski@linux.intel.com \
    --cc=broonie@kernel.org \
    --cc=cezary.rojewski@intel.com \
    --cc=david.hunter.linux@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=sakari.ailus@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

all inboxes | Powered by JetHome®