mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Josh Boyer" <jwboyer@gmail.com>
To: "Thiago Galesi" <thiagogalesi@gmail.com>
Cc: "David Woodhouse" <dwmw2@infradead.org>,
	linux-kernel@vger.kernel.org, linux-mtd@lists.infradead.org
Subject: Re: [PATCH] Remove unnecessary kmalloc/kfree calls in mtdchar
Date: Mon, 17 Apr 2006 07:06:54 -0500	[thread overview]
Message-ID: <625fc13d0604170506n53147772vec944cdd7f2daef7@mail.gmail.com> (raw)
In-Reply-To: <82ecf08e0604141938w4b29259av797e3115b79042a0@mail.gmail.com>

On 4/14/06, Thiago Galesi <thiagogalesi@gmail.com> wrote:
> This patch removes the use of repeated calls to kmalloc / kfree when
> writing / reading from a MTD char device. Not the ideal solution
> mentioned in the driver, but nonetheless better.

NAK.  This patch introduces a bug.  See below.

>
> Index: linux-2.6.16.2/drivers/mtd/mtdchar.c
> ===================================================================
> --- linux-2.6.16.2.orig/drivers/mtd/mtdchar.c
> +++ linux-2.6.16.2/drivers/mtd/mtdchar.c
> @@ -170,15 +170,18 @@ static ssize_t mtd_read(struct file *fil
>
>         /* FIXME: Use kiovec in 2.5 to lock down the user's buffers
>            and pass them directly to the MTD functions */
> -       while (count) {
> -               if (count > MAX_KMALLOC_SIZE)
> -                       len = MAX_KMALLOC_SIZE;
> -               else
> -                       len = count;
>
> -               kbuf=kmalloc(len,GFP_KERNEL);
> -               if (!kbuf)
> -                       return -ENOMEM;
> +       if (count > MAX_KMALLOC_SIZE)
> +               len = MAX_KMALLOC_SIZE;
> +       else
> +               len = count;

Now that len is set outside of the loop, it is always the same size. 
If count is large enough to require more than a single read, the the
original size will still be used and it could overflow the user's
buffer.

I agree that doing the kmallocs in a loop looks nasty.  But we need to
make sure moving out of the loop doesn't break things.

josh

  reply	other threads:[~2006-04-17 12:06 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-04-15  2:38 Thiago Galesi
2006-04-17 12:06 ` Josh Boyer [this message]
2006-04-17 13:19   ` Thiago Galesi
2006-04-17 14:50     ` David Woodhouse
2006-04-17 15:03       ` Thiago Galesi
     [not found]         ` <1145290249.13200.17.camel@pmac.infradead.org>
2006-04-17 16:24           ` Thiago Galesi
2006-04-18  2:06             ` Josh Boyer

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=625fc13d0604170506n53147772vec944cdd7f2daef7@mail.gmail.com \
    --to=jwboyer@gmail.com \
    --cc=dwmw2@infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mtd@lists.infradead.org \
    --cc=thiagogalesi@gmail.com \
    /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

all inboxes | Powered by JetHome®