staging: bcm2835-audio: Fix memory corruption
authorPhil Elwell <phil@raspberrypi.org>
Sun, 24 Sep 2017 14:20:49 +0000 (15:20 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 27 Oct 2017 08:39:08 +0000 (10:39 +0200)
commitaff794632bfec481281ce0b46cd2b54dff847ec1
tree0b6e4d0d71f7de57d610d0aaa0f1911411df9ee5
parent5b61412afb6674b51f83ee0de2df0a455643d5be
staging: bcm2835-audio: Fix memory corruption

commit c97d96b4e612c7dc1b37d7afc61b598a9a25994d upstream.

The previous commit (0adbfd46) fixed a memory leak but also freed a
block in the success case, causing a stale pointer to be used with
potentially fatal results. Only free the vchi_instance block in the
case that vchi_connect fails; once connected, the instance is
retained for subsequent connections.

Simplifying the code by removing a bunch of gotos and returning errors
directly.

Signed-off-by: Phil Elwell <phil@raspberrypi.org>
Fixes: 0adbfd4694c2 ("staging: bcm2835-audio: fix memory leak in bcm2835_audio_open_connection()")
Tested-by: Stefan Wahren <stefan.wahren@i2se.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/staging/vc04_services/bcm2835-audio/bcm2835-vchiq.c