From: Guennadi Liakhovetski <lg@denx.de>
To: Johannes Weiner <hannes@cmpxchg.org>
Cc: linux-kernel@vger.kernel.org, Andrew Morton <akpm@linux-foundation.org>
Subject: Re: [PATCH] bitmap: fix bitmap_find_free_region()
Date: Fri, 19 Dec 2008 14:18:22 +0100 (CET) [thread overview]
Message-ID: <Pine.LNX.4.64.0812191413520.4536@axis700.grange> (raw)
In-Reply-To: <20081219130211.GA1560@cmpxchg.org>
On Fri, 19 Dec 2008, Johannes Weiner wrote:
> On Fri, Dec 19, 2008 at 12:26:41PM +0100, Guennadi Liakhovetski wrote:
> > Currently bitmap_find_free_region() assumes, that the requested region
> > size is smaller than the entire bitmap. If this is not the case it fails
> > to detect it and returns success, while pointing at a position outside of
> > the region.
> >
> > Signed-off-by: Guennadi Liakhovetski <lg@denx.de>
> > Cc: Andrew Morton <akpm@linux-foundation.org>
> > ---
> > It is hard to believe, that this is a bug, last time this code was touched
> > in 2006... Or should the caller guarantee, that the requested region is
> > not larger than the bitmap? Then dma_alloc_from_coherent() is buggy, which
> > is where I hit this bug. But it seems to me bitmap_find_free_region()
> > should be fixed.
> >
> > diff --git a/lib/bitmap.c b/lib/bitmap.c
> > index 1338469..079c5e3 100644
> > --- a/lib/bitmap.c
> > +++ b/lib/bitmap.c
> > @@ -950,6 +950,9 @@ int bitmap_find_free_region(unsigned long *bitmap, int bits, int order)
> > {
> > int pos; /* scans bitmap by regions of size order */
> >
> > + if (bits < 1 << order)
> > + return -ENOMEM;
>
> I think this is an error on the callsite, so a WARN_ON() might be good
> to spot these. I would be interested in the callpath that triggered
> this bug for you.
As I said above it's called from dma_alloc_from_coherent() from
dma_alloc_coherent().
> And return -ENOSPC?
So, you agree that a check should be added to bitmap_find_free_region()?
As for details - to warn or not to warn and what error code to return,
that can be discussed, although "No space left on device" doesn't seem to
fit very well IMHO:-)
Thanks
Guennadi
---
Guennadi Liakhovetski, Ph.D.
DENX Software Engineering GmbH, MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: +49-8142-66989-0 Fax: +49-8142-66989-80 Email: office@denx.de
next prev parent reply other threads:[~2008-12-19 13:18 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-12-19 11:26 Guennadi Liakhovetski
2008-12-19 13:02 ` Johannes Weiner
2008-12-19 13:18 ` Guennadi Liakhovetski [this message]
2008-12-19 13:59 ` Pekka Enberg
2008-12-19 14:47 ` Johannes Weiner
2008-12-19 15:09 ` Guennadi Liakhovetski
2008-12-19 22:45 ` Johannes Weiner
2008-12-19 23:19 ` Guennadi Liakhovetski
2008-12-20 11:34 ` Johannes Weiner
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=Pine.LNX.4.64.0812191413520.4536@axis700.grange \
--to=lg@denx.de \
--cc=akpm@linux-foundation.org \
--cc=hannes@cmpxchg.org \
--cc=linux-kernel@vger.kernel.org \
/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®