ALSA: compress: register the open file with the card

The compress-offload device is the only ALSA character device family
which does not add its open files to the card's file list. Without it
the core cannot replace the file operations on disconnect, so syscalls
issued after the card is gone still reach the driver, and a card freed
with snd_card_free_when_closed() does not wait for the open compress
streams.

Call snd_card_file_add() at open and snd_card_file_remove() at release,
following the ordering used by the PCM, control, rawmidi and hwdep
devices.

Suggested-by: Takashi Iwai <tiwai@suse.de>
Signed-off-by: Peter Ujfalusi <peter.ujfalusi@linux.intel.com>
Reviewed-by: Takashi Iwai <tiwai@suse.de>
Link: https://patch.msgid.link/20261007084955.1256-3-peter.ujfalusi@linux.intel.com
Signed-off-by: Mark Brown <broonie@kernel.org>
This commit is contained in:
Peter Ujfalusi 2026-10-07 11:49:29 +03:00 committed by Mark Brown
parent 59b7978580
commit fd7f98db9c

View File

@ -101,7 +101,14 @@ static int snd_compr_open(struct inode *inode, struct file *f)
return -ENODEV;
}
ret = snd_card_file_add(compr->card, f);
if (ret < 0) {
snd_card_unref(compr->card);
return ret;
}
if (!try_module_get(compr->card->module)) {
snd_card_file_remove(compr->card, f);
snd_card_unref(compr->card);
return -EFAULT;
}
@ -144,6 +151,7 @@ static int snd_compr_open(struct inode *inode, struct file *f)
kfree(runtime);
kfree(data);
module_put(compr->card->module);
snd_card_file_remove(compr->card, f);
}
snd_card_unref(compr->card);
return ret;
@ -153,6 +161,7 @@ static int snd_compr_free(struct inode *inode, struct file *f)
{
struct snd_compr_file *data = f->private_data;
struct snd_compr_runtime *runtime = data->stream.runtime;
struct snd_compr *compr = data->stream.device;
cancel_delayed_work_sync(&data->stream.error_work);
@ -174,6 +183,7 @@ static int snd_compr_free(struct inode *inode, struct file *f)
module_put(data->stream.device->card->module);
kfree(data->stream.runtime);
kfree(data);
snd_card_file_remove(compr->card, f);
return 0;
}