]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
ASoC: mediatek: mt8195: optimize property formatting error handling by using scnprintf()
authorHariKrishna Sagala <hariconscious@gmail.com>
Fri, 12 Dec 2025 04:44:09 +0000 (10:14 +0530)
committerMark Brown <broonie@kernel.org>
Sun, 14 Dec 2025 10:37:32 +0000 (19:37 +0900)
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>
Link: https://patch.msgid.link/20251212044408.1286-2-hariconscious@gmail.com
Signed-off-by: Mark Brown <broonie@kernel.org>
sound/soc/mediatek/mt8195/mt8195-dai-etdm.c

index 723cab01e72e2f9514aaec731a388cfa02ca8910..5dcc8ed26e0096636b9eea622250d30a80af2f14 100644 (file)
@@ -2651,14 +2651,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;
@@ -2667,24 +2662,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) {
@@ -2706,14 +2691,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);