Skip to content

Commit

Permalink
Revert "ALSA: control: Take power_ref lock primarily"
Browse files Browse the repository at this point in the history
The patch will cause system hang when removing some audio modules.

This reverts commit fcc62b1.

Signed-off-by: Bard Liao <yung-chuan.liao@linux.intel.com>
  • Loading branch information
bardliao committed Aug 1, 2024
1 parent a77cb98 commit 57eb1d6
Showing 1 changed file with 20 additions and 34 deletions.
54 changes: 20 additions & 34 deletions sound/core/control.c
Original file line number Diff line number Diff line change
Expand Up @@ -1167,7 +1167,9 @@ static int __snd_ctl_elem_info(struct snd_card *card,
#ifdef CONFIG_SND_DEBUG
info->access = 0;
#endif
result = kctl->info(kctl, info);
result = snd_power_ref_and_wait(card);
if (!result)
result = kctl->info(kctl, info);
snd_power_unref(card);
if (result >= 0) {
snd_BUG_ON(info->access);
Expand Down Expand Up @@ -1206,17 +1208,12 @@ static int snd_ctl_elem_info(struct snd_ctl_file *ctl,
static int snd_ctl_elem_info_user(struct snd_ctl_file *ctl,
struct snd_ctl_elem_info __user *_info)
{
struct snd_card *card = ctl->card;
struct snd_ctl_elem_info info;
int result;

if (copy_from_user(&info, _info, sizeof(info)))
return -EFAULT;
result = snd_power_ref_and_wait(card);
if (result)
return result;
result = snd_ctl_elem_info(ctl, &info);
snd_power_unref(card);
if (result < 0)
return result;
/* drop internal access flags */
Expand Down Expand Up @@ -1260,7 +1257,10 @@ static int snd_ctl_elem_read(struct snd_card *card,

if (!snd_ctl_skip_validation(&info))
fill_remaining_elem_value(control, &info, pattern);
ret = kctl->get(kctl, control);
ret = snd_power_ref_and_wait(card);
if (!ret)
ret = kctl->get(kctl, control);
snd_power_unref(card);
if (ret < 0)
return ret;
if (!snd_ctl_skip_validation(&info) &&
Expand All @@ -1285,11 +1285,7 @@ static int snd_ctl_elem_read_user(struct snd_card *card,
if (IS_ERR(control))
return PTR_ERR(no_free_ptr(control));

result = snd_power_ref_and_wait(card);
if (result)
return result;
result = snd_ctl_elem_read(card, control);
snd_power_unref(card);
if (result < 0)
return result;

Expand All @@ -1304,7 +1300,7 @@ static int snd_ctl_elem_write(struct snd_card *card, struct snd_ctl_file *file,
struct snd_kcontrol *kctl;
struct snd_kcontrol_volatile *vd;
unsigned int index_offset;
int result = 0;
int result;

down_write(&card->controls_rwsem);
kctl = snd_ctl_find_id_locked(card, &control->id);
Expand All @@ -1322,8 +1318,9 @@ static int snd_ctl_elem_write(struct snd_card *card, struct snd_ctl_file *file,
}

snd_ctl_build_ioff(&control->id, kctl, index_offset);
result = snd_power_ref_and_wait(card);
/* validate input values */
if (IS_ENABLED(CONFIG_SND_CTL_INPUT_VALIDATION)) {
if (IS_ENABLED(CONFIG_SND_CTL_INPUT_VALIDATION) && !result) {
struct snd_ctl_elem_info info;

memset(&info, 0, sizeof(info));
Expand All @@ -1335,6 +1332,7 @@ static int snd_ctl_elem_write(struct snd_card *card, struct snd_ctl_file *file,
}
if (!result)
result = kctl->put(kctl, control);
snd_power_unref(card);
if (result < 0) {
up_write(&card->controls_rwsem);
return result;
Expand Down Expand Up @@ -1363,11 +1361,7 @@ static int snd_ctl_elem_write_user(struct snd_ctl_file *file,
return PTR_ERR(no_free_ptr(control));

card = file->card;
result = snd_power_ref_and_wait(card);
if (result < 0)
return result;
result = snd_ctl_elem_write(card, file, control);
snd_power_unref(card);
if (result < 0)
return result;

Expand Down Expand Up @@ -1836,7 +1830,7 @@ static int call_tlv_handler(struct snd_ctl_file *file, int op_flag,
{SNDRV_CTL_TLV_OP_CMD, SNDRV_CTL_ELEM_ACCESS_TLV_COMMAND},
};
struct snd_kcontrol_volatile *vd = &kctl->vd[snd_ctl_get_ioff(kctl, id)];
int i;
int i, ret;

/* Check support of the request for this element. */
for (i = 0; i < ARRAY_SIZE(pairs); ++i) {
Expand All @@ -1854,7 +1848,11 @@ static int call_tlv_handler(struct snd_ctl_file *file, int op_flag,
vd->owner != NULL && vd->owner != file)
return -EPERM;

return kctl->tlv.c(kctl, op_flag, size, buf);
ret = snd_power_ref_and_wait(file->card);
if (!ret)
ret = kctl->tlv.c(kctl, op_flag, size, buf);
snd_power_unref(file->card);
return ret;
}

static int read_tlv_buf(struct snd_kcontrol *kctl, struct snd_ctl_elem_id *id,
Expand Down Expand Up @@ -1967,28 +1965,16 @@ static long snd_ctl_ioctl(struct file *file, unsigned int cmd, unsigned long arg
case SNDRV_CTL_IOCTL_SUBSCRIBE_EVENTS:
return snd_ctl_subscribe_events(ctl, ip);
case SNDRV_CTL_IOCTL_TLV_READ:
err = snd_power_ref_and_wait(card);
if (err < 0)
return err;
scoped_guard(rwsem_read, &card->controls_rwsem)
scoped_guard(rwsem_read, &ctl->card->controls_rwsem)
err = snd_ctl_tlv_ioctl(ctl, argp, SNDRV_CTL_TLV_OP_READ);
snd_power_unref(card);
return err;
case SNDRV_CTL_IOCTL_TLV_WRITE:
err = snd_power_ref_and_wait(card);
if (err < 0)
return err;
scoped_guard(rwsem_write, &card->controls_rwsem)
scoped_guard(rwsem_write, &ctl->card->controls_rwsem)
err = snd_ctl_tlv_ioctl(ctl, argp, SNDRV_CTL_TLV_OP_WRITE);
snd_power_unref(card);
return err;
case SNDRV_CTL_IOCTL_TLV_COMMAND:
err = snd_power_ref_and_wait(card);
if (err < 0)
return err;
scoped_guard(rwsem_write, &card->controls_rwsem)
scoped_guard(rwsem_write, &ctl->card->controls_rwsem)
err = snd_ctl_tlv_ioctl(ctl, argp, SNDRV_CTL_TLV_OP_CMD);
snd_power_unref(card);
return err;
case SNDRV_CTL_IOCTL_POWER:
return -ENOPROTOOPT;
Expand Down

0 comments on commit 57eb1d6

Please sign in to comment.