From: Boris Brezillon <boris.brezillon@free-electrons.com>
To: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
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
Date: Fri, 8 Dec 2017 22:22:38 +0100 [thread overview]
Message-ID: <20171208222238.4b778805@bbrezillon> (raw)
In-Reply-To: <6cde66a56d0228d3933cf0d92fdc725ccb880b4a.1512765898.git.christophe.jaillet@wanadoo.fr>
On Fri, 8 Dec 2017 22:11:04 +0100
Christophe JAILLET <christophe.jaillet@wanadoo.fr> 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 <christophe.jaillet@wanadoo.fr>
> ---
> 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);
> if (!onenand->base_res) {
> dev_err(&pdev->dev, "failed to request memory resource\n");
> - err = -EBUSY;
> - goto resource_failed;
> + return -EBUSY;
> }
>
> - onenand->base = ioremap(r->start, resource_size(r));
> + onenand->base = devm_ioremap(&pdev->dev, r->start, resource_size(r));
> if (!onenand->base) {
> dev_err(&pdev->dev, "failed to map memory resource\n");
> - err = -EFAULT;
> - goto ioremap_failed;
> + return -EFAULT;
> }
Can still be simplified with the following pattern:
r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
onenand->base = devm_ioremap_resource(&pdev->dev, r);
if (IS_ERR(onenand->base))
return PTR_ERR(onenand->base);
No need to keep the error messages, since devm_ioremap_resource()
already takes care of that.
next prev parent reply other threads:[~2017-12-08 21:22 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-12-08 21:11 [PATCH 0/2] mtd: onenand: samsung: Simplify code and fix leaks in error handling paths Christophe JAILLET
2017-12-08 21:11 ` [PATCH 1/2] mtd: onenand: samsung: use devm_ function to simplify code and fix some leaks Christophe JAILLET
2017-12-08 21:22 ` Boris Brezillon [this message]
2017-12-08 21:28 ` Boris Brezillon
2017-12-08 21:11 ` [PATCH 2/2] mtd: onenand: samsung: return an error if 'mtd_device_parse_register()' fails Christophe JAILLET
2017-12-08 21:24 ` Boris Brezillon
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20171208222238.4b778805@bbrezillon \
--to=boris.brezillon@free-electrons.com \
--cc=christophe.jaillet@wanadoo.fr \
--cc=computersforpeace@gmail.com \
--cc=cyrille.pitchen@wedev4u.fr \
--cc=dwmw2@infradead.org \
--cc=kernel-janitors@vger.kernel.org \
--cc=kyungmin.park@samsung.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mtd@lists.infradead.org \
--cc=marek.vasut@gmail.com \
--cc=richard@nod.at \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).