[PATCH 0/2] ASoC: soc-core.c: fixup snd_soc_of_get_dai_link_cpus()
Hi Mark
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.
It needs Tested-by/Reviewed-by/Acked-by from someone.
Kuninori Morimoto (2): ASoC: soc-core.c: fixup snd_soc_of_get_dai_link_cpus() ASoC: soc-core.c: share code for snd_soc_of_get_dai_link_cpus/codecs()
sound/soc/soc-core.c | 146 ++++++++++++++++++++++--------------------- 1 file changed, 75 insertions(+), 71 deletions(-)
From: Kuninori Morimoto kuninori.morimoto.gx@renesas.com
commit 900dedd7e47cc3f ("ASoC: Introduce snd_soc_of_get_dai_link_cpus") adds new snd_soc_of_get_dai_link_cpus(), but it is using "codec" everywhere. It is very strange, and is issue when error case. It should call cpu instead of codec in error case. This patch tidyup it.
Fixes: 900dedd7e47cc3f ("ASoC: Introduce snd_soc_of_get_dai_link_cpus") Signed-off-by: Kuninori Morimoto kuninori.morimoto.gx@renesas.com --- sound/soc/soc-core.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-)
diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c index 57f7105c12b7..669e4164d167 100644 --- a/sound/soc/soc-core.c +++ b/sound/soc/soc-core.c @@ -3426,26 +3426,26 @@ int snd_soc_of_get_dai_link_cpus(struct device *dev, struct of_phandle_args args; struct snd_soc_dai_link_component *component; char *name; - int index, num_codecs, ret; + int index, num_cpus, ret;
- /* Count the number of CODECs */ + /* Count the number of CPUs */ name = "sound-dai"; - num_codecs = of_count_phandle_with_args(of_node, name, + num_cpus = of_count_phandle_with_args(of_node, name, "#sound-dai-cells"); - if (num_codecs <= 0) { - if (num_codecs == -ENOENT) + if (num_cpus <= 0) { + if (num_cpus == -ENOENT) dev_err(dev, "No 'sound-dai' property\n"); else dev_err(dev, "Bad phandle in 'sound-dai'\n"); - return num_codecs; + return num_cpus; } component = devm_kcalloc(dev, - num_codecs, sizeof(*component), + num_cpus, sizeof(*component), GFP_KERNEL); if (!component) return -ENOMEM; dai_link->cpus = component; - dai_link->num_cpus = num_codecs; + dai_link->num_cpus = num_cpus;
/* Parse the list */ for_each_link_cpus(dai_link, index, component) { @@ -3461,7 +3461,7 @@ int snd_soc_of_get_dai_link_cpus(struct device *dev, } 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;
On 22. 6. 2022, at 7:54, Kuninori Morimoto kuninori.morimoto.gx@renesas.com wrote:
From: Kuninori Morimoto kuninori.morimoto.gx@renesas.com
commit 900dedd7e47cc3f ("ASoC: Introduce snd_soc_of_get_dai_link_cpus") adds new snd_soc_of_get_dai_link_cpus(), but it is using "codec" everywhere. It is very strange, and is issue when error case. It should call cpu instead of codec in error case. This patch tidyup it.
Fixes: 900dedd7e47cc3f ("ASoC: Introduce snd_soc_of_get_dai_link_cpus") Signed-off-by: Kuninori Morimoto kuninori.morimoto.gx@renesas.com
Reviewed-by: Martin Povišer povik+lin@cutebit.org
From: Kuninori Morimoto kuninori.morimoto.gx@renesas.com
ASoC has snd_soc_of_get_dai_link_cpus/codecs(), and these are almost same code. The main difference are below.
for_each_link_cpus() dai_link->cpus dai_link->num_cpus for_each_link_codecs() dai_link->codecs dai_link->num_codecs
Because we need to use these parameters, we can't share full-code for now, but can share some codes. This patch adds __snd_soc_of_get/put_xxx() functions, and share the code.
Signed-off-by: Kuninori Morimoto kuninori.morimoto.gx@renesas.com --- sound/soc/soc-core.c | 140 ++++++++++++++++++++++--------------------- 1 file changed, 72 insertions(+), 68 deletions(-)
diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c index 669e4164d167..5d5805e43240 100644 --- a/sound/soc/soc-core.c +++ b/sound/soc/soc-core.c @@ -3305,6 +3305,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 @@ -3316,12 +3371,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);
@@ -3343,41 +3394,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; - - /* 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; + int index, ret; + + 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: @@ -3399,12 +3428,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);
@@ -3423,41 +3448,20 @@ 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_cpus, ret; + int index, ret;
/* Count the number of CPUs */ - name = "sound-dai"; - num_cpus = of_count_phandle_with_args(of_node, name, - "#sound-dai-cells"); - if (num_cpus <= 0) { - if (num_cpus == -ENOENT) - dev_err(dev, "No 'sound-dai' property\n"); - else - dev_err(dev, "Bad phandle in 'sound-dai'\n"); - return num_cpus; - } - component = devm_kcalloc(dev, - num_cpus, sizeof(*component), - GFP_KERNEL); - if (!component) - return -ENOMEM; - dai_link->cpus = component; - dai_link->num_cpus = num_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:
On Wed, 22 Jun 2022 05:53:41 +0000, Kuninori Morimoto wrote:
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.
[...]
Applied to
https://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git for-next
Thanks!
[1/2] ASoC: soc-core.c: fixup snd_soc_of_get_dai_link_cpus() commit: f3762ddfa24068cf67bc395cb80a7928306ad1ef [2/2] ASoC: soc-core.c: share code for snd_soc_of_get_dai_link_cpus/codecs() commit: 9cc69528188a4e3eb24370f6c05a92791ac249ba
All being well this means that it will be integrated into the linux-next tree (usually sometime in the next 24 hours) and sent to Linus during the next merge window (or sooner if it is a bug fix), however if problems are discovered then the patch may be dropped or reverted.
You may get further e-mails resulting from automated or manual testing and review of the tree, please engage with people reporting problems and send followup patches addressing any issues that are reported if needed.
If any updates are required or you are submitting further changes they should be sent as incremental updates against current git, existing patches will not be replaced.
Please add any relevant lists and maintainers to the CCs when replying to this mail.
Thanks, Mark
participants (3)
-
Kuninori Morimoto
-
Mark Brown
-
Martin Povišer