diff mbox

[1/2] ASoC: compress: Correct handling of compressed ops

Message ID 87wp06lotn.wl%kuninori.morimoto.gx@renesas.com (mailing list archive)
State New, archived
Headers show

Commit Message

Kuninori Morimoto Jan. 25, 2018, 1:18 a.m. UTC
Hi Charles

Thank you for your patch.
I'm sorry that my patch breaks your system.

I'm not good at soc_compr_xxx,
thus, basically I have no objection about this patch.
This is just question.

> The soc_compr_copy callback is currently broken. Since the
> changes to move the compr_ops over to the component the return
> value is not correctly proqpagated, always returning zero on
> success rather than the number of bytes copied. This causes
> user-space to stall continuously reading as it does not believe
> it has received any data.
> 
> Furthermore, the changes to move the compr_ops over to the
> component iterate through the list of components and will
> call the compressed operation for any that have compressed
> ops. However, there would be signifcantly more work required
> to support such a system. There isn't currently any sensible
> mechanism to forward the ops to multiple components. For example
> what should be done about merging data from copy?  Or what should
> be returned through the pointer call, each component may have
> different amounts of data available, but user-space expects a
> single answer?
> 
> As such clean up the code a little by factoring out the search
> for the relevant component and bring things back to looking for
> a single component that supports compressed ops on a single
> runtime. These refactorings also put back the original handling
> for the copy callback, correcting the return value.
> 
> Fixes: 9e7e3738ab0e ("ASoC: snd_soc_component_driver has snd_compr_ops")
> Signed-off-by: Charles Keepax <ckeepax@opensource.cirrus.com>
> ---
(snip)
> -static int soc_compr_open(struct snd_compr_stream *cstream)
> +static struct snd_soc_component *
> +soc_compr_get_component(struct snd_soc_pcm_runtime *rtd)
>  {
> -	struct snd_soc_pcm_runtime *rtd = cstream->private_data;
>  	struct snd_soc_platform *platform = rtd->platform;
> -	struct snd_soc_component *component;
>  	struct snd_soc_rtdcom_list *rtdcom;
> +
> +	if (platform)
> +		return &platform->component;
> +
> +	for_each_rtdcom(rtd, rtdcom) {
> +		if (rtdcom->component->driver->compr_ops)
> +			return rtdcom->component;
> +	}
> +
> +	return NULL;
> +}
(snip)
> +static int soc_compr_open(struct snd_compr_stream *cstream)
> +{
> +	struct snd_soc_pcm_runtime *rtd = cstream->private_data;
> +	struct snd_soc_component *component = soc_compr_get_component(rtd);
> +	const struct snd_compr_ops *compr_ops = soc_compr_get_ops(rtd, component);
>  	struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
> -	int ret = 0, __ret;
> +	int ret = 0;
>  
>  	mutex_lock_nested(&rtd->pcm_mutex, rtd->pcm_subclass);
>  
> @@ -46,36 +74,15 @@ static int soc_compr_open(struct snd_compr_stream *cstream)
>  		}
>  	}
>  
> -	if (platform && platform->driver->compr_ops && platform->driver->compr_ops->open) {
> -		ret = platform->driver->compr_ops->open(cstream);
> +	if (compr_ops && compr_ops->open) {
> +		ret = compr_ops->open(cstream);
>  		if (ret < 0) {
>  			pr_err("compress asoc: can't open platform %s\n",
> -				platform->component.name);
> +				component->name);
>  			goto plat_err;
>  		}
>  	}
>  
> -	for_each_rtdcom(rtd, rtdcom) {
> -		component = rtdcom->component;
> -
> -		/* ignore duplication for now */
> -		if (platform && (component == &platform->component))
> -			continue;
> -
> -		if (!component->driver->compr_ops ||
> -		    !component->driver->compr_ops->open)
> -			continue;
> -
> -		__ret = component->driver->compr_ops->open(cstream);
> -		if (__ret < 0) {
> -			pr_err("compress asoc: can't open platform %s\n",
> -			       component->name);
> -			ret = __ret;
> -		}
> -	}

soc_compr_get_component() searches 1st component which have compr_ops,
but it doesn't check compr_ops->xxx, In above case, compr_ops->open.
Is it OK ?

For me, it looks like we can solve it by using "break" and "goto".
"goto" is quick hack for now.
For example like below (not tested).
If we can use rtd->platform, use it, and skip rtdcom loop by using "goto".
If we use rtdcom, call "break" after calling 1st callback.
soc_rtdcom_xxx() in soc-pcm.c is doing similar things.
I don't know this is good idea, or not.

---------------
---------------



Best regards
---
Kuninori Morimoto

Comments

Charles Keepax Jan. 25, 2018, 9:47 a.m. UTC | #1
On Thu, Jan 25, 2018 at 01:18:37AM +0000, Kuninori Morimoto wrote:
> soc_compr_get_component() searches 1st component which have compr_ops,
> but it doesn't check compr_ops->xxx, In above case, compr_ops->open.
> Is it OK ?
> 
> For me, it looks like we can solve it by using "break" and "goto".
> "goto" is quick hack for now.
> For example like below (not tested).
> If we can use rtd->platform, use it, and skip rtdcom loop by using "goto".
> If we use rtdcom, call "break" after calling 1st callback.
> soc_rtdcom_xxx() in soc-pcm.c is doing similar things.
> I don't know this is good idea, or not.
> 
> ---------------
> diff --git a/sound/soc/soc-compress.c b/sound/soc/soc-compress.c
> index 81232f4..a147a03 100644
> --- a/sound/soc/soc-compress.c
> +++ b/sound/soc/soc-compress.c
> @@ -53,6 +53,7 @@ static int soc_compr_open(struct snd_compr_stream *cstream)
>  				platform->component.name);
>  			goto plat_err;
>  		}
> +		goto rtdcom_skip:
>  	}
>  
>  	for_each_rtdcom(rtd, rtdcom) {
> @@ -72,10 +73,13 @@ static int soc_compr_open(struct snd_compr_stream *cstream)
>  			       component->name);
>  			ret = __ret;
>  		}
> +		break;
>  	}
>  	if (ret < 0)
>  		goto machine_err;
>  
> +rtdcom_skip:
> +
>  	if (rtd->dai_link->compr_ops && rtd->dai_link->compr_ops->startup) {
>  		ret = rtd->dai_link->compr_ops->startup(cstream);
>  		if (ret < 0) {
> ---------------

Yes I had considered adding in breaks as an initial fix, however,
two things drove me in this direction.

Firstly, it didn't feel like it made sense to be calling
different compr_ops on different components. Not sure if anyone
feels there might be use-cases for that?

And what should happen if two components had the same
callback? Which do we call, should we call both as the current
code does, but then what to do with the results? In short I
felt there is significantly more work to be done to support
systems where we have multiple components providing compressed
functionality on a single runtime, so better to not look like we
support it at the moment.

Secondly it feels like a lot of code duplication having those
almost identical loops in every callback and this solution keeps
things much neater.

I will have a look through the soc-pcm stuff as well and have a
think if there are any issues there as well, although that does
all seem to work on my system.

Thanks,
Charles
Kuninori Morimoto Jan. 26, 2018, 12:33 a.m. UTC | #2
Hi Charles

Thank you for your feedback

> Yes I had considered adding in breaks as an initial fix, however,
> two things drove me in this direction.
> 
> Firstly, it didn't feel like it made sense to be calling
> different compr_ops on different components. Not sure if anyone
> feels there might be use-cases for that?
> 
> And what should happen if two components had the same
> callback? Which do we call, should we call both as the current
> code does, but then what to do with the results? In short I
> felt there is significantly more work to be done to support
> systems where we have multiple components providing compressed
> functionality on a single runtime, so better to not look like we
> support it at the moment.
> 
> Secondly it feels like a lot of code duplication having those
> almost identical loops in every callback and this solution keeps
> things much neater.
> 
> I will have a look through the soc-pcm stuff as well and have a
> think if there are any issues there as well, although that does
> all seem to work on my system.

In existing drivers, the component which have compr_ops *was* originally
"platform" component only.
The main purpose why we want to replace platform (and codec) to component is that
CPU/Codec/Platform categorize is no longer best match for modern device.

Thus, if we can replace all CPU/Codec/Platform into component, every device
can have every feature, with no categorize !
In other words, we don't know how many device have it.

But anyway, we don't have such situation, and we don't know how to adjust to it
at this point.
Thus Yes !! I can 100% agree your opinion.
Thank you for your help

One note is that "rtd->platform" itself will be removed if all platforms were replaced.
Then, soc_compr_get_component() / soc_compr_get_ops() might be merged or adjusted.

Best regards
---
Kuninori Morimoto
Charles Keepax Jan. 26, 2018, 10:03 a.m. UTC | #3
On Fri, Jan 26, 2018 at 12:33:53AM +0000, Kuninori Morimoto wrote:
> In existing drivers, the component which have compr_ops *was* originally
> "platform" component only.
> The main purpose why we want to replace platform (and codec) to component is that
> CPU/Codec/Platform categorize is no longer best match for modern device.
> 
> Thus, if we can replace all CPU/Codec/Platform into component, every device
> can have every feature, with no categorize !
> In other words, we don't know how many device have it.
> 

Yeah I think there is quite a lot more work to get to that point
though, we need to understand how we will present this to
user-space.

> But anyway, we don't have such situation, and we don't know how to adjust to it
> at this point.
> Thus Yes !! I can 100% agree your opinion.
> Thank you for your help
> 
> One note is that "rtd->platform" itself will be removed if all platforms were replaced.
> Then, soc_compr_get_component() / soc_compr_get_ops() might be merged or adjusted.
> 

Yes that was my thinking as well, once you remove that you should
only need some minor refactoring to make the updates.

Thanks,
Charles
Mark Brown Jan. 26, 2018, 11:48 a.m. UTC | #4
On Fri, Jan 26, 2018 at 10:03:51AM +0000, Charles Keepax wrote:
> On Fri, Jan 26, 2018 at 12:33:53AM +0000, Kuninori Morimoto wrote:

> > Thus, if we can replace all CPU/Codec/Platform into component, every device
> > can have every feature, with no categorize !
> > In other words, we don't know how many device have it.

> Yeah I think there is quite a lot more work to get to that point
> though, we need to understand how we will present this to
> user-space.

I think some of this will sort itself out for the immediate future
through implementation choices in that we've not yet seen a system where
it'd make sense to combine multiple DAIs with compressed ops and don't
seem likely to right now.
diff mbox

Patch

diff --git a/sound/soc/soc-compress.c b/sound/soc/soc-compress.c
index 81232f4..a147a03 100644
--- a/sound/soc/soc-compress.c
+++ b/sound/soc/soc-compress.c
@@ -53,6 +53,7 @@  static int soc_compr_open(struct snd_compr_stream *cstream)
 				platform->component.name);
 			goto plat_err;
 		}
+		goto rtdcom_skip:
 	}
 
 	for_each_rtdcom(rtd, rtdcom) {
@@ -72,10 +73,13 @@  static int soc_compr_open(struct snd_compr_stream *cstream)
 			       component->name);
 			ret = __ret;
 		}
+		break;
 	}
 	if (ret < 0)
 		goto machine_err;
 
+rtdcom_skip:
+
 	if (rtd->dai_link->compr_ops && rtd->dai_link->compr_ops->startup) {
 		ret = rtd->dai_link->compr_ops->startup(cstream);
 		if (ret < 0) {