From: Marek Vasut <marex@denx.de>
To: yuhang wang <wangyuhang2014@gmail.com>
Cc: artem.bityutskiy@linux.intel.com, wfp5p@virginia.edu,
swarren@nvidia.com, linux-mtd@lists.infradead.org
Subject: Re: M25p80 little bug
Date: Fri, 12 Jul 2013 05:51:05 +0200 [thread overview]
Message-ID: <201307120551.05957.marex@denx.de> (raw)
In-Reply-To: <CAHSAbzMWjDrB94Gp-3x4iUWpFewd81f8aeSg0+8pvsvMop0BQg@mail.gmail.com>
Dear yuhang wang,
> Hi,
>
> There seems two bugs in m25p80 driver.
> 1: The position to kmalloc flash->command seems incorrect. Because
> flash->fast_read is not set.
> 2: There is no place to free flash if error occur in probe.
Please use git send-email to submit the patch, the patch below is completely
deformed :(
> From 4c9c1fc03b5a953b0a95f543de1fbdfc62f28b42 Mon Sep 17 00:00:00 2001
> From: wangyuhang <wangyuhang2014@gmail.com>
> Date: Wed, 10 Jul 2013 16:58:17 +0800
> Subject: [PATCH] m25p80 bug Signed-off-by: wangyuhang
> <wangyuhang2014@gmail.com>
>
> Signed-off-by: wangyuhang <wangyuhang2014@gmail.com>
> ---
> drivers/mtd/devices/m25p80.c | 24 ++++++++++++++----------
> 1 file changed, 14 insertions(+), 10 deletions(-)
>
> diff --git a/drivers/mtd/devices/m25p80.c b/drivers/mtd/devices/m25p80.c
> index 5b6b072..6bb9e2b 100644
> --- a/drivers/mtd/devices/m25p80.c
> +++ b/drivers/mtd/devices/m25p80.c
> @@ -901,7 +901,7 @@ static int m25p_probe(struct spi_device *spi)
> struct flash_platform_data *data;
> struct m25p *flash;
> struct flash_info *info;
> - unsigned i;
> + unsigned i,ret;
> struct mtd_part_parser_data ppdata;
> struct device_node __maybe_unused *np = spi->dev.of_node;
>
> @@ -958,13 +958,7 @@ static int m25p_probe(struct spi_device *spi)
> flash = kzalloc(sizeof *flash, GFP_KERNEL);
> if (!flash)
> return -ENOMEM;
> - flash->command = kmalloc(MAX_CMD_SIZE + (flash->fast_read ? 1 : 0),
> - GFP_KERNEL);
> - if (!flash->command) {
> - kfree(flash);
> - return -ENOMEM;
> - }
> -
> +
Why not just use devm_kzalloc() or such ?
> flash->spi = spi;
> mutex_init(&flash->lock);
> dev_set_drvdata(&spi->dev, flash);
> @@ -1031,7 +1025,12 @@ static int m25p_probe(struct spi_device *spi)
> #ifdef CONFIG_M25PXX_USE_FAST_READ
> flash->fast_read = true;
> #endif
> -
> + flash->command = kmalloc(MAX_CMD_SIZE + (flash->fast_read ? 1 : 0),
> + GFP_KERNEL);
> + if (!flash->command) {
> + kfree(flash);
> + return -ENOMEM;
> + }
> if (info->addr_width)
> flash->addr_width = info->addr_width;
> else {
> @@ -1067,9 +1066,14 @@ static int m25p_probe(struct spi_device *spi)
> /* partitions should match sector boundaries; and it may be good to
> * use readonly partitions for writeprotected sectors (BP2..BP0).
> */
> - return mtd_device_parse_register(&flash->mtd, NULL, &ppdata,
> + ret = mtd_device_parse_register(&flash->mtd, NULL, &ppdata,
> data ? data->parts : NULL,
> data ? data->nr_parts : 0);
> + if (ret) {
> + kfree(flash->command);
> + kfree(flash);
Then all this would go away.
> + }
> + return ret;
> }
>
>
> --
> 1.7.9.5
Best regards,
Marek Vasut
prev parent reply other threads:[~2013-07-12 3:51 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-07-12 2:06 M25p80 little bug yuhang wang
2013-07-12 3:51 ` Marek Vasut [this message]
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=201307120551.05957.marex@denx.de \
--to=marex@denx.de \
--cc=artem.bityutskiy@linux.intel.com \
--cc=linux-mtd@lists.infradead.org \
--cc=swarren@nvidia.com \
--cc=wangyuhang2014@gmail.com \
--cc=wfp5p@virginia.edu \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.