diff mbox

[2/4] ASoC: simple-card: dynamically allocate the DAI link array

Message ID 41aa7354a6883f31afa60c21c2e14ecbb3bbb7e9.1392995566.git.moinejf@free.fr (mailing list archive)
State New, archived
Headers show

Commit Message

Jean-Francois Moine Feb. 19, 2014, 6:07 p.m. UTC
The DAI link array is hard-coded as a single CPU / CODEC DAIs link.

This patch allocates this array with the card definition and facilitates
handling more links.

Signed-off-by: Jean-Francois Moine <moinejf@free.fr>
---
 sound/soc/generic/simple-card.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

Comments

Xiubo Li Feb. 24, 2014, 3:32 a.m. UTC | #1
> @@ -20,7 +20,6 @@ struct simple_card_data {
>  	unsigned int daifmt;
>  	struct asoc_simple_dai cpu_dai;
>  	struct asoc_simple_dai codec_dai;
> -	struct snd_soc_dai_link snd_link;
>  };
> 
>  static int __asoc_simple_card_dai_init(struct snd_soc_dai *dai,
> @@ -246,7 +245,9 @@ static int asoc_simple_card_probe(struct platform_device
> *pdev)
>  	struct device *dev = &pdev->dev;
>  	int ret;
> 
> -	priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
> +	priv = devm_kzalloc(dev,
> +			sizeof(*priv) + sizeof(*dai_link),

This is okey for me.

Well, how about splitting the *priv and *dai_link into two separated
memory blocks? As we can get the dai-link pointer via priv->snd_card.dai_link
in other places.

IMHO, then the code will be much more simplifier and readable.

Just for one suggestion.

Thanks,

--
Best regards,
Xiubo


> +			GFP_KERNEL);
>  	if (!priv)
>  		return -ENOMEM;
> 
> @@ -255,7 +256,7 @@ static int asoc_simple_card_probe(struct platform_device
> *pdev)
>  	 */
>  	priv->snd_card.owner = THIS_MODULE;
>  	priv->snd_card.dev = dev;
> -	dai_link = &priv->snd_link;
> +	dai_link = (struct snd_soc_dai_link *) (priv + 1);
>  	priv->snd_card.dai_link = dai_link;
>  	priv->snd_card.num_links = 1;
> 
> --
> 1.9.0
> 
>
Jean-Francois Moine Feb. 25, 2014, 8:02 a.m. UTC | #2
On Mon, 24 Feb 2014 03:32:02 +0000
"Li.Xiubo@freescale.com" <Li.Xiubo@freescale.com> wrote:
> 
> > @@ -20,7 +20,6 @@ struct simple_card_data {
> >  	unsigned int daifmt;
> >  	struct asoc_simple_dai cpu_dai;
> >  	struct asoc_simple_dai codec_dai;
> > -	struct snd_soc_dai_link snd_link;
> >  };
> > 
> >  static int __asoc_simple_card_dai_init(struct snd_soc_dai *dai,
> > @@ -246,7 +245,9 @@ static int asoc_simple_card_probe(struct platform_device
> > *pdev)
> >  	struct device *dev = &pdev->dev;
> >  	int ret;
> > 
> > -	priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
> > +	priv = devm_kzalloc(dev,
> > +			sizeof(*priv) + sizeof(*dai_link),
> 
> This is okey for me.
> 
> Well, how about splitting the *priv and *dai_link into two separated
> memory blocks? As we can get the dai-link pointer via priv->snd_card.dai_link
> in other places.
> 
> IMHO, then the code will be much more simplifier and readable.

It is just a simple optimization: less calls to memory allocation and
less code (also, less TLB reload?). I will add more comments.
diff mbox

Patch

diff --git a/sound/soc/generic/simple-card.c b/sound/soc/generic/simple-card.c
index 8809ab4..a75a8bb 100644
--- a/sound/soc/generic/simple-card.c
+++ b/sound/soc/generic/simple-card.c
@@ -20,7 +20,6 @@  struct simple_card_data {
 	unsigned int daifmt;
 	struct asoc_simple_dai cpu_dai;
 	struct asoc_simple_dai codec_dai;
-	struct snd_soc_dai_link snd_link;
 };
 
 static int __asoc_simple_card_dai_init(struct snd_soc_dai *dai,
@@ -246,7 +245,9 @@  static int asoc_simple_card_probe(struct platform_device *pdev)
 	struct device *dev = &pdev->dev;
 	int ret;
 
-	priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
+	priv = devm_kzalloc(dev,
+			sizeof(*priv) + sizeof(*dai_link),
+			GFP_KERNEL);
 	if (!priv)
 		return -ENOMEM;
 
@@ -255,7 +256,7 @@  static int asoc_simple_card_probe(struct platform_device *pdev)
 	 */
 	priv->snd_card.owner = THIS_MODULE;
 	priv->snd_card.dev = dev;
-	dai_link = &priv->snd_link;
+	dai_link = (struct snd_soc_dai_link *) (priv + 1);
 	priv->snd_card.dai_link = dai_link;
 	priv->snd_card.num_links = 1;