Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753080AbdLHV2m (ORCPT ); Fri, 8 Dec 2017 16:28:42 -0500 Received: from mail.free-electrons.com ([62.4.15.54]:51597 "EHLO mail.free-electrons.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751945AbdLHV2f (ORCPT ); Fri, 8 Dec 2017 16:28:35 -0500 Date: Fri, 8 Dec 2017 22:28:23 +0100 From: Boris Brezillon To: Christophe JAILLET Cc: kyungmin.park@samsung.com, dwmw2@infradead.org, computersforpeace@gmail.com, marek.vasut@gmail.com, richard@nod.at, cyrille.pitchen@wedev4u.fr, linux-mtd@lists.infradead.org, linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org Subject: Re: [PATCH 1/2] mtd: onenand: samsung: use devm_ function to simplify code and fix some leaks Message-ID: <20171208222823.068191f6@bbrezillon> In-Reply-To: <6cde66a56d0228d3933cf0d92fdc725ccb880b4a.1512765898.git.christophe.jaillet@wanadoo.fr> References: <6cde66a56d0228d3933cf0d92fdc725ccb880b4a.1512765898.git.christophe.jaillet@wanadoo.fr> X-Mailer: Claws Mail 3.14.1 (GTK+ 2.24.31; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2333 Lines: 69 On Fri, 8 Dec 2017 22:11:04 +0100 Christophe JAILLET wrote: > Convert all error handling code in 's3c_onenand_probe()' to > resource-managed alternatives in order to simplify code. > > This fixes a resource leak if 'platform_get_resource()' fails at line 872. > > The 'request_irq()' at line 971 was also un-balanced. It is now > resource-managed > > Signed-off-by: Christophe JAILLET > --- > Compile tested-only > --- > drivers/mtd/onenand/samsung.c | 141 +++++++++++++----------------------------- > 1 file changed, 43 insertions(+), 98 deletions(-) > > diff --git a/drivers/mtd/onenand/samsung.c b/drivers/mtd/onenand/samsung.c > index af0ac1a7bf8f..04039b967d59 100644 > --- a/drivers/mtd/onenand/samsung.c > +++ b/drivers/mtd/onenand/samsung.c > @@ -851,15 +851,14 @@ static int s3c_onenand_probe(struct platform_device *pdev) > /* No need to check pdata. the platform data is optional */ > > size = sizeof(struct mtd_info) + sizeof(struct onenand_chip); > - mtd = kzalloc(size, GFP_KERNEL); > + mtd = devm_kzalloc(&pdev->dev, size, GFP_KERNEL); > if (!mtd) > return -ENOMEM; > > - onenand = kzalloc(sizeof(struct s3c_onenand), GFP_KERNEL); > - if (!onenand) { > - err = -ENOMEM; > - goto onenand_fail; > - } > + onenand = devm_kzalloc(&pdev->dev, sizeof(struct s3c_onenand), > + GFP_KERNEL); > + if (!onenand) > + return -ENOMEM; > > this = (struct onenand_chip *) &mtd[1]; > mtd->priv = this; > @@ -873,22 +872,20 @@ static int s3c_onenand_probe(struct platform_device *pdev) > if (!r) { > dev_err(&pdev->dev, "no memory resource defined\n"); > return -ENOENT; > - goto ahb_resource_failed; > } > > - onenand->base_res = request_mem_region(r->start, resource_size(r), > - pdev->name); > + onenand->base_res = devm_request_mem_region(&pdev->dev, r->start, > + resource_size(r), > + pdev->name); Oh, and you should also get rid of all the onenand->xxx_res fields, they're no longer needed after switching to devm_ helpers. Just move the 'onenand->phys_base = r->start' assignment here and you should be good. > if (!onenand->base_res) { > dev_err(&pdev->dev, "failed to request memory resource\n"); > - err = -EBUSY; > - goto resource_failed; > + return -EBUSY; > } >