Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

ASoC: add common snd_soc_ret() and use it

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>

authored by

Kuninori Morimoto and committed by
Mark Brown
943116ba dabbd325

+47 -84
+1
include/sound/soc.h
··· 539 539 int snd_soc_params_to_bclk(const struct snd_pcm_hw_params *parms); 540 540 int snd_soc_tdm_params_to_bclk(const struct snd_pcm_hw_params *params, 541 541 int tdm_width, int tdm_slots, int slot_multiple); 542 + int snd_soc_ret(const struct device *dev, int ret, const char *fmt, ...); 542 543 543 544 /* set runtime hw params */ 544 545 static inline int snd_soc_set_runtime_hwparams(struct snd_pcm_substream *substream,
+2 -12
sound/soc/soc-card.c
··· 15 15 static inline int _soc_card_ret(struct snd_soc_card *card, 16 16 const char *func, int ret) 17 17 { 18 - switch (ret) { 19 - case -EPROBE_DEFER: 20 - case -ENOTSUPP: 21 - case 0: 22 - break; 23 - default: 24 - dev_err(card->dev, 25 - "ASoC: error at %s on %s: %d\n", 26 - func, card->name, ret); 27 - } 28 - 29 - return ret; 18 + return snd_soc_ret(card->dev, ret, 19 + "at %s() on %s\n", func, card->name); 30 20 } 31 21 32 22 struct snd_kcontrol *snd_soc_card_get_kcontrol(struct snd_soc_card *soc_card,
+12 -24
sound/soc/soc-component.c
··· 13 13 #include <sound/soc.h> 14 14 #include <linux/bitops.h> 15 15 16 - #define soc_component_ret(dai, ret) _soc_component_ret(dai, __func__, ret, -1) 17 - #define soc_component_ret_reg_rw(dai, ret, reg) _soc_component_ret(dai, __func__, ret, reg) 18 - static inline int _soc_component_ret(struct snd_soc_component *component, 19 - const char *func, int ret, int reg) 16 + #define soc_component_ret(dai, ret) _soc_component_ret(dai, __func__, ret) 17 + static inline int _soc_component_ret(struct snd_soc_component *component, const char *func, int ret) 20 18 { 21 - /* Positive/Zero values are not errors */ 22 - if (ret >= 0) 23 - return ret; 19 + return snd_soc_ret(component->dev, ret, 20 + "at %s() on %s\n", func, component->name); 21 + } 24 22 25 - /* Negative values might be errors */ 26 - switch (ret) { 27 - case -EPROBE_DEFER: 28 - case -ENOTSUPP: 29 - break; 30 - default: 31 - if (reg == -1) 32 - dev_err(component->dev, 33 - "ASoC: error at %s on %s: %d\n", 34 - func, component->name, ret); 35 - else 36 - dev_err(component->dev, 37 - "ASoC: error at %s on %s for register: [0x%08x] %d\n", 38 - func, component->name, reg, ret); 39 - } 40 - 41 - return ret; 23 + #define soc_component_ret_reg_rw(dai, ret, reg) _soc_component_ret_reg_rw(dai, __func__, ret, reg) 24 + static inline int _soc_component_ret_reg_rw(struct snd_soc_component *component, 25 + const char *func, int ret, int reg) 26 + { 27 + return snd_soc_ret(component->dev, ret, 28 + "at %s() on %s for register: [0x%08x]\n", 29 + func, component->name, reg); 42 30 } 43 31 44 32 static inline int soc_component_field_shift(struct snd_soc_component *component,
+2 -16
sound/soc/soc-dai.c
··· 14 14 static inline int _soc_dai_ret(const struct snd_soc_dai *dai, 15 15 const char *func, int ret) 16 16 { 17 - /* Positive, Zero values are not errors */ 18 - if (ret >= 0) 19 - return ret; 20 - 21 - /* Negative values might be errors */ 22 - switch (ret) { 23 - case -EPROBE_DEFER: 24 - case -ENOTSUPP: 25 - break; 26 - default: 27 - dev_err(dai->dev, 28 - "ASoC: error at %s on %s: %d\n", 29 - func, dai->name, ret); 30 - } 31 - 32 - return ret; 17 + return snd_soc_ret(dai->dev, ret, 18 + "at %s() on %s\n", func, dai->name); 33 19 } 34 20 35 21 /*
+2 -16
sound/soc/soc-link.c
··· 12 12 static inline int _soc_link_ret(struct snd_soc_pcm_runtime *rtd, 13 13 const char *func, int ret) 14 14 { 15 - /* Positive, Zero values are not errors */ 16 - if (ret >= 0) 17 - return ret; 18 - 19 - /* Negative values might be errors */ 20 - switch (ret) { 21 - case -EPROBE_DEFER: 22 - case -ENOTSUPP: 23 - break; 24 - default: 25 - dev_err(rtd->dev, 26 - "ASoC: error at %s on %s: %d\n", 27 - func, rtd->dai_link->name, ret); 28 - } 29 - 30 - return ret; 15 + return snd_soc_ret(rtd->dev, ret, 16 + "at %s() on %s\n", func, rtd->dai_link->name); 31 17 } 32 18 33 19 /*
+2 -16
sound/soc/soc-pcm.c
··· 30 30 static inline int _soc_pcm_ret(struct snd_soc_pcm_runtime *rtd, 31 31 const char *func, int ret) 32 32 { 33 - /* Positive, Zero values are not errors */ 34 - if (ret >= 0) 35 - return ret; 36 - 37 - /* Negative values might be errors */ 38 - switch (ret) { 39 - case -EPROBE_DEFER: 40 - case -ENOTSUPP: 41 - break; 42 - default: 43 - dev_err(rtd->dev, 44 - "ASoC: error at %s on %s: %d\n", 45 - func, rtd->dai_link->name, ret); 46 - } 47 - 48 - return ret; 33 + return snd_soc_ret(rtd->dev, ret, 34 + "at %s() on %s\n", func, rtd->dai_link->name); 49 35 } 50 36 51 37 /* is the current PCM operation for this FE ? */
+26
sound/soc/soc-utils.c
··· 15 15 #include <sound/pcm_params.h> 16 16 #include <sound/soc.h> 17 17 18 + int snd_soc_ret(const struct device *dev, int ret, const char *fmt, ...) 19 + { 20 + struct va_format vaf; 21 + va_list args; 22 + 23 + /* Positive, Zero values are not errors */ 24 + if (ret >= 0) 25 + return ret; 26 + 27 + /* Negative values might be errors */ 28 + switch (ret) { 29 + case -EPROBE_DEFER: 30 + case -ENOTSUPP: 31 + break; 32 + default: 33 + va_start(args, fmt); 34 + vaf.fmt = fmt; 35 + vaf.va = &args; 36 + 37 + dev_err(dev, "ASoC error (%d): %pV", ret, &vaf); 38 + } 39 + 40 + return ret; 41 + } 42 + EXPORT_SYMBOL_GPL(snd_soc_ret); 43 + 18 44 int snd_soc_calc_frame_size(int sample_size, int channels, int tdm_slots) 19 45 { 20 46 return sample_size * channels * tdm_slots;