Skip to content

Commit dc82e52

Browse files
committed
ALSA: core: Assure control device to be registered at last
The commit 289ca02 ("ALSA: Use priority list for managing device list") changed the way to register/disconnect/free devices via a single priority list. This helped to make behavior consistent, but it also changed a slight behavior change: namely, the control device is registered earlier than others, while it was supposed to be the very last one. I've put SNDRV_DEV_CONTROL in the current position as the release of ctl elements often conflict with the private ctl elements some PCM or other components may create, which often leads to a double-free. But, the order of register and disconnect should be indeed fixed as expected in the early days: the control device gets registered at last, and disconnected at first. This patch changes the priority list order to move SNDRV_DEV_CONTROL as the last guy to assure the register / disconnect order. Meanwhile, for keeping the messy resource release order, manually treat the control and lowlevel devices as last freed one. Additional note: The lowlevel device is the device where a card driver creates at probe. And, we still keep the release order control -> lowlevel, as there might be link from a control element back to a lowlevel object. Fixes: 289ca02 ("ALSA: Use priority list for managing device list") Reported-by: Tzung-Bi Shih <tzungbi@google.com> Tested-by: Tzung-Bi Shih <tzungbi@google.com> Signed-off-by: Takashi Iwai <tiwai@suse.de>
1 parent 377a879 commit dc82e52

2 files changed

Lines changed: 10 additions & 1 deletion

File tree

‎include/sound/core.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ struct completion;
5151
*/
5252
enum snd_device_type {
5353
SNDRV_DEV_LOWLEVEL,
54-
SNDRV_DEV_CONTROL,
5554
SNDRV_DEV_INFO,
5655
SNDRV_DEV_BUS,
5756
SNDRV_DEV_CODEC,
@@ -62,6 +61,7 @@ enum snd_device_type {
6261
SNDRV_DEV_SEQUENCER,
6362
SNDRV_DEV_HWDEP,
6463
SNDRV_DEV_JACK,
64+
SNDRV_DEV_CONTROL, /* NOTE: this must be the last one */
6565
};
6666

6767
enum snd_device_state {

‎sound/core/device.c‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,15 @@ void snd_device_free_all(struct snd_card *card)
240240

241241
if (snd_BUG_ON(!card))
242242
return;
243+
list_for_each_entry_safe_reverse(dev, next, &card->devices, list) {
244+
/* exception: free ctl and lowlevel stuff later */
245+
if (dev->type == SNDRV_DEV_CONTROL ||
246+
dev->type == SNDRV_DEV_LOWLEVEL)
247+
continue;
248+
__snd_device_free(dev);
249+
}
250+
251+
/* free all */
243252
list_for_each_entry_safe_reverse(dev, next, &card->devices, list)
244253
__snd_device_free(dev);
245254
}

0 commit comments

Comments
 (0)