From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751827AbeB0R6C (ORCPT ); Tue, 27 Feb 2018 12:58:02 -0500 Received: from foss.arm.com ([217.140.101.70]:39298 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750952AbeB0R6B (ORCPT ); Tue, 27 Feb 2018 12:58:01 -0500 Date: Tue, 27 Feb 2018 17:57:56 +0000 From: Lorenzo Pieralisi To: Rolf Evers-Fischer Cc: kishon@ti.com, bhelgaas@google.com, linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org, andy.shevchenko@gmail.com, Rolf Evers-Fischer Subject: Re: [PATCH v3 2/2] pci: endpoint: Fix kernel panic after put_device() Message-ID: <20180227175756.GB12756@e107981-ln.cambridge.arm.com> References: <20180227100231.22561-1-embedded24@evers-fischer.de> <20180227100231.22561-3-embedded24@evers-fischer.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180227100231.22561-3-embedded24@evers-fischer.de> User-Agent: Mutt/1.5.24 (2015-08-30) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Feb 27, 2018 at 11:02:30AM +0100, Rolf Evers-Fischer wrote: > From: Rolf Evers-Fischer > > 'put_device()' calls the relase function 'pci_epf_dev_release()', > which already frees 'epf->name' and 'epf'. > > Therefore we must not free them again after 'put_device()'. > > Fixes: 5e8cb4033807 ("PCI: endpoint: Add EP core layer to enable EP controller and EP functions") > > Signed-off-by: Rolf Evers-Fischer > --- > drivers/pci/endpoint/pci-epf-core.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/drivers/pci/endpoint/pci-epf-core.c b/drivers/pci/endpoint/pci-epf-core.c > index 1f2506f32bb9..1878a6776519 100644 > --- a/drivers/pci/endpoint/pci-epf-core.c > +++ b/drivers/pci/endpoint/pci-epf-core.c > @@ -232,7 +232,7 @@ struct pci_epf *pci_epf_create(const char *name) > > put_dev: > put_device(dev); > - kfree(epf->name); > + return ERR_PTR(ret); Another thing you could do, which would get rid of these multiple return statements (yes there is another one) would consist in removing the goto labels completely and handle the errors at the respective call site and just return instead of jumping around. Thanks, Lorenzo