Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752016AbdHJKZE (ORCPT ); Thu, 10 Aug 2017 06:25:04 -0400 Received: from userp1040.oracle.com ([156.151.31.81]:45291 "EHLO userp1040.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750841AbdHJKZC (ORCPT ); Thu, 10 Aug 2017 06:25:02 -0400 Date: Thu, 10 Aug 2017 13:21:55 +0300 From: Dan Carpenter To: Phil Elwell Cc: Eric Anholt , Stefan Wahren , Greg Kroah-Hartman , Florian Fainelli , Aishwarya Pant , linux-rpi-kernel@lists.infradead.org, devel@driverdev.osuosl.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] staging: bcm2835-audio: Fix memory corruption Message-ID: <20170810102155.6j373u3yktnlwsqw@mwanda> References: <1502193902-87160-1-git-send-email-phil@raspberrypi.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1502193902-87160-1-git-send-email-phil@raspberrypi.org> User-Agent: NeoMutt/20170113 (1.7.2) X-Source-IP: userv0021.oracle.com [156.151.31.71] Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1814 Lines: 42 The original patch did not go through the normal review process... On Tue, Aug 08, 2017 at 01:05:02PM +0100, Phil Elwell wrote: > I'm all for fixing memory leaks, but freeing a block while it is still > being used is a recipe for hard-to-debug kernel exceptions. > This bug completely breaks the driver doesn't it? It's not very subtle so it should be easy to diagnose with git bisect. > 1) There is already a vchi method for freeing the instance, so use it. > 2) Only call it on error, and then only before initted is false. > > Signed-off-by: Phil Elwell > Fixes: 0adbfd4694c2 ("staging: bcm2835-audio: fix memory leak in bcm2835_audio_open_connection()") > --- > drivers/staging/vc04_services/bcm2835-audio/bcm2835-vchiq.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/drivers/staging/vc04_services/bcm2835-audio/bcm2835-vchiq.c b/drivers/staging/vc04_services/bcm2835-audio/bcm2835-vchiq.c > index 5f3d8f2..89f96f3 100644 > --- a/drivers/staging/vc04_services/bcm2835-audio/bcm2835-vchiq.c > +++ b/drivers/staging/vc04_services/bcm2835-audio/bcm2835-vchiq.c > @@ -409,6 +409,7 @@ static int bcm2835_audio_open_connection(struct bcm2835_alsa_stream *alsa_stream > LOG_ERR("%s: failed to connect VCHI instance (ret=%d)\n", > __func__, ret); > > + vchi_disconnect(vchi_instance); This is ugly because why are we calling disconnect() if connect() fails? These functions should be symetric so disconnect only disconnects and we call a different function to undo vchi_initialise(). > ret = -EIO; > goto err_free_mem; This label name is out of date. There is a later error path where vc_vchi_audio_init() fails and we leak on that path. Also why is vchi_instance a static variable? Arglebargleblargleblah... regards, dan carpenter