Skip to contentSkip to conversation

ASoC don't clobber platform DMA driver ops

PATCH In review Alan Tull 3 participants 8 messages Nov 1, 2011 – Nov 10, 2011

Subsystems (2)
lore
Share & tools
lore

Alan Tull

author
#0 lore raw

PATCH 1/1 ASoC don't clobber platform DMA driver ops

Previously, only one static struct for ops existed for all platform DMA drivers to share. Half of the ops are shared functions which don't have stubs in the ALSA core. The other half are initialized to point directly to ops in the platform driver. This creates problems where each time soc_new_pcm is called, the new platform driver's ops would overwrite a subset of the ops.

This patch creates and populates a ops struct for each call to soc_pcm_new. Also creates a common soc_pcm_ioctl function that calls all the driver components for ioctl calls.

---
 include/sound/soc-dai.h |    2 +
 include/sound/soc.h     |    1 +
 sound/soc/soc-core.c    |    1 +
 sound/soc/soc-pcm.c     |   80 +++++++++++++++++++++++++++++++++++-----------
 4 files changed, 65 insertions(+), 19 deletions(-)
include/sound/soc-dai.h +2 -0
index 5ad5f3a..b3f880e 100644
@@ -172,6 +172,8 @@ struct snd_soc_dai_ops {
 		struct snd_soc_dai *);
 	int (*trigger)(struct snd_pcm_substream *, int,
 		struct snd_soc_dai *);
+	int (*ioctl)(struct snd_pcm_substream *, unsigned int, void *,
+		struct snd_soc_dai *);
 	/*
 	 * For hardware based FIFO caused delay reporting.
 	 * Optional.
include/sound/soc.h +1 -0
index aa19f5a..1574325 100644
@@ -517,6 +517,7 @@ struct snd_soc_ops {
 	int (*hw_free)(struct snd_pcm_substream *);
 	int (*prepare)(struct snd_pcm_substream *);
 	int (*trigger)(struct snd_pcm_substream *, int);
+	int (*ioctl)(struct snd_pcm_substream *, unsigned int, void *);
 };
 
 /* SoC cache ops */
sound/soc/soc-core.c +1 -0
index b085d8e..1b48fc6 100644
@@ -1547,6 +1547,7 @@ static int soc_cleanup_card_resources(struct snd_soc_card *card)
 
 	snd_soc_dapm_free(&card->dapm);
 
+	kfree(card->rtd->ops);
 	kfree(card->rtd);
 	snd_card_free(card->snd_card);
 	return 0;
sound/soc/soc-pcm.c +61 -19

120 lines not on this page · raw message

Signature · 1 line
1.6.0.4
#1 lore raw
Quoted 4 lines · Alan Tull

This patch creates and populates a ops struct for each call to soc_pcm_new.  Also creates a common soc_pcm_ioctl function that calls all the driver components for ioctl calls.

Maybe I'm missing something, but it looks like the ioctl stuff is not related to the ops stuff. In other words, it looks like this patch does two completely different things. Shouldn't it be broken into two patches?

Signature · 2 lines
Timur Tabi
Linux kernel developer at Freescale
#2 lore raw
Quoted 10 lines · On Wed, Nov 02, 2011 at 03:40:48AM +0000, Tabi Timur-B04825 wrote:
Quoted 3 lines · Alan Tull

This patch creates and populates a ops struct for each call to soc_pcm_new. ?Also creates a common soc_pcm_ioctl function that calls all the driver components for ioctl calls.

Maybe I'm missing something, but it looks like the ioctl stuff is not related to the ops stuff. In other words, it looks like this patch does two completely different things. Shouldn't it be broken into two patches?

Ideally. The relationship is that it's making all the ops per-PCM overridable rather than just a few as is the case currently.

#3 lore raw
In reply to Alan Tull

On Tue, Nov 01, 2011 at 04:05:16PM -0500, Alan Tull wrote:

This looks mostly good, though as someone pointed out earlier it'd be nicer to split the ioctl() operation addition out into a separate patch. One issue, though.

sound/soc/soc-core.c static int soc_cleanup_card_resources(struct snd_soc_card *card) · line 1550

Quoted 5 lines
sound/soc/soc-core.c +1 -0
@@ -1547,6 +1547,7 @@ static int soc_cleanup_card_resources(struct snd_soc_card *card)
 
 	snd_soc_dapm_free(&card->dapm);
 
+	kfree(card->rtd->ops);

This is going to leak - rtd is an array per PCM, not a single value, so we need to free the ops for each element. This is so we can have multiple DMA controllers in a single card.

Actually what would be even easier would be to just embed the ops in the struct, we need to allocate one per runtime anyway and it makes for less allocation and cleanup code.

author
#4 lore raw
Quoted 16 lines · Mark Brown

On Tue, Nov 01, 2011 at 04:05:16PM -0500, Alan Tull wrote:

This looks mostly good, though as someone pointed out earlier it'd be nicer to split the ioctl() operation addition out into a separate patch. One issue, though.

sound/soc/soc-core.c static int soc_cleanup_card_resources(struct snd_soc_card *card) · line 1550

Quoted 5 lines
sound/soc/soc-core.c +1 -0
@@ -1547,6 +1547,7 @@ static int soc_cleanup_card_resources(struct snd_soc_card *card)
 
  	snd_soc_dapm_free(&card->dapm);
 
+	kfree(card->rtd->ops);

This is going to leak - rtd is an array per PCM, not a single value, so we need to free the ops for each element. This is so we can have multiple DMA controllers in a single card.

Quoted 4 lines

Actually what would be even easier would be to just embed the ops in the struct, we need to allocate one per runtime anyway and it makes for less allocation and cleanup code.

In soc-pcm.c we allocate:
soc_pcm_ops = kzalloc(sizeof(struct snd_pcm_ops), GFP_KERNEL);

and set it to the pointer

rtd->ops = soc_pcm_ops;

So that's what is freed there.

Signature · 2 lines
Regards,
Alan
#5 lore raw
Quoted 10 lines · On Thu, Nov 10, 2011 at 09:14:25AM -0600, r80115 wrote:
Quoted 7 lines · Mark Brown

This is going to leak - rtd is an array per PCM, not a single value, so we need to free the ops for each element. This is so we can have multiple DMA controllers in a single card.

Actually what would be even easier would be to just embed the ops in the struct, we need to allocate one per runtime anyway and it makes for less allocation and cleanup code.

Quoted 8 lines

In soc-pcm.c we allocate:
soc_pcm_ops = kzalloc(sizeof(struct snd_pcm_ops), GFP_KERNEL);

and set it to the pointer

rtd->ops = soc_pcm_ops;

So that's what is freed there.

You're not getting the point here. The point is that you're only freeing a single copy of the ops no matter how many are allocated.

author
#6 lore raw
Quoted 14 lines · Mark Brown
Quoted 12 lines · On Thu, Nov 10, 2011 at 09:14:25AM -0600, r80115 wrote:
Quoted 7 lines · Mark Brown

This is going to leak - rtd is an array per PCM, not a single value, so we need to free the ops for each element. This is so we can have multiple DMA controllers in a single card.

Actually what would be even easier would be to just embed the ops in the struct, we need to allocate one per runtime anyway and it makes for less allocation and cleanup code.

In soc-pcm.c we allocate:
soc_pcm_ops = kzalloc(sizeof(struct snd_pcm_ops), GFP_KERNEL);

Quoted 9 lines
Quoted 5 lines

and set it to the pointer

rtd->ops = soc_pcm_ops;

So that's what is freed there.

You're not getting the point here. The point is that you're only freeing a single copy of the ops no matter how many are allocated.

I see. This is sounding like a significant rewrite. I'll have to revisit this then. Thanks for catching that.

Signature · 2 lines
Regards,
Alan
#7 lore raw
Quoted 2 lines · On Thu, Nov 10, 2011 at 09:20:35AM -0600, r80115 wrote:

I see. This is sounding like a significant rewrite. I'll have to revisit this then. Thanks for catching that.

It should be pretty trivial - just a for loop over all rtds, or even simpler should be to just embed the ops within the rtd.