• Kuninori Morimoto's avatar
    ASoC: rsnd: call rsnd_ssi_master_clk_start() from rsnd_ssi_init() · a122a116
    Kuninori Morimoto authored
    Current rsnd needs to call .prepare (P) for clock settings,
    .trigger for playback start (S) and stop (E).
    It should be called as below from SSI point of view.
    
    	P -> S -> E -> P -> S -> E -> ...
    
    But, if you used MIXer, below case might happen
    
    	              (2)
    	1: P -> S ---> E -> ...
    	2:         P ----> S -> ...
    	          (1)     (3)
    
    P(1) setups clock, but E(2) resets it. and starts playback (3).
    In such case, it will reports "SSI parent/child should use same rate".
    
    rsnd_ssi_master_clk_start() which is the main function at (P)
    was called from rsnd_ssi_init() (= S) before,
    but was moved by below patch to rsnd_soc_dai_prepare() (= P) to avoid
    using clk_get_rate() which shouldn't be used under atomic context.
    
    	commit 4d230d12 ("ASoC: rsnd: fixup not to call clk_get/set
    				under non-atomic")
    
    Because of above patch, rsnd_ssi_master_clk_start() is now called at (P)
    which is for non atomic context. But (P) is assuming that spin lock is
    *not* used.
    One issue now is rsnd_ssi_master_clk_start() is checking ssi->xxx
    which should be protected by spin lock.
    
    After above patch, adg.c had below patch for other reasons.
    
    	commit 06e8f5c8 ("ASoC: rsnd: don't call clk_get_rate()
    				under atomic context")
    
    clk_get_rate() is used at probe() timing by this patch.
    In other words, rsnd_ssi_master_clk_start() is no longer using
    clk_get_rate() any more.
    
    This means we can call it from rsnd_ssi_init() (= S) again which is
    protected by spin lock.
    This patch re-move it to under spin lock, and solves
    1. checking ssi->xxx without spin lock issue.
    2. clk setting / device start / device stop race condition.
    Reported-by: default avatarLinh Phung T. Y. <linh.phung.jy@renesas.com>
    Signed-off-by: default avatarKuninori Morimoto <kuninori.morimoto.gx@renesas.com>
    Link: https://lore.kernel.org/r/875z0x1jt5.wl-kuninori.morimoto.gx@renesas.comSigned-off-by: default avatarMark Brown <broonie@kernel.org>
    a122a116
ssi.c 28.7 KB