From: Boris Brezillon <boris.brezillon@free-electrons.com>
To: Arvind Yadav <arvind.yadav.cs@gmail.com>
Cc: richard@nod.at, dwmw2@infradead.org, computersforpeace@gmail.com,
marek.vasut@gmail.com, cyrille.pitchen@atmel.com,
linux-mtd@lists.infradead.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH V1] mtd : nand : denali :- No need of devm functions
Date: Thu, 29 Dec 2016 18:24:43 +0100 [thread overview]
Message-ID: <20161229182443.2bdb37a7@bbrezillon> (raw)
In-Reply-To: <1481123711-7205-1-git-send-email-arvind.yadav.cs@gmail.com>
On Wed, 7 Dec 2016 20:45:11 +0530
Arvind Yadav <arvind.yadav.cs@gmail.com> wrote:
> In function denali_init, the memory allocated for denali->buf.buf
> is live within the function only. After the allocation it is
> immediately freed with devm_kfree. There is no need to allocate
> memory for denali->buf.buf with devm function so replace
> devm_kzalloc with kzalloc and devm_kfree with kfree.
>
> Signed-off-by: Arvind Yadav <arvind.yadav.cs@gmail.com>
> ---
> drivers/mtd/nand/denali.c | 7 ++++---
> 1 file changed, 4 insertions(+), 3 deletions(-)
Not sure it's any better than the previous logic (see the diffstat). The
devm_kzalloc() approach has the benefit of simplifying the different
error paths.
>
> diff --git a/drivers/mtd/nand/denali.c b/drivers/mtd/nand/denali.c
> index 0476ae8..ce3c31f 100644
> --- a/drivers/mtd/nand/denali.c
> +++ b/drivers/mtd/nand/denali.c
> @@ -1476,8 +1476,7 @@ int denali_init(struct denali_nand_info *denali)
> }
>
> /* allocate a temporary buffer for nand_scan_ident() */
> - denali->buf.buf = devm_kzalloc(denali->dev, PAGE_SIZE,
> - GFP_DMA | GFP_KERNEL);
> + denali->buf.buf = kzalloc(PAGE_SIZE, GFP_DMA | GFP_KERNEL);
> if (!denali->buf.buf)
> return -ENOMEM;
>
> @@ -1492,6 +1491,7 @@ int denali_init(struct denali_nand_info *denali)
> if (request_irq(denali->irq, denali_isr, IRQF_SHARED,
> DENALI_NAND_NAME, denali)) {
> pr_err("Spectra: Unable to allocate IRQ\n");
> + kfree(denali->buf.buf);
> return -ENODEV;
> }
>
> @@ -1512,11 +1512,12 @@ int denali_init(struct denali_nand_info *denali)
> */
> if (nand_scan_ident(mtd, denali->max_banks, NULL)) {
> ret = -ENXIO;
> + kfree(denali->buf.buf);
> goto failed_req_irq;
> }
>
> /* allocate the right size buffer now */
> - devm_kfree(denali->dev, denali->buf.buf);
> + kfree(denali->buf.buf);
> denali->buf.buf = devm_kzalloc(denali->dev,
> mtd->writesize + mtd->oobsize,
> GFP_KERNEL);
next prev parent reply other threads:[~2016-12-29 17:24 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-12-07 15:15 [PATCH V1] mtd : nand : denali :- No need of devm functions Arvind Yadav
2016-12-29 17:24 ` Boris Brezillon [this message]
2017-01-02 7:56 ` Arvind Yadav
2017-01-02 8:51 ` 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=20161229182443.2bdb37a7@bbrezillon \
--to=boris.brezillon@free-electrons.com \
--cc=arvind.yadav.cs@gmail.com \
--cc=computersforpeace@gmail.com \
--cc=cyrille.pitchen@atmel.com \
--cc=dwmw2@infradead.org \
--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).