Skip to content

Commit be8cedb

Browse files
ujfalusibardliao
authored andcommitted
ASoC: SOF: Intel: Use guard()/scoped_guard() for mutex locks where it makes sense
Replace the manual mutex lock/unlock pairs with guard()/scoped_guard(). Only code refactoring, and no behavior change. Signed-off-by: Peter Ujfalusi <peter.ujfalusi@linux.intel.com>
1 parent 9c64a0a commit be8cedb

2 files changed

Lines changed: 20 additions & 31 deletions

File tree

sound/soc/sof/intel/hda-dai-ops.c

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ static int hda_ipc4_pre_trigger(struct snd_sof_dev *sdev, struct snd_soc_dai *cp
311311
if (pipe_widget->instance_id < 0)
312312
return 0;
313313

314-
mutex_lock(&ipc4_data->pipeline_state_mutex);
314+
guard(mutex)(&ipc4_data->pipeline_state_mutex);
315315

316316
switch (cmd) {
317317
case SNDRV_PCM_TRIGGER_START:
@@ -323,16 +323,16 @@ static int hda_ipc4_pre_trigger(struct snd_sof_dev *sdev, struct snd_soc_dai *cp
323323
ret = sof_ipc4_set_pipeline_state(sdev, pipe_widget->instance_id,
324324
SOF_IPC4_PIPE_PAUSED);
325325
if (ret < 0)
326-
goto out;
326+
return ret;
327327

328328
pipeline->state = SOF_IPC4_PIPE_PAUSED;
329+
329330
break;
330331
default:
331332
dev_err(sdev->dev, "unknown trigger command %d\n", cmd);
332333
ret = -EINVAL;
333334
}
334-
out:
335-
mutex_unlock(&ipc4_data->pipeline_state_mutex);
335+
336336
return ret;
337337
}
338338

@@ -388,30 +388,33 @@ static int hda_ipc4_post_trigger(struct snd_sof_dev *sdev, struct snd_soc_dai *c
388388
if (pipe_widget->instance_id < 0)
389389
return 0;
390390

391-
mutex_lock(&ipc4_data->pipeline_state_mutex);
391+
guard(mutex)(&ipc4_data->pipeline_state_mutex);
392392

393393
switch (cmd) {
394394
case SNDRV_PCM_TRIGGER_START:
395395
if (pipeline->state != SOF_IPC4_PIPE_PAUSED) {
396396
ret = sof_ipc4_set_pipeline_state(sdev, pipe_widget->instance_id,
397397
SOF_IPC4_PIPE_PAUSED);
398398
if (ret < 0)
399-
goto out;
399+
return ret;
400+
400401
pipeline->state = SOF_IPC4_PIPE_PAUSED;
401402
}
402403

403404
ret = sof_ipc4_set_pipeline_state(sdev, pipe_widget->instance_id,
404405
SOF_IPC4_PIPE_RUNNING);
405406
if (ret < 0)
406-
goto out;
407+
return ret;
408+
407409
pipeline->state = SOF_IPC4_PIPE_RUNNING;
408410
swidget->spipe->started_count++;
409411
break;
410412
case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
411413
ret = sof_ipc4_set_pipeline_state(sdev, pipe_widget->instance_id,
412414
SOF_IPC4_PIPE_RUNNING);
413415
if (ret < 0)
414-
goto out;
416+
return ret;
417+
415418
pipeline->state = SOF_IPC4_PIPE_RUNNING;
416419
break;
417420
case SNDRV_PCM_TRIGGER_SUSPEND:
@@ -429,8 +432,7 @@ static int hda_ipc4_post_trigger(struct snd_sof_dev *sdev, struct snd_soc_dai *c
429432
ret = -EINVAL;
430433
break;
431434
}
432-
out:
433-
mutex_unlock(&ipc4_data->pipeline_state_mutex);
435+
434436
return ret;
435437
}
436438

sound/soc/sof/intel/hda-mlink.c

Lines changed: 8 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -524,11 +524,8 @@ void hdac_bus_eml_enable_interrupt(struct hdac_bus *bus, bool alt, int elid, boo
524524

525525
hlink = &h2link->hext_link;
526526

527-
mutex_lock(&h2link->eml_lock);
528-
529-
hdaml_link_enable_interrupt(hlink->ml_addr + AZX_REG_ML_LCTL, enable);
530-
531-
mutex_unlock(&h2link->eml_lock);
527+
scoped_guard(mutex, &h2link->eml_lock)
528+
hdaml_link_enable_interrupt(hlink->ml_addr + AZX_REG_ML_LCTL, enable);
532529
}
533530
EXPORT_SYMBOL_NS(hdac_bus_eml_enable_interrupt, "SND_SOC_SOF_HDA_MLINK");
534531

@@ -837,11 +834,8 @@ int hdac_bus_eml_sdw_set_lsdiid(struct hdac_bus *bus, int sublink, int dev_num)
837834

838835
hlink = &h2link->hext_link;
839836

840-
mutex_lock(&h2link->eml_lock);
841-
842-
hdaml_link_set_lsdiid(hlink->ml_addr + AZX_REG_ML_LSDIID_OFFSET(sublink), dev_num);
843-
844-
mutex_unlock(&h2link->eml_lock);
837+
scoped_guard(mutex, &h2link->eml_lock)
838+
hdaml_link_set_lsdiid(hlink->ml_addr + AZX_REG_ML_LSDIID_OFFSET(sublink), dev_num);
845839

846840
return 0;
847841
} EXPORT_SYMBOL_NS(hdac_bus_eml_sdw_set_lsdiid, "SND_SOC_SOF_HDA_MLINK");
@@ -875,12 +869,8 @@ int hdac_bus_eml_sdw_map_stream_ch(struct hdac_bus *bus, int sublink, int y,
875869
lchan = 0;
876870
}
877871

878-
mutex_lock(&h2link->eml_lock);
879-
880-
hdaml_shim_map_stream_ch(pcmsycm, lchan, hchan,
881-
stream_id, dir);
882-
883-
mutex_unlock(&h2link->eml_lock);
872+
scoped_guard(mutex, &h2link->eml_lock)
873+
hdaml_shim_map_stream_ch(pcmsycm, lchan, hchan, stream_id, dir);
884874

885875
val = readw(pcmsycm);
886876

@@ -1012,11 +1002,8 @@ int hdac_bus_eml_enable_offload(struct hdac_bus *bus, bool alt, int elid, bool e
10121002

10131003
hlink = &h2link->hext_link;
10141004

1015-
mutex_lock(&h2link->eml_lock);
1016-
1017-
hdaml_lctl_offload_enable(hlink->ml_addr + AZX_REG_ML_LCTL, enable);
1018-
1019-
mutex_unlock(&h2link->eml_lock);
1005+
scoped_guard(mutex, &h2link->eml_lock)
1006+
hdaml_lctl_offload_enable(hlink->ml_addr + AZX_REG_ML_LCTL, enable);
10201007

10211008
return 0;
10221009
}

0 commit comments

Comments
 (0)