ASoC: mediatek: Use guard() for mutex & spin locks
Subsystems (4)
cover ASoC: mediatek: Use guard() for mutex & spin locks
From: bui duc phuc <[email protected]>
Hi all,
This series converts mutex and spinlock handling in Mediatek ASoC drivers to use guard() helpers.
Most patches are straightforward conversions to guard() helpers with no functional change intended.
One exception is mt8192-afe-gpio, where the mutex release point moves from immediately before dev_warn() to scope exit. However, the affected path only emits a warning and immediately returns -EINVAL, without any further processing.
Compile-tested only.
Best regards,
Phuc
bui duc phuc (10):
ASoC: mediatek: common: mtk-afe-fe-dai: Use guard() for mutex locks
ASoC: mediatek: common: mtk-btcvsd: Use guard() for spin locks
ASoC: mediatek: mt8186: mt8186-afe-gpio: Use guard() for mutex locks
ASoC: mediatek: mt8188: mt8188-afe-clk: Use guard() for spin locks
ASoC: mediatek: mt8192: mt8192-afe-gpio: Use guard() for mutex locks
ASoC: mediatek: mt8195: mt8195-afe-clk: Use guard() for spin locks
ASoC: mediatek: mt8195: mt8195-dai-etdm: Use guard() for spin locks
ASoC: mediatek: mt8195: mt8365-afe-clk: Use guard() for mutex & spin
locks
ASoC: mediatek: mt8195: mt8365-dai-adda: Use guard() for spin locks
ASoC: mediatek: mt8195: mt8365-dai-i2s: Use guard() for spin locks
sound/soc/mediatek/common/mtk-afe-fe-dai.c | 8 +- sound/soc/mediatek/common/mtk-btcvsd.c | 81 +++++++++------------ sound/soc/mediatek/mt8186/mt8186-afe-gpio.c | 13 +--- sound/soc/mediatek/mt8188/mt8188-afe-clk.c | 29 +++----- sound/soc/mediatek/mt8192/mt8192-afe-gpio.c | 4 +- sound/soc/mediatek/mt8195/mt8195-afe-clk.c | 42 +++++------ sound/soc/mediatek/mt8195/mt8195-dai-etdm.c | 16 ++-- sound/soc/mediatek/mt8365/mt8365-afe-clk.c | 30 ++------ sound/soc/mediatek/mt8365/mt8365-dai-adda.c | 10 +-- sound/soc/mediatek/mt8365/mt8365-dai-i2s.c | 5 +- 10 files changed, 87 insertions(+), 151 deletions(-)
Signature · 1 line
2.43.0
PATCH 1/10 ASoC: mediatek: common: mtk-afe-fe-dai: Use guard() for mutex locks
From: bui duc phuc <[email protected]>
Clean up the code using guard() for mutex locks.
Merely code refactoring, and no behavior change.
--- sound/soc/mediatek/common/mtk-afe-fe-dai.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-)
sound/soc/mediatek/common/mtk-afe-fe-dai.c +2 -6
@@ -292,28 +292,24 @@ int mtk_dynamic_irq_acquire(struct mtk_base_afe *afe) {int i; -mutex_lock (&afe->irq_alloc_lock); +guard (mutex)(&afe->irq_alloc_lock);for (i =0 ; i < afe->irqs_size; ++i) {if (afe->irqs[i].irq_occupyed ==0 ) { afe->irqs[i].irq_occupyed =1 ; -mutex_unlock (&afe->irq_alloc_lock);return i; } } -mutex_unlock (&afe->irq_alloc_lock);return afe->irqs_size; }EXPORT_SYMBOL_GPL (mtk_dynamic_irq_acquire);int mtk_dynamic_irq_release (struct mtk_base_afe *afe,int irq_id) { -mutex_lock (&afe->irq_alloc_lock); +guard (mutex)(&afe->irq_alloc_lock);if (irq_id >=0 && irq_id < afe->irqs_size) { afe->irqs[irq_id].irq_occupyed =0 ; -mutex_unlock (&afe->irq_alloc_lock);return 0 ; } -mutex_unlock (&afe->irq_alloc_lock);return -EINVAL ; }EXPORT_SYMBOL_GPL (mtk_dynamic_irq_release);
Signature · 1 line
2.43.0
PATCH 2/10 ASoC: mediatek: common: mtk-btcvsd: Use guard() for spin locks
In reply to [email protected]From: bui duc phuc <[email protected]>
Clean up the code using guard() for spin locks.
Merely code refactoring, and no behavior change.
--- sound/soc/mediatek/common/mtk-btcvsd.c | 81 +++++++++++--------------- 1 file changed, 35 insertions(+), 46 deletions(-)
sound/soc/mediatek/common/mtk-btcvsd.c +35 -46
@@ -319,7 +319,6 @@ static int btcvsd_tx_clean_buffer(struct mtk_btcvsd_snd *bt) {unsigned int i;unsigned int num_valid_addr; -unsigned long flags;enum BT_SCO_BAND band = bt->band;/* prepare encoded mute data */
@@ -330,7 +329,7 @@ static int btcvsd_tx_clean_buffer(struct mtk_btcvsd_snd *bt) table_msbc_silence, SCO_PACKET_180);/* write mute data to bt tx sram buffer */ -spin_lock_irqsave (&bt->tx_lock, flags); +guard (spinlock_irqsave)(&bt->tx_lock); num_valid_addr = bt->tx->buffer_info.num_valid_addr; dev_info(bt->dev, "%s(), band %d, num_valid_addr %u\n",
@@ -349,7 +348,6 @@ static int btcvsd_tx_clean_buffer(struct mtk_btcvsd_snd *bt) bt->tx->buffer_info.packet_length, bt->tx->buffer_info.packet_num); } -spin_unlock_irqrestore (&bt->tx_lock, flags);return 0 ; }
@@ -365,7 +363,6 @@ static int mtk_btcvsd_read_from_bt(struct mtk_btcvsd_snd *bt,int pv;u8 *src;unsigned int packet_buf_ofs; -unsigned long flags;unsigned long connsys_addr_rx, ap_addr_rx; connsys_addr_rx = *bt->bt_reg_pkt_r;
@@ -385,7 +382,7 @@ static int mtk_btcvsd_read_from_bt(struct mtk_btcvsd_snd *bt, bt->rx->temp_packet_buf, packet_length, packet_num); -spin_lock_irqsave (&bt->rx_lock, flags); +guard (spinlock_irqsave)(&bt->rx_lock);for (i =0 ; i < blk_size; i++) { packet_buf_ofs = (bt->rx->packet_w &SCO_RX_PACKET_MASK ) * bt->rx->packet_size;
@@ -403,7 +400,7 @@ static int mtk_btcvsd_read_from_bt(struct mtk_btcvsd_snd *bt, SCO_CVSD_PACKET_VALID_SIZE); bt->rx->packet_w++; } -spin_unlock_irqrestore (&bt->rx_lock, flags); +return 0 ; }
@@ -414,7 +411,6 @@ static int mtk_btcvsd_write_to_bt(struct mtk_btcvsd_snd *bt, unsigned int blk_size) {unsigned int i; -unsigned long flags;u8 *dst;unsigned long connsys_addr_tx, ap_addr_tx;bool new_ap_addr_tx = true;
@@ -430,17 +426,17 @@ static int mtk_btcvsd_write_to_bt(struct mtk_btcvsd_snd *bt,return -EIO ; } -spin_lock_irqsave (&bt->tx_lock, flags); -for (i =0 ; i < blk_size; i++) { -memcpy (bt->tx->temp_packet_buf + (bt->tx->packet_size * i), - (bt->tx_packet_buf + - (bt->tx->packet_r %SCO_TX_PACKER_BUF_NUM ) * - bt->tx->packet_size), - bt->tx->packet_size); + scoped_guard(spinlock_irqsave, &bt->tx_lock) { +for (i =0 ; i < blk_size; i++) { +memcpy (bt->tx->temp_packet_buf + (bt->tx->packet_size * i), + (bt->tx_packet_buf + + (bt->tx->packet_r %SCO_TX_PACKER_BUF_NUM ) * + bt->tx->packet_size), + bt->tx->packet_size); - bt->tx->packet_r++; + bt->tx->packet_r++; + } } -spin_unlock_irqrestore (&bt->tx_lock, flags); dst = (u8 *)ap_addr_tx;
@@ -462,11 +458,11 @@ static int mtk_btcvsd_write_to_bt(struct mtk_btcvsd_snd *bt,if (new_ap_addr_tx) {unsigned int next_idx; -spin_lock_irqsave (&bt->tx_lock, flags); - bt->tx->buffer_info.num_valid_addr++; - next_idx = bt->tx->buffer_info.num_valid_addr -1 ; - bt->tx->buffer_info.bt_sram_addr[next_idx] = ap_addr_tx; -spin_unlock_irqrestore (&bt->tx_lock, flags); + scoped_guard(spinlock_irqsave, &bt->tx_lock) { + bt->tx->buffer_info.num_valid_addr++; + next_idx = bt->tx->buffer_info.num_valid_addr -1 ; + bt->tx->buffer_info.bt_sram_addr[next_idx] = ap_addr_tx; + }dev_info (bt->dev,"%s(), new ap_addr_tx = 0x%lx, num_valid_addr %d\n" , __func__, ap_addr_tx, bt->tx->buffer_info.num_valid_addr);
@@ -701,17 +697,16 @@ static ssize_t mtk_btcvsd_snd_read(struct mtk_btcvsd_snd *bt, {ssize_t read_size =0 , read_count =0 , cur_read_idx, cont;unsigned long avail; -unsigned long flags;unsigned int packet_size = bt->rx->packet_size;while (count) { -spin_lock_irqsave (&bt->rx_lock, flags); -/* available data in RX packet buffer */ - avail = (bt->rx->packet_w - bt->rx->packet_r) * packet_size; + scoped_guard(spinlock_irqsave, &bt->rx_lock) { +/* available data in RX packet buffer */ + avail = (bt->rx->packet_w - bt->rx->packet_r) * packet_size; - cur_read_idx = (bt->rx->packet_r &SCO_RX_PACKET_MASK ) * - packet_size; -spin_unlock_irqrestore (&bt->rx_lock, flags); + cur_read_idx = (bt->rx->packet_r &SCO_RX_PACKET_MASK ) * + packet_size; + }if (!avail) {int ret =wait_for_bt_irq (bt, bt->rx);
@@ -749,9 +744,8 @@ static ssize_t mtk_btcvsd_snd_read(struct mtk_btcvsd_snd *bt,return -EFAULT ; } -spin_lock_irqsave (&bt->rx_lock, flags); - bt->rx->packet_r += read_size / packet_size; -spin_unlock_irqrestore (&bt->rx_lock, flags); +scoped_guard (spinlock_irqsave, &bt->rx_lock) + bt->rx->packet_r += read_size / packet_size; read_count += read_size; count -= read_size;
@@ -778,7 +772,6 @@ static ssize_t mtk_btcvsd_snd_write(struct mtk_btcvsd_snd *bt, size_t count) {int written_size = count, avail, cur_write_idx, write_size, cont; -unsigned long flags;unsigned int packet_size = bt->tx->packet_size;/*
@@ -794,14 +787,14 @@ static ssize_t mtk_btcvsd_snd_write(struct mtk_btcvsd_snd *bt, bt->tx->buf_data_equivalent_time *=1000 ;while (count) { -spin_lock_irqsave (&bt->tx_lock, flags); -/* free space of TX packet buffer */ - avail = bt->tx->buf_size - - (bt->tx->packet_w - bt->tx->packet_r) * packet_size; + scoped_guard(spinlock_irqsave, &bt->tx_lock) { +/* free space of TX packet buffer */ + avail = bt->tx->buf_size - + (bt->tx->packet_w - bt->tx->packet_r) * packet_size; - cur_write_idx = (bt->tx->packet_w %SCO_TX_PACKER_BUF_NUM ) * - packet_size; -spin_unlock_irqrestore (&bt->tx_lock, flags); + cur_write_idx = (bt->tx->packet_w %SCO_TX_PACKER_BUF_NUM ) * + packet_size; + }if (!avail) {int ret =wait_for_bt_irq (bt, bt->tx);
@@ -838,9 +831,8 @@ static ssize_t mtk_btcvsd_snd_write(struct mtk_btcvsd_snd *bt,return -EFAULT ; } -spin_lock_irqsave (&bt->tx_lock, flags); - bt->tx->packet_w += write_size / packet_size; -spin_unlock_irqrestore (&bt->tx_lock, flags); +scoped_guard (spinlock_irqsave, &bt->tx_lock) + bt->tx->packet_w += write_size / packet_size; count -= write_size; }
@@ -985,7 +977,6 @@ static snd_pcm_uframes_t mtk_pcm_btcvsd_pointer(int hw_packet_ptr;int packet_diff;spinlock_t *lock;/* spinlock for bt stream control */ -unsigned long flags;if (substream->stream ==SNDRV_PCM_STREAM_PLAYBACK ) { lock = &bt->tx_lock;
@@ -995,7 +986,7 @@ static snd_pcm_uframes_t mtk_pcm_btcvsd_pointer( bt_stream = bt->rx; } -spin_lock_irqsave (lock, flags); +guard (spinlock_irqsave)(lock); hw_packet_ptr = substream->stream ==SNDRV_PCM_STREAM_PLAYBACK ? bt->tx->packet_r : bt->rx->packet_w;
@@ -1018,8 +1009,6 @@ static snd_pcm_uframes_t mtk_pcm_btcvsd_pointer( bt_stream->prev_frame = frame; -spin_unlock_irqrestore (lock, flags); -return frame; }
Signature · 1 line
2.43.0
PATCH 3/10 ASoC: mediatek: mt8186: mt8186-afe-gpio: Use guard() for mutex locks
In reply to [email protected]From: bui duc phuc <[email protected]>
Clean up the code using guard() for mutex locks.
Merely code refactoring, and no behavior change.
--- sound/soc/mediatek/mt8186/mt8186-afe-gpio.c | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-)
sound/soc/mediatek/mt8186/mt8186-afe-gpio.c +4 -9
@@ -201,7 +201,7 @@ int mt8186_afe_gpio_request(struct device *dev, bool enable,enum mt8186_afe_gpio sel;int ret = -EINVAL ; -mutex_lock (&gpio_request_mutex); +guard (mutex)(&gpio_request_mutex);switch (dai) {case MT8186_DAI_ADDA :
@@ -209,7 +209,7 @@ int mt8186_afe_gpio_request(struct device *dev, bool enable, ret =mt8186_afe_gpio_adda_ul (dev, enable); else ret =mt8186_afe_gpio_adda_dl (dev, enable); - goto unlock; +return ret;case MT8186_DAI_I2S_0 : sel = enable ?MT8186_AFE_GPIO_I2S0_ON :MT8186_AFE_GPIO_I2S0_OFF ;break ;
@@ -230,13 +230,8 @@ int mt8186_afe_gpio_request(struct device *dev, bool enable,break ;default :dev_dbg (dev,"%s(), invalid dai %d\n" , __func__, dai); - goto unlock; +return ret; } - ret =mt8186_afe_gpio_select (dev, sel); - -unlock: -mutex_unlock (&gpio_request_mutex); - -return ret; +return mt8186_afe_gpio_select (dev, sel); }
Signature · 1 line
2.43.0
PATCH 4/10 ASoC: mediatek: mt8188: mt8188-afe-clk: Use guard() for spin locks
In reply to [email protected]From: bui duc phuc <[email protected]>
Clean up the code using guard() for spin locks.
Merely code refactoring, and no behavior change.
--- sound/soc/mediatek/mt8188/mt8188-afe-clk.c | 29 ++++++++-------------- 1 file changed, 11 insertions(+), 18 deletions(-)
sound/soc/mediatek/mt8188/mt8188-afe-clk.c +11 -18
@@ -301,7 +301,6 @@ static int mt8188_afe_disable_tuner_clk(struct mtk_base_afe *afe,static int mt8188_afe_enable_apll_tuner (struct mtk_base_afe *afe,unsigned int id) {struct mt8188_afe_tuner_cfg *cfg =mt8188_afe_found_apll_tuner (id); -unsigned long flags;int ret;if (!cfg)
@@ -315,8 +314,7 @@ static int mt8188_afe_enable_apll_tuner(struct mtk_base_afe *afe, unsigned int iif (ret)return ret; -spin_lock_irqsave (&cfg->ctrl_lock, flags); - +guard (spinlock_irqsave)(&cfg->ctrl_lock); cfg->ref_cnt++;if (cfg->ref_cnt ==1 ) regmap_update_bits(afe->regmap,
@@ -324,32 +322,27 @@ static int mt8188_afe_enable_apll_tuner(struct mtk_base_afe *afe, unsigned int i cfg->tuner_en_maskbit << cfg->tuner_en_shift, BIT(cfg->tuner_en_shift)); -spin_unlock_irqrestore (&cfg->ctrl_lock, flags); -return 0 ; }static int mt8188_afe_disable_apll_tuner (struct mtk_base_afe *afe,unsigned int id) {struct mt8188_afe_tuner_cfg *cfg =mt8188_afe_found_apll_tuner (id); -unsigned long flags;int ret;if (!cfg)return -EINVAL ; -spin_lock_irqsave (&cfg->ctrl_lock, flags); - - cfg->ref_cnt--; -if (cfg->ref_cnt ==0 ) -regmap_update_bits (afe->regmap, - cfg->tuner_en_reg, - cfg->tuner_en_maskbit << cfg->tuner_en_shift, -0 << cfg->tuner_en_shift); -else if (cfg->ref_cnt <0 ) - cfg->ref_cnt =0 ; - -spin_unlock_irqrestore (&cfg->ctrl_lock, flags); + scoped_guard(spinlock_irqsave, &cfg->ctrl_lock) { + cfg->ref_cnt--; +if (cfg->ref_cnt ==0 ) +regmap_update_bits (afe->regmap, + cfg->tuner_en_reg, + cfg->tuner_en_maskbit << cfg->tuner_en_shift, +0 << cfg->tuner_en_shift); +else if (cfg->ref_cnt <0 ) + cfg->ref_cnt =0 ; + } ret =mt8188_afe_disable_tuner_clk (afe, id);if (ret)
Signature · 1 line
2.43.0
PATCH 5/10 ASoC: mediatek: mt8192: mt8192-afe-gpio: Use guard() for mutex locks
In reply to [email protected]From: bui duc phuc <[email protected]>
Convert the explicit mutex_lock()/mutex_unlock() pair to guard(mutex) to simplify the locking logic and automatically release the mutex on all exit paths.
This changes the mutex release point from immediately before dev_warn() to automatic cleanup at scope exit. However, the affected path only emits a warning and immediately returns -EINVAL, without any further processing.
--- sound/soc/mediatek/mt8192/mt8192-afe-gpio.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
sound/soc/mediatek/mt8192/mt8192-afe-gpio.c +1 -3
@@ -208,7 +208,7 @@ static int mt8192_afe_gpio_adda_ch34_ul(struct device *dev, bool enable)int mt8192_afe_gpio_request (struct device *dev,bool enable,int dai,int uplink) { -mutex_lock (&gpio_request_mutex); +guard (mutex)(&gpio_request_mutex);switch (dai) {case MT8192_DAI_ADDA :if (uplink)
@@ -296,11 +296,9 @@ int mt8192_afe_gpio_request(struct device *dev, bool enable, }break ;default : -mutex_unlock (&gpio_request_mutex);dev_warn (dev,"%s(), invalid dai %d\n" , __func__, dai);return -EINVAL ; } -mutex_unlock (&gpio_request_mutex);return 0 ; }
Signature · 1 line
2.43.0
PATCH 6/10 ASoC: mediatek: mt8195: mt8195-afe-clk: Use guard() for spin locks
In reply to [email protected]From: bui duc phuc <[email protected]>
Clean up the code using guard() for spin locks.
Merely code refactoring, and no behavior change.
--- sound/soc/mediatek/mt8195/mt8195-afe-clk.c | 42 ++++++++++------------ 1 file changed, 18 insertions(+), 24 deletions(-)
sound/soc/mediatek/mt8195/mt8195-afe-clk.c +18 -24
@@ -283,7 +283,6 @@ static int mt8195_afe_enable_apll_tuner(struct mtk_base_afe *afe, unsigned int id) {struct mt8195_afe_tuner_cfg *cfg =mt8195_afe_found_apll_tuner (id); -unsigned long flags;int ret;if (!cfg)
@@ -297,16 +296,14 @@ static int mt8195_afe_enable_apll_tuner(struct mtk_base_afe *afe,if (ret)return ret; -spin_lock_irqsave (&cfg->ctrl_lock, flags); - - cfg->ref_cnt++; -if (cfg->ref_cnt ==1 ) -regmap_update_bits (afe->regmap, - cfg->tuner_en_reg, - cfg->tuner_en_maskbit << cfg->tuner_en_shift, -1 << cfg->tuner_en_shift); - -spin_unlock_irqrestore (&cfg->ctrl_lock, flags); + scoped_guard(spinlock_irqsave, &cfg->ctrl_lock) { + cfg->ref_cnt++; +if (cfg->ref_cnt ==1 ) +regmap_update_bits (afe->regmap, + cfg->tuner_en_reg, + cfg->tuner_en_maskbit << cfg->tuner_en_shift, +1 << cfg->tuner_en_shift); + }return 0 ; }
@@ -315,24 +312,21 @@ static int mt8195_afe_disable_apll_tuner(struct mtk_base_afe *afe, unsigned int id) {struct mt8195_afe_tuner_cfg *cfg =mt8195_afe_found_apll_tuner (id); -unsigned long flags;int ret;if (!cfg)return -EINVAL ; -spin_lock_irqsave (&cfg->ctrl_lock, flags); - - cfg->ref_cnt--; -if (cfg->ref_cnt ==0 ) -regmap_update_bits (afe->regmap, - cfg->tuner_en_reg, - cfg->tuner_en_maskbit << cfg->tuner_en_shift, -0 << cfg->tuner_en_shift); -else if (cfg->ref_cnt <0 ) - cfg->ref_cnt =0 ; - -spin_unlock_irqrestore (&cfg->ctrl_lock, flags); + scoped_guard(spinlock_irqsave, &cfg->ctrl_lock) { + cfg->ref_cnt--; +if (cfg->ref_cnt ==0 ) +regmap_update_bits (afe->regmap, + cfg->tuner_en_reg, + cfg->tuner_en_maskbit << cfg->tuner_en_shift, +0 << cfg->tuner_en_shift); +else if (cfg->ref_cnt <0 ) + cfg->ref_cnt =0 ; + } ret =mt8195_afe_disable_tuner_clk (afe, id);if (ret)
Signature · 1 line
2.43.0
PATCH 7/10 ASoC: mediatek: mt8195: mt8195-dai-etdm: Use guard() for spin locks
In reply to [email protected]From: bui duc phuc <[email protected]>
Clean up the code using guard() for spin locks.
Merely code refactoring, and no behavior change.
--- sound/soc/mediatek/mt8195/mt8195-dai-etdm.c | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-)
sound/soc/mediatek/mt8195/mt8195-dai-etdm.c +6 -10
@@ -1318,24 +1318,22 @@ static int mt8195_afe_enable_etdm(struct mtk_base_afe *afe, int dai_id)struct etdm_con_reg etdm_reg;struct mt8195_afe_private *afe_priv = afe->platform_priv;struct mtk_dai_etdm_priv *etdm_data; -unsigned long flags;if (!mt8195_afe_etdm_is_valid (dai_id))return -EINVAL ; etdm_data = afe_priv->dai_priv[dai_id]; -spin_lock_irqsave (&afe_priv->afe_ctrl_lock, flags); +guard (spinlock_irqsave)(&afe_priv->afe_ctrl_lock); etdm_data->en_ref_cnt++;if (etdm_data->en_ref_cnt ==1 ) { ret =get_etdm_reg (dai_id, &etdm_reg);if (ret <0 ) - goto out; +return ret;regmap_update_bits (afe->regmap, etdm_reg.con0,ETDM_CON0_EN ,ETDM_CON0_EN ); } -out: -spin_unlock_irqrestore (&afe_priv->afe_ctrl_lock, flags); +return ret; }
@@ -1345,26 +1343,24 @@ static int mt8195_afe_disable_etdm(struct mtk_base_afe *afe, int dai_id)struct etdm_con_reg etdm_reg;struct mt8195_afe_private *afe_priv = afe->platform_priv;struct mtk_dai_etdm_priv *etdm_data; -unsigned long flags;if (!mt8195_afe_etdm_is_valid (dai_id))return -EINVAL ; etdm_data = afe_priv->dai_priv[dai_id]; -spin_lock_irqsave (&afe_priv->afe_ctrl_lock, flags); +guard (spinlock_irqsave)(&afe_priv->afe_ctrl_lock);if (etdm_data->en_ref_cnt >0 ) { etdm_data->en_ref_cnt--;if (etdm_data->en_ref_cnt ==0 ) { ret =get_etdm_reg (dai_id, &etdm_reg);if (ret <0 ) - goto out; +return ret;regmap_update_bits (afe->regmap, etdm_reg.con0,ETDM_CON0_EN ,0 ); } } -out: -spin_unlock_irqrestore (&afe_priv->afe_ctrl_lock, flags); +return ret; }
Signature · 1 line
2.43.0
PATCH 8/10 ASoC: mediatek: mt8195: mt8365-afe-clk: Use guard() for mutex & spin locks
In reply to [email protected]From: bui duc phuc <[email protected]>
Clean up the code using guard() for mutex & spin locks. Merely code refactoring, and no behavior change.
--- sound/soc/mediatek/mt8365/mt8365-afe-clk.c | 30 +++++----------------- 1 file changed, 7 insertions(+), 23 deletions(-)
sound/soc/mediatek/mt8365/mt8365-afe-clk.c +7 -23
@@ -194,16 +194,13 @@ int mt8365_afe_enable_top_cg(struct mtk_base_afe *afe, unsigned int cg_type)unsigned int reg =get_top_cg_reg (cg_type);unsigned int mask =get_top_cg_mask (cg_type);unsigned int val =get_top_cg_on_val (cg_type); -unsigned long flags; -spin_lock_irqsave (&afe_priv->afe_ctrl_lock, flags); +guard (spinlock_irqsave)(&afe_priv->afe_ctrl_lock); afe_priv->top_cg_ref_cnt[cg_type]++;if (afe_priv->top_cg_ref_cnt[cg_type] ==1 )regmap_update_bits (afe->regmap, reg, mask, val); -spin_unlock_irqrestore (&afe_priv->afe_ctrl_lock, flags); -return 0 ; }
@@ -213,9 +210,8 @@ int mt8365_afe_disable_top_cg(struct mtk_base_afe *afe, unsigned int cg_type)unsigned int reg =get_top_cg_reg (cg_type);unsigned int mask =get_top_cg_mask (cg_type);unsigned int val =get_top_cg_off_val (cg_type); -unsigned long flags; -spin_lock_irqsave (&afe_priv->afe_ctrl_lock, flags); +guard (spinlock_irqsave)(&afe_priv->afe_ctrl_lock); afe_priv->top_cg_ref_cnt[cg_type]--;if (afe_priv->top_cg_ref_cnt[cg_type] ==0 )
@@ -223,8 +219,6 @@ int mt8365_afe_disable_top_cg(struct mtk_base_afe *afe, unsigned int cg_type)else if (afe_priv->top_cg_ref_cnt[cg_type] <0 ) afe_priv->top_cg_ref_cnt[cg_type] =0 ; -spin_unlock_irqrestore (&afe_priv->afe_ctrl_lock, flags); -return 0 ; }
@@ -263,25 +257,21 @@ int mt8365_afe_emi_clk_off(struct mtk_base_afe *afe)int mt8365_afe_enable_afe_on (struct mtk_base_afe *afe) {struct mt8365_afe_private *afe_priv = afe->platform_priv; -unsigned long flags; -spin_lock_irqsave (&afe_priv->afe_ctrl_lock, flags); +guard (spinlock_irqsave)(&afe_priv->afe_ctrl_lock); afe_priv->afe_on_ref_cnt++;if (afe_priv->afe_on_ref_cnt ==1 )regmap_update_bits (afe->regmap,AFE_DAC_CON0 ,0x1 ,0x1 ); -spin_unlock_irqrestore (&afe_priv->afe_ctrl_lock, flags); -return 0 ; }int mt8365_afe_disable_afe_on (struct mtk_base_afe *afe) {struct mt8365_afe_private *afe_priv = afe->platform_priv; -unsigned long flags; -spin_lock_irqsave (&afe_priv->afe_ctrl_lock, flags); +guard (spinlock_irqsave)(&afe_priv->afe_ctrl_lock); afe_priv->afe_on_ref_cnt--;if (afe_priv->afe_on_ref_cnt ==0 )
@@ -289,8 +279,6 @@ int mt8365_afe_disable_afe_on(struct mtk_base_afe *afe)else if (afe_priv->afe_on_ref_cnt <0 ) afe_priv->afe_on_ref_cnt =0 ; -spin_unlock_irqrestore (&afe_priv->afe_ctrl_lock, flags); -return 0 ; }
@@ -322,13 +310,11 @@ int mt8365_afe_enable_apll_tuner_cfg(struct mtk_base_afe *afe, unsigned int apll {struct mt8365_afe_private *afe_priv = afe->platform_priv; -mutex_lock (&afe_priv->afe_clk_mutex); +guard (mutex)(&afe_priv->afe_clk_mutex); afe_priv->apll_tuner_ref_cnt[apll]++; -if (afe_priv->apll_tuner_ref_cnt[apll] !=1 ) { -mutex_unlock (&afe_priv->afe_clk_mutex); +if (afe_priv->apll_tuner_ref_cnt[apll] !=1 )return 0 ; - }if (apll ==MT8365_AFE_APLL1 ) { regmap_update_bits(afe->regmap, AFE_APLL_TUNER_CFG,
@@ -342,7 +328,6 @@ int mt8365_afe_enable_apll_tuner_cfg(struct mtk_base_afe *afe, unsigned int apll AFE_APLL_TUNER_CFG1_EN_MASK, 0x1); } -mutex_unlock (&afe_priv->afe_clk_mutex);return 0 ; }
@@ -350,7 +335,7 @@ int mt8365_afe_disable_apll_tuner_cfg(struct mtk_base_afe *afe, unsigned int apl {struct mt8365_afe_private *afe_priv = afe->platform_priv; -mutex_lock (&afe_priv->afe_clk_mutex); +guard (mutex)(&afe_priv->afe_clk_mutex); afe_priv->apll_tuner_ref_cnt[apll]--;if (afe_priv->apll_tuner_ref_cnt[apll] ==0 ) {
@@ -365,7 +350,6 @@ int mt8365_afe_disable_apll_tuner_cfg(struct mtk_base_afe *afe, unsigned int apl afe_priv->apll_tuner_ref_cnt[apll] =0 ; } -mutex_unlock (&afe_priv->afe_clk_mutex);return 0 ; }
Signature · 1 line
2.43.0
PATCH 9/10 ASoC: mediatek: mt8195: mt8365-dai-adda: Use guard() for spin locks
In reply to [email protected]From: bui duc phuc <[email protected]>
Clean up the code using guard() for spin locks.
Merely code refactoring, and no behavior change.
--- sound/soc/mediatek/mt8365/mt8365-dai-adda.c | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-)
sound/soc/mediatek/mt8365/mt8365-dai-adda.c +2 -8
@@ -63,10 +63,9 @@ static int mt8365_dai_set_adda_in(struct mtk_base_afe *afe, unsigned int rate)int mt8365_dai_enable_adda_on (struct mtk_base_afe *afe) { -unsigned long flags;struct mt8365_afe_private *afe_priv = afe->platform_priv; -spin_lock_irqsave (&afe_priv->afe_ctrl_lock, flags); +guard (spinlock_irqsave)(&afe_priv->afe_ctrl_lock); adda_afe_on_ref_cnt++;if (adda_afe_on_ref_cnt ==1 )
@@ -74,17 +73,14 @@ int mt8365_dai_enable_adda_on(struct mtk_base_afe *afe)AFE_ADDA_UL_DL_ADDA_AFE_ON , AFE_ADDA_UL_DL_ADDA_AFE_ON); -spin_unlock_irqrestore (&afe_priv->afe_ctrl_lock, flags); -return 0 ; }int mt8365_dai_disable_adda_on (struct mtk_base_afe *afe) { -unsigned long flags;struct mt8365_afe_private *afe_priv = afe->platform_priv; -spin_lock_irqsave (&afe_priv->afe_ctrl_lock, flags); +guard (spinlock_irqsave)(&afe_priv->afe_ctrl_lock); adda_afe_on_ref_cnt--;if (adda_afe_on_ref_cnt ==0 )
@@ -96,8 +92,6 @@ int mt8365_dai_disable_adda_on(struct mtk_base_afe *afe)dev_warn (afe->dev,"Abnormal adda_on ref count. Force it to 0\n" ); } -spin_unlock_irqrestore (&afe_priv->afe_ctrl_lock, flags); -return 0 ; }
Signature · 1 line
2.43.0
PATCH 10/10 ASoC: mediatek: mt8195: mt8365-dai-i2s: Use guard() for spin locks
In reply to [email protected]From: bui duc phuc <[email protected]>
Clean up the code using guard() for spin locks.
Merely code refactoring, and no behavior change.
--- sound/soc/mediatek/mt8365/mt8365-dai-i2s.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-)
sound/soc/mediatek/mt8365/mt8365-dai-i2s.c +1 -4
@@ -463,7 +463,6 @@ static int mt8365_afe_set_2nd_i2s_asrc_enable(struct mtk_base_afe *afe,void mt8365_afe_set_i2s_out_enable (struct mtk_base_afe *afe,bool enable) {int i; -unsigned long flags;struct mt8365_afe_private *afe_priv = afe->platform_priv;struct mtk_afe_i2s_priv *i2s_data =NULL ;
@@ -475,7 +474,7 @@ void mt8365_afe_set_i2s_out_enable(struct mtk_base_afe *afe, bool enable)if (!i2s_data)return ; -spin_lock_irqsave (&afe_priv->afe_ctrl_lock, flags); +guard (spinlock_irqsave)(&afe_priv->afe_ctrl_lock);if (enable) { i2s_data->i2s_out_on_ref_cnt++;
@@ -490,8 +489,6 @@ void mt8365_afe_set_i2s_out_enable(struct mtk_base_afe *afe, bool enable)else if (i2s_data->i2s_out_on_ref_cnt <0 ) i2s_data->i2s_out_on_ref_cnt =0 ; } - -spin_unlock_irqrestore (&afe_priv->afe_ctrl_lock, flags); } static void mt8365_dai_set_enable(struct mtk_base_afe *afe,
Signature · 1 line
2.43.0
Mark Brown
maintainerQuoted 10 lines · On Wed, 10 Jun 2026 17:20:11 +0700, [email protected] wrote:
ASoC: mediatek: Use
guard()for mutex & spin locksFrom: bui duc phuc <[email protected]>
Hi all,
This series converts mutex and spinlock handling in Mediatek ASoC drivers to use
guard()helpers.[...]
Applied to
https://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git for-7.2
Thanks!
[01/10] ASoC: mediatek: common: mtk-afe-fe-dai: Use guard() for mutex locks
https://git.kernel.org/broonie/sound/c/9475859429e4 [02/10] ASoC: mediatek: common: mtk-btcvsd: Use guard() for spin locks https://git.kernel.org/broonie/sound/c/c69724b714c5 [03/10] ASoC: mediatek: mt8186: mt8186-afe-gpio: Use guard() for mutex locks https://git.kernel.org/broonie/sound/c/1e9f4587c873 [04/10] ASoC: mediatek: mt8188: mt8188-afe-clk: Use guard() for spin locks https://git.kernel.org/broonie/sound/c/cc29c31e87fc [05/10] ASoC: mediatek: mt8192: mt8192-afe-gpio: Use guard() for mutex locks https://git.kernel.org/broonie/sound/c/14edf39daefb [06/10] ASoC: mediatek: mt8195: mt8195-afe-clk: Use guard() for spin locks https://git.kernel.org/broonie/sound/c/a9f8d09ab109 [07/10] ASoC: mediatek: mt8195: mt8195-dai-etdm: Use guard() for spin locks https://git.kernel.org/broonie/sound/c/a57e39c7ff03 [08/10] ASoC: mediatek: mt8195: mt8365-afe-clk: Use guard() for mutex & spin locks https://git.kernel.org/broonie/sound/c/befae7299ab4 [09/10] ASoC: mediatek: mt8195: mt8365-dai-adda: Use guard() for spin locks https://git.kernel.org/broonie/sound/c/754c2fbf8bbc [10/10] ASoC: mediatek: mt8195: mt8365-dai-i2s: Use guard() for spin locks https://git.kernel.org/broonie/sound/c/62bde3771c3b
All being well this means that it will be integrated into the linux-next tree (usually sometime in the next 24 hours) and sent to Linus during the next merge window (or sooner if it is a bug fix), however if problems are discovered then the patch may be dropped or reverted.
You may get further e-mails resulting from automated or manual testing and review of the tree, please engage with people reporting problems and send followup patches addressing any issues that are reported if needed.
If any updates are required or you are submitting further changes they should be sent as incremental updates against current git, existing patches will not be replaced.
Please add any relevant lists and maintainers to the CCs when replying to this mail.
Thanks,
Mark