Skip to content

Commit 30d8340

Browse files
takaswietiwai
authored andcommitted
ALSA: control: obsolete user_ctl_lock
At a previous commit, concurrent requests for TLV data are maintained exclusively between read requests and write/command requests. TLV callback handlers in each driver has no risk from concurrent access for reference/change. In current implementation, 'struct snd_card' has a mutex to control concurrent accesses to user-defined element sets. This commit obsoletes it. Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp> Signed-off-by: Takashi Iwai <tiwai@suse.de>
1 parent 4c8099e commit 30d8340

3 files changed

Lines changed: 13 additions & 27 deletions

File tree

‎include/sound/core.h‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,6 @@ struct snd_card {
118118
int user_ctl_count; /* count of all user controls */
119119
struct list_head controls; /* all controls for this card */
120120
struct list_head ctl_files; /* active control files */
121-
struct mutex user_ctl_lock; /* protects user controls against
122-
concurrent access */
123121

124122
struct snd_info_entry *proc_root; /* root for soundcard specific files */
125123
struct snd_info_entry *proc_id; /* the card id */

‎sound/core/control.c‎

Lines changed: 13 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1095,9 +1095,7 @@ static int snd_ctl_elem_user_get(struct snd_kcontrol *kcontrol,
10951095
char *src = ue->elem_data +
10961096
snd_ctl_get_ioff(kcontrol, &ucontrol->id) * size;
10971097

1098-
mutex_lock(&ue->card->user_ctl_lock);
10991098
memcpy(&ucontrol->value, src, size);
1100-
mutex_unlock(&ue->card->user_ctl_lock);
11011099
return 0;
11021100
}
11031101

@@ -1110,11 +1108,9 @@ static int snd_ctl_elem_user_put(struct snd_kcontrol *kcontrol,
11101108
char *dst = ue->elem_data +
11111109
snd_ctl_get_ioff(kcontrol, &ucontrol->id) * size;
11121110

1113-
mutex_lock(&ue->card->user_ctl_lock);
11141111
change = memcmp(&ucontrol->value, dst, size) != 0;
11151112
if (change)
11161113
memcpy(dst, &ucontrol->value, size);
1117-
mutex_unlock(&ue->card->user_ctl_lock);
11181114
return change;
11191115
}
11201116

@@ -1124,44 +1120,37 @@ static int snd_ctl_elem_user_tlv(struct snd_kcontrol *kcontrol,
11241120
unsigned int __user *tlv)
11251121
{
11261122
struct user_element *ue = kcontrol->private_data;
1127-
int change = 0;
1128-
void *new_data;
11291123

11301124
if (op_flag == SNDRV_CTL_TLV_OP_WRITE) {
1125+
int change;
1126+
void *new_data;
1127+
11311128
if (size > 1024 * 128) /* sane value */
11321129
return -EINVAL;
11331130

11341131
new_data = memdup_user(tlv, size);
11351132
if (IS_ERR(new_data))
11361133
return PTR_ERR(new_data);
1137-
mutex_lock(&ue->card->user_ctl_lock);
11381134
change = ue->tlv_data_size != size;
11391135
if (!change)
11401136
change = memcmp(ue->tlv_data, new_data, size);
11411137
kfree(ue->tlv_data);
11421138
ue->tlv_data = new_data;
11431139
ue->tlv_data_size = size;
1144-
mutex_unlock(&ue->card->user_ctl_lock);
1140+
1141+
return change;
11451142
} else {
1146-
int ret = 0;
1143+
if (!ue->tlv_data_size || !ue->tlv_data)
1144+
return -ENXIO;
1145+
1146+
if (size < ue->tlv_data_size)
1147+
return -ENOSPC;
11471148

1148-
mutex_lock(&ue->card->user_ctl_lock);
1149-
if (!ue->tlv_data_size || !ue->tlv_data) {
1150-
ret = -ENXIO;
1151-
goto err_unlock;
1152-
}
1153-
if (size < ue->tlv_data_size) {
1154-
ret = -ENOSPC;
1155-
goto err_unlock;
1156-
}
11571149
if (copy_to_user(tlv, ue->tlv_data, ue->tlv_data_size))
1158-
ret = -EFAULT;
1159-
err_unlock:
1160-
mutex_unlock(&ue->card->user_ctl_lock);
1161-
if (ret)
1162-
return ret;
1150+
return -EFAULT;
1151+
1152+
return 0;
11631153
}
1164-
return change;
11651154
}
11661155

11671156
static int snd_ctl_elem_init_enum_names(struct user_element *ue)

‎sound/core/init.c‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,6 @@ int snd_card_new(struct device *parent, int idx, const char *xid,
248248
INIT_LIST_HEAD(&card->devices);
249249
init_rwsem(&card->controls_rwsem);
250250
rwlock_init(&card->ctl_files_rwlock);
251-
mutex_init(&card->user_ctl_lock);
252251
INIT_LIST_HEAD(&card->controls);
253252
INIT_LIST_HEAD(&card->ctl_files);
254253
spin_lock_init(&card->files_lock);

0 commit comments

Comments
 (0)