From 9e4980896c46ed84d0aa27382e18d1cacb7cb86e Mon Sep 17 00:00:00 2001 From: Srinivas Kandagatla Date: Fri, 15 May 2015 10:38:27 +0100 Subject: ASoC: skip legacy dai naming if dai driver has all the information Original issue is that the id field in the dai is not same as the id in dai_driver when dai driver count == 1. This is due to the legacy dai naming check, which could possibly cause issues if the audio drivers written in assumption that dai->id would be always equal to dai_driver->id. This assumption is true only if the dai driver count is greater than 1, and false if dai driver count is 1. On Qcom Lpass driver we hit such issue while adding support to apq8016. The code path which falls back to legacy naming for cases where num_dai == 1 does not check if there is any valid information in the dai_driver. This patch fixes that by checking if the dai_driver has valid id and name before falling back to legacy dai naming Although the drivers can work around this issue by only using dai->driver->id, but this patch attempts to fix the actual issue. Suggested-by: Lars-Peter Clausen Signed-off-by: Srinivas Kandagatla Acked-by: Kenneth Westfield Signed-off-by: Mark Brown diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c index 2373252..7d028e8 100644 --- a/sound/soc/soc-core.c +++ b/sound/soc/soc-core.c @@ -2599,7 +2599,8 @@ static int snd_soc_register_dais(struct snd_soc_component *component, * the same naming style even though those DAIs are not * component-less anymore. */ - if (count == 1 && legacy_dai_naming) { + if (count == 1 && legacy_dai_naming && + (dai_drv[i].id == 0 || dai_drv[i].name == NULL)) { dai->name = fmt_single_name(dev, &dai->id); } else { dai->name = fmt_multiple_name(dev, &dai_drv[i]); -- cgit v0.10.2 From d6b6c2ca6a2fbbb39051ec1d2763a947e3283683 Mon Sep 17 00:00:00 2001 From: Takashi Iwai Date: Tue, 26 May 2015 14:40:14 +0200 Subject: ASoC: Simplify format_register_str() without stack usages Instead of allocating two string buffers on stack and copying them back, manipulate directly the target string buffer. This simplifies the code well. Signed-off-by: Takashi Iwai Signed-off-by: Mark Brown diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c index 7d028e8..95414a2 100644 --- a/sound/soc/soc-core.c +++ b/sound/soc/soc-core.c @@ -92,30 +92,21 @@ static int format_register_str(struct snd_soc_codec *codec, int wordsize = min_bytes_needed(codec->driver->reg_cache_size) * 2; int regsize = codec->driver->reg_word_size * 2; int ret; - char tmpbuf[len + 1]; - char regbuf[regsize + 1]; - - /* since tmpbuf is allocated on the stack, warn the callers if they - * try to abuse this function */ - WARN_ON(len > 63); /* +2 for ': ' and + 1 for '\n' */ if (wordsize + regsize + 2 + 1 != len) return -EINVAL; - ret = snd_soc_read(codec, reg); - if (ret < 0) { - memset(regbuf, 'X', regsize); - regbuf[regsize] = '\0'; - } else { - snprintf(regbuf, regsize + 1, "%.*x", regsize, ret); - } - - /* prepare the buffer */ - snprintf(tmpbuf, len + 1, "%.*x: %s\n", wordsize, reg, regbuf); - /* copy it back to the caller without the '\0' */ - memcpy(buf, tmpbuf, len); + sprintf(buf, "%.*x: ", wordsize, reg); + buf += wordsize + 2; + ret = snd_soc_read(codec, reg); + if (ret < 0) + memset(buf, 'X', regsize); + else + sprintf(buf, "%.*x", regsize, ret); + buf[regsize] = '\n'; + /* no NUL-termination needed */ return 0; } -- cgit v0.10.2 From 3e0aa8d83bf8e6d414e538cf1046a3a7b48017bc Mon Sep 17 00:00:00 2001 From: Jyri Sarha Date: Tue, 26 May 2015 21:59:05 +0300 Subject: ASoC: core: If component doesn't have of_node use parent's node instead If an ASoC component device does not have a device tree node, use its parent's node instead, when looking for a matching DAI based on a device tree reference. This allows video device drivers to register a separate child device for their ASoC side audio functionality. [And MFDs in general -- broonie] Signed-off-by: Jyri Sarha Signed-off-by: Mark Brown diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c index 95414a2..80b7cf5 100644 --- a/sound/soc/soc-core.c +++ b/sound/soc/soc-core.c @@ -895,12 +895,17 @@ static struct snd_soc_dai *snd_soc_find_dai( { struct snd_soc_component *component; struct snd_soc_dai *dai; + struct device_node *component_of_node; lockdep_assert_held(&client_mutex); /* Find CPU DAI from registered DAIs*/ list_for_each_entry(component, &component_list, list) { - if (dlc->of_node && component->dev->of_node != dlc->of_node) + component_of_node = component->dev->of_node; + if (!component_of_node && component->dev->parent) + component_of_node = component->dev->parent->of_node; + + if (dlc->of_node && component_of_node != dlc->of_node) continue; if (dlc->name && strcmp(component->name, dlc->name)) continue; @@ -3480,11 +3485,16 @@ static int snd_soc_get_dai_name(struct of_phandle_args *args, const char **dai_name) { struct snd_soc_component *pos; + struct device_node *component_of_node; int ret = -EPROBE_DEFER; mutex_lock(&client_mutex); list_for_each_entry(pos, &component_list, list) { - if (pos->dev->of_node != args->np) + component_of_node = pos->dev->of_node; + if (!component_of_node && pos->dev->parent) + component_of_node = pos->dev->parent->of_node; + + if (component_of_node != args->np) continue; if (pos->driver->of_xlate_dai_name) { -- cgit v0.10.2