ALSA: isight: fix isight_pcm_abort() crashes
Fix crashes in isight_pcm_abort() that happen when the driver tries to access isight->pcm->runtime which does not exist when the device is not open. Introduce a new field pcm_active to track this state. Signed-off-by: Clemens Ladisch <clemens@ladisch.de> Reported-by: Stefan Richter <stefanr@s5r6.in-berlin.de> Signed-off-by: Takashi Iwai <tiwai@suse.de>
This commit is contained in:
parent
3a691b28a0
commit
03c29680d4
1 changed files with 20 additions and 6 deletions
|
@ -56,6 +56,7 @@ struct isight {
|
||||||
struct iso_packets_buffer buffer;
|
struct iso_packets_buffer buffer;
|
||||||
struct fw_iso_resources resources;
|
struct fw_iso_resources resources;
|
||||||
struct fw_iso_context *context;
|
struct fw_iso_context *context;
|
||||||
|
bool pcm_active;
|
||||||
bool pcm_running;
|
bool pcm_running;
|
||||||
bool first_packet;
|
bool first_packet;
|
||||||
int packet_index;
|
int packet_index;
|
||||||
|
@ -131,10 +132,12 @@ static void isight_pcm_abort(struct isight *isight)
|
||||||
{
|
{
|
||||||
unsigned long flags;
|
unsigned long flags;
|
||||||
|
|
||||||
snd_pcm_stream_lock_irqsave(isight->pcm, flags);
|
if (ACCESS_ONCE(isight->pcm_active)) {
|
||||||
if (snd_pcm_running(isight->pcm))
|
snd_pcm_stream_lock_irqsave(isight->pcm, flags);
|
||||||
snd_pcm_stop(isight->pcm, SNDRV_PCM_STATE_XRUN);
|
if (snd_pcm_running(isight->pcm))
|
||||||
snd_pcm_stream_unlock_irqrestore(isight->pcm, flags);
|
snd_pcm_stop(isight->pcm, SNDRV_PCM_STATE_XRUN);
|
||||||
|
snd_pcm_stream_unlock_irqrestore(isight->pcm, flags);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void isight_dropped_samples(struct isight *isight, unsigned int total)
|
static void isight_dropped_samples(struct isight *isight, unsigned int total)
|
||||||
|
@ -295,8 +298,17 @@ static int isight_close(struct snd_pcm_substream *substream)
|
||||||
static int isight_hw_params(struct snd_pcm_substream *substream,
|
static int isight_hw_params(struct snd_pcm_substream *substream,
|
||||||
struct snd_pcm_hw_params *hw_params)
|
struct snd_pcm_hw_params *hw_params)
|
||||||
{
|
{
|
||||||
return snd_pcm_lib_alloc_vmalloc_buffer(substream,
|
struct isight *isight = substream->private_data;
|
||||||
params_buffer_bytes(hw_params));
|
int err;
|
||||||
|
|
||||||
|
err = snd_pcm_lib_alloc_vmalloc_buffer(substream,
|
||||||
|
params_buffer_bytes(hw_params));
|
||||||
|
if (err < 0)
|
||||||
|
return err;
|
||||||
|
|
||||||
|
ACCESS_ONCE(isight->pcm_active) = true;
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void isight_stop_streaming(struct isight *isight)
|
static void isight_stop_streaming(struct isight *isight)
|
||||||
|
@ -322,6 +334,8 @@ static int isight_hw_free(struct snd_pcm_substream *substream)
|
||||||
{
|
{
|
||||||
struct isight *isight = substream->private_data;
|
struct isight *isight = substream->private_data;
|
||||||
|
|
||||||
|
ACCESS_ONCE(isight->pcm_active) = false;
|
||||||
|
|
||||||
mutex_lock(&isight->mutex);
|
mutex_lock(&isight->mutex);
|
||||||
isight_stop_streaming(isight);
|
isight_stop_streaming(isight);
|
||||||
mutex_unlock(&isight->mutex);
|
mutex_unlock(&isight->mutex);
|
||||||
|
|
Loading…
Add table
Reference in a new issue