Skip to contentSkip to conversation

ALSA: compress: Cleanup and a potential fix

PATCH In review Takashi Iwai 5 participants 10 messages Jul 14, 2021 – Jul 15, 2021

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

cover ALSA: compress: Cleanup and a potential fix

Hi,

this series contains a couple of patches for compress-offload API, one for a cleanup of unused API functions and another for the proper mutex initialization. I stumbled on the second while doing the first.

Takashi

===

Takashi Iwai (2):
ALSA: compress: Drop unused functions
ALSA: compress: Initialize mutex in snd_compress_new()

 include/sound/compress_driver.h |  2 -
 sound/core/compress_offload.c   | 69 +--------------------------------
 sound/soc/soc-compress.c        |  1 -
 3 files changed, 1 insertion(+), 71 deletions(-)
Signature · 1 line
2.26.2
#1 lore raw

PATCH 1/2 ALSA: compress: Drop unused functions

snd_compress_register() and snd_compress_deregister() API functions have been never used by in-tree drivers.
Let's clean up the dead code.

---
 include/sound/compress_driver.h |  2 -
 sound/core/compress_offload.c   | 68 ---------------------------------
 2 files changed, 70 deletions(-)
include/sound/compress_driver.h +0 -2
index 277087f635f3..d91289c6f00e 100644
@@ -165,8 +165,6 @@ struct snd_compr {
 };
 
 /* compress device register APIs */
-int snd_compress_register(struct snd_compr *device);
-int snd_compress_deregister(struct snd_compr *device);
 int snd_compress_new(struct snd_card *card, int device,
 			int type, const char *id, struct snd_compr *compr);
 
sound/core/compress_offload.c +0 -68

80 lines not on this page · raw message

Signature · 1 line
2.26.2
#2 lore raw

PATCH 2/2 ALSA: compress: Initialize mutex in snd_compress_new()

In reply to Takashi Iwai

Currently the snd_compr.lock mutex isn't initialized in the API functions although the lock is used many places in other code in compress offload API. It's because the object was expected to be initialized via snd_compress_register(), but this was never used by ASoC, which is the only user. Instead, ASoC initializes the mutex by itself, and this is error-prone.

This patch moves the mutex initialization into the more appropriate place, snd_compress_new(), for avoiding the missing init.

---
 sound/core/compress_offload.c | 1 +
 sound/soc/soc-compress.c      | 1 -
 2 files changed, 1 insertion(+), 1 deletion(-)
sound/core/compress_offload.c +1 -0
index ed5546ae300a..de514ec8c83d 100644
@@ -1177,6 +1177,7 @@ int snd_compress_new(struct snd_card *card, int device,
 	compr->card = card;
 	compr->device = device;
 	compr->direction = dirn;
+	mutex_init(&compr->lock);
 
 	snd_compress_set_id(compr, id);
 
sound/soc/soc-compress.c +0 -1
index b4f59350a5a8..36060800e9bd 100644
@@ -604,7 +604,6 @@ int snd_soc_new_compress(struct snd_soc_pcm_runtime *rtd, int num)
 		break;
 	}
 
-	mutex_init(&compr->lock);
 	ret = snd_compress_new(rtd->card->snd_card, num, direction,
 				new_name, compr);
 	if (ret < 0) {
Signature · 1 line
2.26.2
maintainer Reviewed-by on v1 2/2
#3 lore raw

Re: [PATCH 2/2] ALSA: compress: Initialize mutex in snd_compress_new()

Quoted 6 lines · Takashi Iwai

Currently the snd_compr.lock mutex isn't initialized in the API functions although the lock is used many places in other code in compress offload API. It's because the object was expected to be initialized via snd_compress_register(), but this was never used by ASoC, which is the only user. Instead, ASoC initializes the mutex by itself, and this is error-prone.

maintainer Acked-by on the v1 series
#4 lore raw
In reply to Takashi Iwai
Quoted 5 lines · Takashi Iwai

Hi,

this series contains a couple of patches for compress-offload API, one for a cleanup of unused API functions and another for the proper mutex initialization. I stumbled on the second while doing the first.

Thanks for the cleanup. We never have a compress only device and it is a mix of PCM and compress FEs mostly :)

So:

Signature · 1 line
~Vinod
#5 lore raw
Quoted 9 lines · Vinod Koul
Quoted 5 lines · Takashi Iwai

Hi,

this series contains a couple of patches for compress-offload API, one for a cleanup of unused API functions and another for the proper mutex initialization. I stumbled on the second while doing the first.

Thanks for the cleanup. We never have a compress only device and it is a mix of PCM and compress FEs mostly :)

Actually I'm working on a series where a card would only contain nothing else but a compr, no PCMs...

Quoted 5 lines

So:

Signature · 1 line
Péter
#6 lore raw
Quoted 10 lines · Péter Ujfalusi
Quoted 7 lines · Vinod Koul
Quoted 5 lines · Takashi Iwai

Hi,

this series contains a couple of patches for compress-offload API, one for a cleanup of unused API functions and another for the proper mutex initialization. I stumbled on the second while doing the first.

Quoted 5 lines
Quoted 2 lines

Thanks for the cleanup. We never have a compress only device and it is a mix of PCM and compress FEs mostly :)

Actually I'm working on a series where a card would only contain nothing else but a compr, no PCMs...

and I should have replied from here ;)

I'm preparing to split up the SOF into IPC clients [1] and the probes support (which is using compress API) is going to be moved as a separate client, creating it's own sound card with the single comprCxD0 (and the controlCx).

Is this cleanup going to prevent this?

[1] https://github.com/thesofproject/linux/pull/3007

Signature · 1 line
Péter
#7 lore raw
Quoted 20 lines · Peter
Quoted 10 lines · Péter Ujfalusi
Quoted 7 lines · Vinod Koul
Quoted 5 lines · Takashi Iwai

Hi,

this series contains a couple of patches for compress-offload API, one for a cleanup of unused API functions and another for the proper mutex initialization. I stumbled on the second while doing the first.

Quoted 5 lines
Quoted 2 lines

Thanks for the cleanup. We never have a compress only device and it is a mix of PCM and compress FEs mostly :)

Actually I'm working on a series where a card would only contain nothing else but a compr, no PCMs...

Quoted 8 lines

and I should have replied from here ;)

I'm preparing to split up the SOF into IPC clients [1] and the probes support (which is using compress API) is going to be moved as a separate client, creating it's own sound card with the single comprCxD0 (and the controlCx).

Is this cleanup going to prevent this?

Unless you use snd_compress_register() function, nothing can break. And if you were to use the function together with ASoC, it must be very wrong :)

Takashi

Reviewed-by
#8 lore raw
Quoted 29 lines · Takashi Iwai
Quoted 27 lines · Peter
Quoted 10 lines · Péter Ujfalusi
Quoted 7 lines · Vinod Koul
Quoted 5 lines · Takashi Iwai

Hi,

this series contains a couple of patches for compress-offload API, one for a cleanup of unused API functions and another for the proper mutex initialization. I stumbled on the second while doing the first.

Quoted 5 lines
Quoted 2 lines

Thanks for the cleanup. We never have a compress only device and it is a mix of PCM and compress FEs mostly :)

Actually I'm working on a series where a card would only contain nothing else but a compr, no PCMs...

and I should have replied from here ;)

I'm preparing to split up the SOF into IPC clients [1] and the probes support (which is using compress API) is going to be moved as a separate client, creating it's own sound card with the single comprCxD0 (and the controlCx).

Quoted 5 lines
Quoted 1 line

Is this cleanup going to prevent this?

Unless you use snd_compress_register() function, nothing can break. And if you were to use the function together with ASoC, it must be very wrong :)

Yes, I just checked the patch ;)

and since I just did that:

Thank you,
Péter

#9 lore raw
In reply to Takashi Iwai
Quoted 8 lines · Takashi Iwai

Hi,

this series contains a couple of patches for compress-offload API, one for a cleanup of unused API functions and another for the proper mutex initialization. I stumbled on the second while doing the first.

Quoted 7 lines

Takashi

===

Takashi Iwai (2):
ALSA: compress: Drop unused functions
ALSA: compress: Initialize mutex in snd_compress_new()

Applied now to for-next branch.

Takashi