[alsa-devel] [RFC PATCH] ASoC: dpcm: prevent snd_soc_dpcm use after free

Kuninori Morimoto kuninori.morimoto.gx at renesas.com
Wed Mar 6 09:20:51 CET 2019


Hi

Small comment from me

> @@ -3257,9 +3268,12 @@ int snd_soc_dpcm_can_be_params(struct snd_soc_pcm_runtime *fe,
>  		if (state == SND_SOC_DPCM_STATE_START ||
>  			state == SND_SOC_DPCM_STATE_PAUSED ||
>  			state == SND_SOC_DPCM_STATE_SUSPEND ||
> -			state == SND_SOC_DPCM_STATE_PREPARE)
> +			state == SND_SOC_DPCM_STATE_PREPARE) {
> +			spin_unlock(&fe->card->dpcm_lock);
>  			return 0;
> +		}
>  	}
> +			spin_unlock(&fe->card->dpcm_lock);

1st is you want to alignment last spin_unlock() position.
2ns is you want to have clean code which can avoid multiple unlock

	ret = 1; // default

	spin_lock()
	for_each_dpcm_fe(be, stream, dpcm) {
		...
		if (xxx) {
			ret = 0;
			break;
		}
	}
	spin_unlock()

	return ret;

Best regards
---
Kuninori Morimoto


More information about the Alsa-devel mailing list