From 06d5ffb0f1c9a3800e4d1612b713d65a4d6e94a7 Mon Sep 17 00:00:00 2001 From: Mayank Rana Date: Mon, 7 Dec 2020 13:46:13 -0800 Subject: [PATCH] sound: usb: Unmap secondary event ring before freeing USB secondary event ring is being freed before it is being unmap. Fix this by calling xhci_sec_event_ring_cleanup() after unmapping. Also move secondary event ring cleanup and unmap related duplicate code into one API. Change-Id: I420f53d9e3ad6aa7b310dc354c7d35ce139afbe9 Signed-off-by: Mayank Rana --- sound/usb/usb_audio_qmi_svc.c | 36 ++++++++++++++--------------------- 1 file changed, 14 insertions(+), 22 deletions(-) diff --git a/sound/usb/usb_audio_qmi_svc.c b/sound/usb/usb_audio_qmi_svc.c index b7ff300b9f96..d72c2e650c8d 100644 --- a/sound/usb/usb_audio_qmi_svc.c +++ b/sound/usb/usb_audio_qmi_svc.c @@ -856,6 +856,18 @@ static void uaudio_dev_intf_cleanup(struct usb_device *udev, info->in_use = false; } +static void uaudio_event_ring_cleanup_free(struct uaudio_dev *dev) +{ + clear_bit(dev->card_num, &uaudio_qdev->card_slot); + /* all audio devices are disconnected */ + if (!uaudio_qdev->card_slot) { + uaudio_iommu_unmap(MEM_EVENT_RING, IOVA_BASE, PAGE_SIZE, + PAGE_SIZE); + xhci_sec_event_ring_cleanup(dev->udev, uaudio_qdev->intr_num); + uaudio_dbg("all audio devices disconnected\n"); + } +} + static void uaudio_dev_cleanup(struct uaudio_dev *dev) { int if_idx; @@ -879,17 +891,7 @@ static void uaudio_dev_cleanup(struct uaudio_dev *dev) /* free interface info */ kfree(dev->info); dev->info = NULL; - - clear_bit(dev->card_num, &uaudio_qdev->card_slot); - - /* all audio devices are disconnected */ - if (!uaudio_qdev->card_slot) { - uaudio_iommu_unmap(MEM_EVENT_RING, IOVA_BASE, PAGE_SIZE, - PAGE_SIZE); - xhci_sec_event_ring_cleanup(dev->udev, uaudio_qdev->intr_num); - uaudio_dbg("all audio devices disconnected\n"); - } - + uaudio_event_ring_cleanup_free(dev); dev->udev = NULL; } @@ -961,17 +963,7 @@ static void uaudio_dev_release(struct kref *kref) uaudio_dbg("for dev %pK\n", dev); atomic_set(&dev->in_use, 0); - - clear_bit(dev->card_num, &uaudio_qdev->card_slot); - - /* all audio devices are disconnected */ - if (!uaudio_qdev->card_slot) { - xhci_sec_event_ring_cleanup(dev->udev, uaudio_qdev->intr_num); - uaudio_iommu_unmap(MEM_EVENT_RING, IOVA_BASE, PAGE_SIZE, - PAGE_SIZE); - uaudio_dbg("all audio devices disconnected\n"); - } - + uaudio_event_ring_cleanup_free(dev); wake_up(&dev->disconnect_wq); }