From: hariconscious@gmail.com
To: lgirdwood@gmail.com, broonie@kernel.org, matthias.bgg@gmail.com,
angelogioacchino.delregno@collabora.com
Cc: perex@perex.cz, tiwai@suse.com, khalid@kernel.org,
shuah@kernel.org, david.hunter.linux@gmail.com,
linux-sound@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-arm-kernel@lists.infradead.org,
linux-mediatek@lists.infradead.org,
HariKrishna Sagala <hariconscious@gmail.com>
Subject: [PATCH] ASoC: mediatek: mt8195: optimize property formatting error handling by using scnprintf()
Date: Wed, 26 Nov 2025 11:05:02 +0530 [thread overview]
Message-ID: <20251126053500.56353-3-hariconscious@gmail.com> (raw)
From: HariKrishna Sagala <hariconscious@gmail.com>
Replace snprintf() with scnprintf() when constructing the property
and remove negative return error handling as scnprintf() returns the
actual number of bytes written to buffer.
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>
---
This patch optimizes the error handling part of property formatting
using the scnrpintf().
Removed the error check ret < 0 as scnprintf() doesn't return the
negative value as per contract.
https://www.kernel.org/doc/html/latest/core-api/kernel-api.html#c.scnprintf
Thank you.
sound/soc/mediatek/mt8195/mt8195-dai-etdm.c | 44 ++++++---------------
1 file changed, 12 insertions(+), 32 deletions(-)
diff --git a/sound/soc/mediatek/mt8195/mt8195-dai-etdm.c b/sound/soc/mediatek/mt8195/mt8195-dai-etdm.c
index fd4f9f8f032d..77c58c9ec3e2 100644
--- a/sound/soc/mediatek/mt8195/mt8195-dai-etdm.c
+++ b/sound/soc/mediatek/mt8195/mt8195-dai-etdm.c
@@ -2652,14 +2652,9 @@ static void mt8195_dai_etdm_parse_of(struct mtk_base_afe *afe)
etdm_data = afe_priv->dai_priv[dai_id];
- ret = snprintf(prop, sizeof(prop),
- "mediatek,%s-mclk-always-on-rate",
- of_afe_etdms[i].name);
- if (ret < 0) {
- dev_info(afe->dev, "%s snprintf err=%d\n",
- __func__, ret);
- return;
- }
+ scnprintf(prop, sizeof(prop),
+ "mediatek,%s-mclk-always-on-rate",
+ of_afe_etdms[i].name);
ret = of_property_read_u32(of_node, prop, &sel);
if (ret == 0) {
etdm_data->mclk_dir = SND_SOC_CLOCK_OUT;
@@ -2668,24 +2663,14 @@ static void mt8195_dai_etdm_parse_of(struct mtk_base_afe *afe)
__func__, sel);
}
- ret = snprintf(prop, sizeof(prop),
- "mediatek,%s-multi-pin-mode",
- of_afe_etdms[i].name);
- if (ret < 0) {
- dev_info(afe->dev, "%s snprintf err=%d\n",
- __func__, ret);
- return;
- }
+ scnprintf(prop, sizeof(prop),
+ "mediatek,%s-multi-pin-mode",
+ of_afe_etdms[i].name);
etdm_data->data_mode = of_property_read_bool(of_node, prop);
- ret = snprintf(prop, sizeof(prop),
- "mediatek,%s-cowork-source",
- of_afe_etdms[i].name);
- if (ret < 0) {
- dev_info(afe->dev, "%s snprintf err=%d\n",
- __func__, ret);
- return;
- }
+ scnprintf(prop, sizeof(prop),
+ "mediatek,%s-cowork-source",
+ of_afe_etdms[i].name);
ret = of_property_read_u32(of_node, prop, &sel);
if (ret == 0) {
if (sel >= MT8195_AFE_IO_ETDM_NUM) {
@@ -2707,14 +2692,9 @@ static void mt8195_dai_etdm_parse_of(struct mtk_base_afe *afe)
dai_id = ETDM_TO_DAI_ID(i);
etdm_data = afe_priv->dai_priv[dai_id];
- ret = snprintf(prop, sizeof(prop),
- "mediatek,%s-chn-disabled",
- of_afe_etdms[i].name);
- if (ret < 0) {
- dev_info(afe->dev, "%s snprintf err=%d\n",
- __func__, ret);
- return;
- }
+ scnprintf(prop, sizeof(prop),
+ "mediatek,%s-chn-disabled",
+ of_afe_etdms[i].name);
ret = of_property_read_variable_u8_array(of_node, prop,
disable_chn,
1, max_chn);
base-commit: 30f09200cc4aefbd8385b01e41bde2e4565a6f0e
--
2.43.0
reply other threads:[~2025-11-26 5:41 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20251126053500.56353-3-hariconscious@gmail.com \
--to=hariconscious@gmail.com \
--cc=angelogioacchino.delregno@collabora.com \
--cc=broonie@kernel.org \
--cc=david.hunter.linux@gmail.com \
--cc=khalid@kernel.org \
--cc=lgirdwood@gmail.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mediatek@lists.infradead.org \
--cc=linux-sound@vger.kernel.org \
--cc=matthias.bgg@gmail.com \
--cc=perex@perex.cz \
--cc=shuah@kernel.org \
--cc=tiwai@suse.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