ASoC: add common snd_soc_ret() and use it
authorKuninori Morimoto <kuninori.morimoto.gx@renesas.com>
Wed, 5 Feb 2025 00:16:10 +0000 (00:16 +0000)
committerMark Brown <broonie@kernel.org>
Thu, 6 Feb 2025 17:26:18 +0000 (17:26 +0000)
Each soc-xxx.c is using own snd_xxx_ret(), but we want to share it.
Let's add common snd_soc_ret() for it.

Signed-off-by: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
Link: https://patch.msgid.link/87frkt2qlx.wl-kuninori.morimoto.gx@renesas.com
Signed-off-by: Mark Brown <broonie@kernel.org>
include/sound/soc.h
sound/soc/soc-card.c
sound/soc/soc-component.c
sound/soc/soc-dai.c
sound/soc/soc-link.c
sound/soc/soc-pcm.c
sound/soc/soc-utils.c

index fcdb5adfcd5eccd4d74ee6e52357543cfbc23e36..16e4e488521c0c89453e368a2dd9dea1457b9f44 100644 (file)
@@ -539,6 +539,7 @@ int snd_soc_calc_bclk(int fs, int sample_size, int channels, int tdm_slots);
 int snd_soc_params_to_bclk(const struct snd_pcm_hw_params *parms);
 int snd_soc_tdm_params_to_bclk(const struct snd_pcm_hw_params *params,
                               int tdm_width, int tdm_slots, int slot_multiple);
+int snd_soc_ret(const struct device *dev, int ret, const char *fmt, ...);
 
 /* set runtime hw params */
 static inline int snd_soc_set_runtime_hwparams(struct snd_pcm_substream *substream,
index e6eb71b3010a83fc070f9ad8c560526c92d30efb..235427d69061737fa10bfcd7e2e8ba0e83202444 100644 (file)
 static inline int _soc_card_ret(struct snd_soc_card *card,
                                const char *func, int ret)
 {
-       switch (ret) {
-       case -EPROBE_DEFER:
-       case -ENOTSUPP:
-       case 0:
-               break;
-       default:
-               dev_err(card->dev,
-                       "ASoC: error at %s on %s: %d\n",
-                       func, card->name, ret);
-       }
-
-       return ret;
+       return snd_soc_ret(card->dev, ret,
+                          "at %s() on %s\n", func, card->name);
 }
 
 struct snd_kcontrol *snd_soc_card_get_kcontrol(struct snd_soc_card *soc_card,
index b67ef78f405c3be7f118e4c355e8fcf990e19e6c..25f5e543ae8d37240522357fa242e7bc1c39c8b4 100644 (file)
 #include <sound/soc.h>
 #include <linux/bitops.h>
 
-#define soc_component_ret(dai, ret) _soc_component_ret(dai, __func__, ret, -1)
-#define soc_component_ret_reg_rw(dai, ret, reg) _soc_component_ret(dai, __func__, ret, reg)
-static inline int _soc_component_ret(struct snd_soc_component *component,
-                                    const char *func, int ret, int reg)
-{
-       /* Positive/Zero values are not errors */
-       if (ret >= 0)
-               return ret;
-
-       /* Negative values might be errors */
-       switch (ret) {
-       case -EPROBE_DEFER:
-       case -ENOTSUPP:
-               break;
-       default:
-               if (reg == -1)
-                       dev_err(component->dev,
-                               "ASoC: error at %s on %s: %d\n",
-                               func, component->name, ret);
-               else
-                       dev_err(component->dev,
-                               "ASoC: error at %s on %s for register: [0x%08x] %d\n",
-                               func, component->name, reg, ret);
-       }
+#define soc_component_ret(dai, ret) _soc_component_ret(dai, __func__, ret)
+static inline int _soc_component_ret(struct snd_soc_component *component, const char *func, int ret)
+{
+       return snd_soc_ret(component->dev, ret,
+                          "at %s() on %s\n", func, component->name);
+}
 
-       return ret;
+#define soc_component_ret_reg_rw(dai, ret, reg) _soc_component_ret_reg_rw(dai, __func__, ret, reg)
+static inline int _soc_component_ret_reg_rw(struct snd_soc_component *component,
+                                           const char *func, int ret, int reg)
+{
+       return snd_soc_ret(component->dev, ret,
+                          "at %s() on %s for register: [0x%08x]\n",
+                          func, component->name, reg);
 }
 
 static inline int soc_component_field_shift(struct snd_soc_component *component,
index ca0308f6d41c17f73e87bddb46a8441437fefaf5..7c4c9127e5f3f7f6659767f62ae48bcfe1786137 100644 (file)
 static inline int _soc_dai_ret(const struct snd_soc_dai *dai,
                               const char *func, int ret)
 {
-       /* Positive, Zero values are not errors */
-       if (ret >= 0)
-               return ret;
-
-       /* Negative values might be errors */
-       switch (ret) {
-       case -EPROBE_DEFER:
-       case -ENOTSUPP:
-               break;
-       default:
-               dev_err(dai->dev,
-                       "ASoC: error at %s on %s: %d\n",
-                       func, dai->name, ret);
-       }
-
-       return ret;
+       return snd_soc_ret(dai->dev, ret,
+                          "at %s() on %s\n", func, dai->name);
 }
 
 /*
index 7f1f1bc717e2ceeeee0d375b39e63f39e8ad5a5d..02fd68f2e70289e914ec5760ae4904ae4d18bc4f 100644 (file)
 static inline int _soc_link_ret(struct snd_soc_pcm_runtime *rtd,
                                const char *func, int ret)
 {
-       /* Positive, Zero values are not errors */
-       if (ret >= 0)
-               return ret;
-
-       /* Negative values might be errors */
-       switch (ret) {
-       case -EPROBE_DEFER:
-       case -ENOTSUPP:
-               break;
-       default:
-               dev_err(rtd->dev,
-                       "ASoC: error at %s on %s: %d\n",
-                       func, rtd->dai_link->name, ret);
-       }
-
-       return ret;
+       return snd_soc_ret(rtd->dev, ret,
+                          "at %s() on %s\n", func, rtd->dai_link->name);
 }
 
 /*
index 88b3ad5a255205019e2689d6797fab7143d380cc..a2caa146cac2c6bb59affed378d3bb28a49ba081 100644 (file)
 static inline int _soc_pcm_ret(struct snd_soc_pcm_runtime *rtd,
                               const char *func, int ret)
 {
-       /* Positive, Zero values are not errors */
-       if (ret >= 0)
-               return ret;
-
-       /* Negative values might be errors */
-       switch (ret) {
-       case -EPROBE_DEFER:
-       case -ENOTSUPP:
-               break;
-       default:
-               dev_err(rtd->dev,
-                       "ASoC: error at %s on %s: %d\n",
-                       func, rtd->dai_link->name, ret);
-       }
-
-       return ret;
+       return snd_soc_ret(rtd->dev, ret,
+                          "at %s() on %s\n", func, rtd->dai_link->name);
 }
 
 /* is the current PCM operation for this FE ? */
index aa93e77ac937b0255c5dfa519207693fb560a6d6..e8958158acc11783f629adceb63f163c432593ea 100644 (file)
 #include <sound/pcm_params.h>
 #include <sound/soc.h>
 
+int snd_soc_ret(const struct device *dev, int ret, const char *fmt, ...)
+{
+       struct va_format vaf;
+       va_list args;
+
+       /* Positive, Zero values are not errors */
+       if (ret >= 0)
+               return ret;
+
+       /* Negative values might be errors */
+       switch (ret) {
+       case -EPROBE_DEFER:
+       case -ENOTSUPP:
+               break;
+       default:
+               va_start(args, fmt);
+               vaf.fmt = fmt;
+               vaf.va = &args;
+
+               dev_err(dev, "ASoC error (%d): %pV", ret, &vaf);
+       }
+
+       return ret;
+}
+EXPORT_SYMBOL_GPL(snd_soc_ret);
+
 int snd_soc_calc_frame_size(int sample_size, int channels, int tdm_slots)
 {
        return sample_size * channels * tdm_slots;