ASoC: soc-core.c: fixup snd_soc_of_get_dai_link_cpus()

Merge series from Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>:

Current ASoC has fixup both snd_soc_of_get_dai_link_cpus/codecs().
I guess cpu was copied from codec, but it is using "codec" naming everwhere
in "cpu" function. It is strange, and thus, error case will be issue
(It should call cpu function instead of codec).

This patch tidyup it, and try to cleanup.
[1/2] is for bug-fix,
[2/2] is for new feature.
This commit is contained in:
Mark Brown 2022-06-30 16:09:32 +01:00
commit f3762ddfa2
No known key found for this signature in database
GPG Key ID: 24D68B725D5487D0
1 changed files with 73 additions and 69 deletions

View File

@ -3303,6 +3303,61 @@ int snd_soc_of_get_dai_name(struct device_node *of_node,
}
EXPORT_SYMBOL_GPL(snd_soc_of_get_dai_name);
static void __snd_soc_of_put_component(struct snd_soc_dai_link_component *component)
{
if (component->of_node) {
of_node_put(component->of_node);
component->of_node = NULL;
}
}
static int __snd_soc_of_get_dai_link_component_alloc(
struct device *dev, struct device_node *of_node,
struct snd_soc_dai_link_component **ret_component,
int *ret_num)
{
struct snd_soc_dai_link_component *component;
int num;
/* Count the number of CPUs/CODECs */
num = of_count_phandle_with_args(of_node, "sound-dai", "#sound-dai-cells");
if (num <= 0) {
if (num == -ENOENT)
dev_err(dev, "No 'sound-dai' property\n");
else
dev_err(dev, "Bad phandle in 'sound-dai'\n");
return num;
}
component = devm_kcalloc(dev, num, sizeof(*component), GFP_KERNEL);
if (!component)
return -ENOMEM;
*ret_component = component;
*ret_num = num;
return 0;
}
static int __snd_soc_of_get_dai_link_component_parse(
struct device_node *of_node,
struct snd_soc_dai_link_component *component, int index)
{
struct of_phandle_args args;
int ret;
ret = of_parse_phandle_with_args(of_node, "sound-dai", "#sound-dai-cells",
index, &args);
if (ret)
return ret;
ret = snd_soc_get_dai_name(&args, &component->dai_name);
if (ret < 0)
return ret;
component->of_node = args.np;
return 0;
}
/*
* snd_soc_of_put_dai_link_codecs - Dereference device nodes in the codecs array
* @dai_link: DAI link
@ -3314,12 +3369,8 @@ void snd_soc_of_put_dai_link_codecs(struct snd_soc_dai_link *dai_link)
struct snd_soc_dai_link_component *component;
int index;
for_each_link_codecs(dai_link, index, component) {
if (!component->of_node)
break;
of_node_put(component->of_node);
component->of_node = NULL;
}
for_each_link_codecs(dai_link, index, component)
__snd_soc_of_put_component(component);
}
EXPORT_SYMBOL_GPL(snd_soc_of_put_dai_link_codecs);
@ -3341,41 +3392,19 @@ int snd_soc_of_get_dai_link_codecs(struct device *dev,
struct device_node *of_node,
struct snd_soc_dai_link *dai_link)
{
struct of_phandle_args args;
struct snd_soc_dai_link_component *component;
char *name;
int index, num_codecs, ret;
int index, ret;
/* Count the number of CODECs */
name = "sound-dai";
num_codecs = of_count_phandle_with_args(of_node, name,
"#sound-dai-cells");
if (num_codecs <= 0) {
if (num_codecs == -ENOENT)
dev_err(dev, "No 'sound-dai' property\n");
else
dev_err(dev, "Bad phandle in 'sound-dai'\n");
return num_codecs;
}
component = devm_kcalloc(dev,
num_codecs, sizeof(*component),
GFP_KERNEL);
if (!component)
return -ENOMEM;
dai_link->codecs = component;
dai_link->num_codecs = num_codecs;
ret = __snd_soc_of_get_dai_link_component_alloc(dev, of_node,
&dai_link->codecs, &dai_link->num_codecs);
if (ret < 0)
return ret;
/* Parse the list */
for_each_link_codecs(dai_link, index, component) {
ret = of_parse_phandle_with_args(of_node, name,
"#sound-dai-cells",
index, &args);
ret = __snd_soc_of_get_dai_link_component_parse(of_node, component, index);
if (ret)
goto err;
component->of_node = args.np;
ret = snd_soc_get_dai_name(&args, &component->dai_name);
if (ret < 0)
goto err;
}
return 0;
err:
@ -3397,12 +3426,8 @@ void snd_soc_of_put_dai_link_cpus(struct snd_soc_dai_link *dai_link)
struct snd_soc_dai_link_component *component;
int index;
for_each_link_cpus(dai_link, index, component) {
if (!component->of_node)
break;
of_node_put(component->of_node);
component->of_node = NULL;
}
for_each_link_cpus(dai_link, index, component)
__snd_soc_of_put_component(component);
}
EXPORT_SYMBOL_GPL(snd_soc_of_put_dai_link_cpus);
@ -3421,45 +3446,24 @@ int snd_soc_of_get_dai_link_cpus(struct device *dev,
struct device_node *of_node,
struct snd_soc_dai_link *dai_link)
{
struct of_phandle_args args;
struct snd_soc_dai_link_component *component;
char *name;
int index, num_codecs, ret;
int index, ret;
/* Count the number of CODECs */
name = "sound-dai";
num_codecs = of_count_phandle_with_args(of_node, name,
"#sound-dai-cells");
if (num_codecs <= 0) {
if (num_codecs == -ENOENT)
dev_err(dev, "No 'sound-dai' property\n");
else
dev_err(dev, "Bad phandle in 'sound-dai'\n");
return num_codecs;
}
component = devm_kcalloc(dev,
num_codecs, sizeof(*component),
GFP_KERNEL);
if (!component)
return -ENOMEM;
dai_link->cpus = component;
dai_link->num_cpus = num_codecs;
/* Count the number of CPUs */
ret = __snd_soc_of_get_dai_link_component_alloc(dev, of_node,
&dai_link->cpus, &dai_link->num_cpus);
if (ret < 0)
return ret;
/* Parse the list */
for_each_link_cpus(dai_link, index, component) {
ret = of_parse_phandle_with_args(of_node, name,
"#sound-dai-cells",
index, &args);
ret = __snd_soc_of_get_dai_link_component_parse(of_node, component, index);
if (ret)
goto err;
component->of_node = args.np;
ret = snd_soc_get_dai_name(&args, &component->dai_name);
if (ret < 0)
goto err;
}
return 0;
err:
snd_soc_of_put_dai_link_codecs(dai_link);
snd_soc_of_put_dai_link_cpus(dai_link);
dai_link->cpus = NULL;
dai_link->num_cpus = 0;
return ret;