[alsa-devel] [PATCH v2 0/9] ASoC: simple-card: tidyup and synchronize patches
Hi Mark
These are v2 of cleanup/tidyup and synchronize patches for simple-card. We have now simple-card and simple-scu-card. These are almost same, difference should be very small. But, because of historical reason, these have "code" difference. This patch cleanup and synchronize these.
Kuninori Morimoto (9): ASoC: simple-card: call of_node_put() for dai_link ASoC: simple-card: tidyup mclk-fs of_property_read_u32() usage ASoC: simple-card: code sync: tidyup simple_priv_to_xxx() macro ASoC: simple-card: code sync: use simple_priv_to_props() macro ASoC: simple-card: is GPL v2 ASoC: simple-card: code sync: tidyup white line ASoC: simple-card: code sync: use tag ASoC: simple-card: code sync: rename num_link to num ASoC: simple-card: use kzalloc() for dai_props / dai_link
sound/soc/generic/simple-card.c | 87 ++++++++++++++++++++--------------------- 1 file changed, 43 insertions(+), 44 deletions(-)
From: Kuninori Morimoto kuninori.morimoto.gx@renesas.com
We need to call of_node_put() if we used of_get_child_by_name(), but missing it for "dai-link" loop.
Signed-off-by: Kuninori Morimoto kuninori.morimoto.gx@renesas.com --- v1 -> v2
- no change
sound/soc/generic/simple-card.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-)
diff --git a/sound/soc/generic/simple-card.c b/sound/soc/generic/simple-card.c index 55638a8..3ce8bb6 100644 --- a/sound/soc/generic/simple-card.c +++ b/sound/soc/generic/simple-card.c @@ -322,18 +322,21 @@ static int asoc_simple_card_parse_of(struct device_node *node, struct simple_card_data *priv) { struct device *dev = simple_priv_to_dev(priv); + struct device_node *dai_link; u32 val; int ret;
if (!node) return -EINVAL;
+ dai_link = of_get_child_by_name(node, PREFIX "dai-link"); + /* The off-codec widgets */ if (of_property_read_bool(node, PREFIX "widgets")) { ret = snd_soc_of_parse_audio_simple_widgets(&priv->snd_card, PREFIX "widgets"); if (ret) - return ret; + goto card_parse_end; }
/* DAPM routes */ @@ -341,7 +344,7 @@ static int asoc_simple_card_parse_of(struct device_node *node, ret = snd_soc_of_parse_audio_routing(&priv->snd_card, PREFIX "routing"); if (ret) - return ret; + goto card_parse_end; }
/* Factor to mclk, used in hw_params() */ @@ -350,7 +353,7 @@ static int asoc_simple_card_parse_of(struct device_node *node, priv->mclk_fs = val;
/* Single/Muti DAI link(s) & New style of DT node */ - if (of_get_child_by_name(node, PREFIX "dai-link")) { + if (dai_link) { struct device_node *np = NULL; int i = 0;
@@ -360,7 +363,7 @@ static int asoc_simple_card_parse_of(struct device_node *node, i, false); if (ret < 0) { of_node_put(np); - return ret; + goto card_parse_end; } i++; } @@ -368,14 +371,15 @@ static int asoc_simple_card_parse_of(struct device_node *node, /* For single DAI link & old style of DT node */ ret = asoc_simple_card_dai_link_of(node, priv, 0, true); if (ret < 0) - return ret; + goto card_parse_end; }
ret = asoc_simple_card_parse_card_name(&priv->snd_card, PREFIX); - if (ret) - return ret;
- return 0; +card_parse_end: + of_node_put(dai_link); + + return ret; }
static int asoc_simple_card_probe(struct platform_device *pdev)
From: Kuninori Morimoto kuninori.morimoto.gx@renesas.com
of_property_read_u32() do nothing in error case. Let's tidyup useless usage.
Signed-off-by: Kuninori Morimoto kuninori.morimoto.gx@renesas.com --- v1 -> v2
- no change
sound/soc/generic/simple-card.c | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-)
diff --git a/sound/soc/generic/simple-card.c b/sound/soc/generic/simple-card.c index 3ce8bb6..a4a39d4 100644 --- a/sound/soc/generic/simple-card.c +++ b/sound/soc/generic/simple-card.c @@ -222,7 +222,6 @@ static int asoc_simple_card_dai_link_of(struct device_node *node, char prop[128]; char *prefix = ""; int ret, single_cpu; - u32 val;
/* For single DAI link & old style of DT node */ if (is_top_level_node) @@ -248,8 +247,7 @@ static int asoc_simple_card_dai_link_of(struct device_node *node, if (ret < 0) goto dai_link_of_err;
- if (!of_property_read_u32(node, "mclk-fs", &val)) - dai_props->mclk_fs = val; + of_property_read_u32(node, "mclk-fs", &dai_props->mclk_fs);
ret = asoc_simple_card_parse_cpu(cpu, dai_link, DAI, CELL, &single_cpu); @@ -323,7 +321,6 @@ static int asoc_simple_card_parse_of(struct device_node *node, { struct device *dev = simple_priv_to_dev(priv); struct device_node *dai_link; - u32 val; int ret;
if (!node) @@ -348,9 +345,7 @@ static int asoc_simple_card_parse_of(struct device_node *node, }
/* Factor to mclk, used in hw_params() */ - ret = of_property_read_u32(node, PREFIX "mclk-fs", &val); - if (ret == 0) - priv->mclk_fs = val; + of_property_read_u32(node, PREFIX "mclk-fs", &priv->mclk_fs);
/* Single/Muti DAI link(s) & New style of DT node */ if (dai_link) {
From: Kuninori Morimoto kuninori.morimoto.gx@renesas.com
Signed-off-by: Kuninori Morimoto kuninori.morimoto.gx@renesas.com --- v1 -> v2
- no change
sound/soc/generic/simple-card.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/sound/soc/generic/simple-card.c b/sound/soc/generic/simple-card.c index a4a39d4..8774d803 100644 --- a/sound/soc/generic/simple-card.c +++ b/sound/soc/generic/simple-card.c @@ -41,8 +41,8 @@ struct simple_card_data { };
#define simple_priv_to_dev(priv) ((priv)->snd_card.dev) -#define simple_priv_to_link(priv, i) ((priv)->snd_card.dai_link + i) -#define simple_priv_to_props(priv, i) ((priv)->dai_props + i) +#define simple_priv_to_link(priv, i) ((priv)->snd_card.dai_link + (i)) +#define simple_priv_to_props(priv, i) ((priv)->dai_props + (i))
#define DAI "sound-dai" #define CELL "#sound-dai-cells"
From: Kuninori Morimoto kuninori.morimoto.gx@renesas.com
Signed-off-by: Kuninori Morimoto kuninori.morimoto.gx@renesas.com --- v1 -> v2
- no change
sound/soc/generic/simple-card.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-)
diff --git a/sound/soc/generic/simple-card.c b/sound/soc/generic/simple-card.c index 8774d803..939c827 100644 --- a/sound/soc/generic/simple-card.c +++ b/sound/soc/generic/simple-card.c @@ -114,7 +114,7 @@ static int asoc_simple_card_startup(struct snd_pcm_substream *substream) struct snd_soc_pcm_runtime *rtd = substream->private_data; struct simple_card_data *priv = snd_soc_card_get_drvdata(rtd->card); struct simple_dai_props *dai_props = - &priv->dai_props[rtd->num]; + simple_priv_to_props(priv, rtd->num); int ret;
ret = clk_prepare_enable(dai_props->cpu_dai.clk); @@ -133,7 +133,7 @@ static void asoc_simple_card_shutdown(struct snd_pcm_substream *substream) struct snd_soc_pcm_runtime *rtd = substream->private_data; struct simple_card_data *priv = snd_soc_card_get_drvdata(rtd->card); struct simple_dai_props *dai_props = - &priv->dai_props[rtd->num]; + simple_priv_to_props(priv, rtd->num);
clk_disable_unprepare(dai_props->cpu_dai.clk);
@@ -147,7 +147,8 @@ static int asoc_simple_card_hw_params(struct snd_pcm_substream *substream, struct snd_soc_dai *codec_dai = rtd->codec_dai; struct snd_soc_dai *cpu_dai = rtd->cpu_dai; struct simple_card_data *priv = snd_soc_card_get_drvdata(rtd->card); - struct simple_dai_props *dai_props = &priv->dai_props[rtd->num]; + struct simple_dai_props *dai_props = + simple_priv_to_props(priv, rtd->num); unsigned int mclk, mclk_fs = 0; int ret = 0;
@@ -184,7 +185,8 @@ static int asoc_simple_card_dai_init(struct snd_soc_pcm_runtime *rtd) struct simple_card_data *priv = snd_soc_card_get_drvdata(rtd->card); struct snd_soc_dai *codec = rtd->codec_dai; struct snd_soc_dai *cpu = rtd->cpu_dai; - struct simple_dai_props *dai_props = &priv->dai_props[rtd->num]; + struct simple_dai_props *dai_props = + simple_priv_to_props(priv, rtd->num); int ret;
ret = asoc_simple_card_init_dai(codec, &dai_props->codec_dai);
From: Kuninori Morimoto kuninori.morimoto.gx@renesas.com
It is indicating that this driver is GPL v2 on top of C code. Let's fixup it on MODULE_LICENSE()
Signed-off-by: Kuninori Morimoto kuninori.morimoto.gx@renesas.com --- v1 -> v2
- no change
sound/soc/generic/simple-card.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/sound/soc/generic/simple-card.c b/sound/soc/generic/simple-card.c index 939c827..7b0a56f 100644 --- a/sound/soc/generic/simple-card.c +++ b/sound/soc/generic/simple-card.c @@ -498,6 +498,6 @@ static struct platform_driver asoc_simple_card = { module_platform_driver(asoc_simple_card);
MODULE_ALIAS("platform:asoc-simple-card"); -MODULE_LICENSE("GPL"); +MODULE_LICENSE("GPL v2"); MODULE_DESCRIPTION("ASoC Simple Sound Card"); MODULE_AUTHOR("Kuninori Morimoto kuninori.morimoto.gx@renesas.com");
From: Kuninori Morimoto kuninori.morimoto.gx@renesas.com
simple sound card family are using very similar style, but because of its historical reason, there are small differences. For example pointer style, function name, caller postion etc... This patch synchronized simple card style to other simple card family.
This patch tidyups white line
Signed-off-by: Kuninori Morimoto kuninori.morimoto.gx@renesas.com --- v1 -> v2
- no change
sound/soc/generic/simple-card.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
diff --git a/sound/soc/generic/simple-card.c b/sound/soc/generic/simple-card.c index 7b0a56f..7d15b50 100644 --- a/sound/soc/generic/simple-card.c +++ b/sound/soc/generic/simple-card.c @@ -120,7 +120,7 @@ static int asoc_simple_card_startup(struct snd_pcm_substream *substream) ret = clk_prepare_enable(dai_props->cpu_dai.clk); if (ret) return ret; - + ret = clk_prepare_enable(dai_props->codec_dai.clk); if (ret) clk_disable_unprepare(dai_props->cpu_dai.clk); @@ -454,7 +454,6 @@ static int asoc_simple_card_probe(struct platform_device *pdev) sizeof(priv->dai_props->cpu_dai)); memcpy(&priv->dai_props->codec_dai, &cinfo->codec_dai, sizeof(priv->dai_props->codec_dai)); - }
snd_soc_card_set_drvdata(&priv->snd_card, priv); @@ -462,9 +461,9 @@ static int asoc_simple_card_probe(struct platform_device *pdev) ret = devm_snd_soc_register_card(&pdev->dev, &priv->snd_card); if (ret >= 0) return ret; - err: asoc_simple_card_clean_reference(&priv->snd_card); + return ret; }
From: Kuninori Morimoto kuninori.morimoto.gx@renesas.com
simple sound card family are using very similar style, but because of its historical reason, there are small differences. For example pointer style, function name, caller postion etc... This patch synchronized simple card style to other simple card family.
This patch uses tag on asoc_simple_card_probe
Signed-off-by: Kuninori Morimoto kuninori.morimoto.gx@renesas.com --- v1 -> v2
- no change
sound/soc/generic/simple-card.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/sound/soc/generic/simple-card.c b/sound/soc/generic/simple-card.c index 7d15b50..c17f851 100644 --- a/sound/soc/generic/simple-card.c +++ b/sound/soc/generic/simple-card.c @@ -401,11 +401,11 @@ static int asoc_simple_card_probe(struct platform_device *pdev) return -ENOMEM;
/* Init snd_soc_card */ - priv->snd_card.owner = THIS_MODULE; - priv->snd_card.dev = dev; dai_link = priv->dai_link; - priv->snd_card.dai_link = dai_link; - priv->snd_card.num_links = num_links; + priv->snd_card.owner = THIS_MODULE; + priv->snd_card.dev = dev; + priv->snd_card.dai_link = priv->dai_link; + priv->snd_card.num_links = num_links;
/* Get room for the other properties */ priv->dai_props = devm_kzalloc(dev,
From: Kuninori Morimoto kuninori.morimoto.gx@renesas.com
simple sound card family are using very similar style, but because of its historical reason, there are small differences. For example pointer style, function name, caller postion etc... This patch synchronized simple card style to other simple card family.
This patch renames num_link to num
Signed-off-by: Kuninori Morimoto kuninori.morimoto.gx@renesas.com --- v1 -> v2
- replaced missing num_links
sound/soc/generic/simple-card.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/sound/soc/generic/simple-card.c b/sound/soc/generic/simple-card.c index c17f851..93163c9 100644 --- a/sound/soc/generic/simple-card.c +++ b/sound/soc/generic/simple-card.c @@ -385,17 +385,17 @@ static int asoc_simple_card_probe(struct platform_device *pdev) struct snd_soc_dai_link *dai_link; struct device_node *np = pdev->dev.of_node; struct device *dev = &pdev->dev; - int num_links, ret; + int num, ret;
/* Get the number of DAI links */ if (np && of_get_child_by_name(np, PREFIX "dai-link")) - num_links = of_get_child_count(np); + num = of_get_child_count(np); else - num_links = 1; + num = 1;
/* Allocate the private data and the DAI link array */ priv = devm_kzalloc(dev, - sizeof(*priv) + sizeof(*dai_link) * num_links, + sizeof(*priv) + sizeof(*dai_link) * num, GFP_KERNEL); if (!priv) return -ENOMEM; @@ -405,11 +405,11 @@ static int asoc_simple_card_probe(struct platform_device *pdev) priv->snd_card.owner = THIS_MODULE; priv->snd_card.dev = dev; priv->snd_card.dai_link = priv->dai_link; - priv->snd_card.num_links = num_links; + priv->snd_card.num_links = num;
/* Get room for the other properties */ priv->dai_props = devm_kzalloc(dev, - sizeof(*priv->dai_props) * num_links, + sizeof(*priv->dai_props) * num, GFP_KERNEL); if (!priv->dai_props) return -ENOMEM;
From: Kuninori Morimoto kuninori.morimoto.gx@renesas.com
simple sound card family are using very similar style, but because of its historical reason, there are small differences. For example pointer style, function name, caller postion etc... This patch synchronized simple card style to other simple card family.
Now, simple card needs to 2 type of buffer for dai_props and dai_link. But, these used different style for buffer allocation. This patch make these same style as other simple card family. (= use kzalloc() for both)
Signed-off-by: Kuninori Morimoto kuninori.morimoto.gx@renesas.com --- v1 -> v2
- based on previous patch
sound/soc/generic/simple-card.c | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-)
diff --git a/sound/soc/generic/simple-card.c b/sound/soc/generic/simple-card.c index 93163c9..fe0bc5c 100644 --- a/sound/soc/generic/simple-card.c +++ b/sound/soc/generic/simple-card.c @@ -37,7 +37,7 @@ struct simple_card_data { unsigned int mclk_fs; struct asoc_simple_jack hp_jack; struct asoc_simple_jack mic_jack; - struct snd_soc_dai_link dai_link[]; /* dynamically allocated */ + struct snd_soc_dai_link *dai_link; };
#define simple_priv_to_dev(priv) ((priv)->snd_card.dev) @@ -383,6 +383,7 @@ static int asoc_simple_card_probe(struct platform_device *pdev) { struct simple_card_data *priv; struct snd_soc_dai_link *dai_link; + struct simple_dai_props *dai_props; struct device_node *np = pdev->dev.of_node; struct device *dev = &pdev->dev; int num, ret; @@ -394,26 +395,24 @@ static int asoc_simple_card_probe(struct platform_device *pdev) num = 1;
/* Allocate the private data and the DAI link array */ - priv = devm_kzalloc(dev, - sizeof(*priv) + sizeof(*dai_link) * num, - GFP_KERNEL); + priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); if (!priv) return -ENOMEM;
+ dai_props = devm_kzalloc(dev, sizeof(*dai_props) * num, GFP_KERNEL); + dai_link = devm_kzalloc(dev, sizeof(*dai_link) * num, GFP_KERNEL); + if (!dai_props || !dai_link) + return -ENOMEM; + + priv->dai_props = dai_props; + priv->dai_link = dai_link; + /* Init snd_soc_card */ - dai_link = priv->dai_link; priv->snd_card.owner = THIS_MODULE; priv->snd_card.dev = dev; priv->snd_card.dai_link = priv->dai_link; priv->snd_card.num_links = num;
- /* Get room for the other properties */ - priv->dai_props = devm_kzalloc(dev, - sizeof(*priv->dai_props) * num, - GFP_KERNEL); - if (!priv->dai_props) - return -ENOMEM; - if (np && of_device_is_available(np)) {
ret = asoc_simple_card_parse_of(np, priv);
Hi Mark
Does these go to next v4.9 merge window ? or v4.10 ?
These are v2 of cleanup/tidyup and synchronize patches for simple-card. We have now simple-card and simple-scu-card. These are almost same, difference should be very small. But, because of historical reason, these have "code" difference. This patch cleanup and synchronize these.
Kuninori Morimoto (9): ASoC: simple-card: call of_node_put() for dai_link ASoC: simple-card: tidyup mclk-fs of_property_read_u32() usage ASoC: simple-card: code sync: tidyup simple_priv_to_xxx() macro ASoC: simple-card: code sync: use simple_priv_to_props() macro ASoC: simple-card: is GPL v2 ASoC: simple-card: code sync: tidyup white line ASoC: simple-card: code sync: use tag ASoC: simple-card: code sync: rename num_link to num ASoC: simple-card: use kzalloc() for dai_props / dai_link
sound/soc/generic/simple-card.c | 87 ++++++++++++++++++++--------------------- 1 file changed, 43 insertions(+), 44 deletions(-)
-- 1.9.1
participants (2)
-
Kuninori Morimoto
-
Mark Brown