mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2026-09-10 18:11:43 -04:00
ALSA: caiaq: Fix potential double-free at error path
The fix for caiaq driver's resource management to handle the errors
tries to release the resources in a common destructor call, but as a
sashiko review for another patch suggested, some of the audio
resources such as URBs have been already freed, and this may lead to a
double-free.
For addressing the double-free, call the common destructor function
from each place, and assure that the resource pointers get cleared.
Link: https://sashiko.dev/#/patchset/20260903084747.535367-1-eadavis%40sina.com
Fixes: 28abd224db ("ALSA: caiaq: Handle probe errors properly")
Link: https://patch.msgid.link/20260903103855.1807838-1-tiwai@suse.de
Signed-off-by: Takashi Iwai <tiwai@suse.de>
This commit is contained in:
@@ -828,16 +828,13 @@ int snd_usb_caiaq_audio_init(struct snd_usb_caiaqdev *cdev)
|
||||
|
||||
cdev->data_urbs_in = alloc_urbs(cdev, SNDRV_PCM_STREAM_CAPTURE, &ret);
|
||||
if (ret < 0) {
|
||||
kfree(cdev->data_cb_info);
|
||||
free_urbs(cdev->data_urbs_in);
|
||||
snd_usb_caiaq_audio_free(cdev);
|
||||
return ret;
|
||||
}
|
||||
|
||||
cdev->data_urbs_out = alloc_urbs(cdev, SNDRV_PCM_STREAM_PLAYBACK, &ret);
|
||||
if (ret < 0) {
|
||||
kfree(cdev->data_cb_info);
|
||||
free_urbs(cdev->data_urbs_in);
|
||||
free_urbs(cdev->data_urbs_out);
|
||||
snd_usb_caiaq_audio_free(cdev);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -858,6 +855,9 @@ void snd_usb_caiaq_audio_free(struct snd_usb_caiaqdev *cdev)
|
||||
|
||||
dev_dbg(dev, "%s(%p)\n", __func__, cdev);
|
||||
free_urbs(cdev->data_urbs_in);
|
||||
cdev->data_urbs_in = NULL;
|
||||
free_urbs(cdev->data_urbs_out);
|
||||
cdev->data_urbs_out = NULL;
|
||||
kfree(cdev->data_cb_info);
|
||||
cdev->data_cb_info = NULL;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user