]> www.infradead.org Git - users/dwmw2/linux.git/commitdiff
staging: bcm2835-audio: Don't leak workqueue if open fails
authorTuomas Tynkkynen <tuomas@tuxera.com>
Thu, 12 Jul 2018 21:54:17 +0000 (00:54 +0300)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 26 Sep 2018 06:39:40 +0000 (08:39 +0200)
[ Upstream commit 678c5b119307c40f9a17152512f9c949d0ec7292 ]

Currently, if bcm2835_audio_open() fails partway, the allocated
workqueue is leaked. Avoid that.

While at it, propagate the return value of
bcm2835_audio_open_connection() on failure instead of returning -1.

Signed-off-by: Tuomas Tynkkynen <tuomas@tuxera.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Sasha Levin <alexander.levin@microsoft.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/staging/vc04_services/bcm2835-audio/bcm2835-vchiq.c

index f0cefa1b7b0f5b53caa747b50ea072acbfc463ac..b20d34449ed49da76e390246ac158e54958093c1 100644 (file)
@@ -439,16 +439,16 @@ int bcm2835_audio_open(struct bcm2835_alsa_stream *alsa_stream)
        my_workqueue_init(alsa_stream);
 
        ret = bcm2835_audio_open_connection(alsa_stream);
-       if (ret) {
-               ret = -1;
-               goto exit;
-       }
+       if (ret)
+               goto free_wq;
+
        instance = alsa_stream->instance;
        LOG_DBG(" instance (%p)\n", instance);
 
        if (mutex_lock_interruptible(&instance->vchi_mutex)) {
                LOG_DBG("Interrupted whilst waiting for lock on (%d)\n", instance->num_connections);
-               return -EINTR;
+               ret = -EINTR;
+               goto free_wq;
        }
        vchi_service_use(instance->vchi_handle[0]);
 
@@ -471,7 +471,11 @@ int bcm2835_audio_open(struct bcm2835_alsa_stream *alsa_stream)
 unlock:
        vchi_service_release(instance->vchi_handle[0]);
        mutex_unlock(&instance->vchi_mutex);
-exit:
+
+free_wq:
+       if (ret)
+               destroy_workqueue(alsa_stream->my_wq);
+
        return ret;
 }