mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Kyle Hubert <khubert@gmail.com>
To: linux-kernel@vger.kernel.org
Subject: iommu-helper.c -> find_next_zero_area errors
Date: Tue, 13 Oct 2009 02:01:03 -0700	[thread overview]
Message-ID: <9a158e2e0910130201m1f63a7d7h15c8a7445a36cd51@mail.gmail.com> (raw)

In the function find_next_zero_area in iommu-helper.c, I think there
are two small issues. For one, it appears the conditionals after
find_next_zero_bit will cause failures when there is still room in the
IOMMU area. Here is the code in question:

  15again:
  16        index = find_next_zero_bit(map, size, start);
  17
  18        /* Align allocation */
  19        index = (index + align_mask) & ~align_mask;
  20
  21        end = index + nr;
  22        if (end >= size)
  23                return -1;
  24        for (i = index; i < end; i++) {
  25                if (test_bit(i, map)) {
  26                        start = i+1;
  27                        goto again;
  28                }
  29        }
  30        return index;

On line 16, we get the index with the next zero bit in the bit-field.
Then the "end" value is compared against size on line 22. By testing
for >=, an allocation of 64 elements in a 64 bit bit-field would
result in (0 + 64) >= 64. This means it would return -1, or, no space.
Anything that butts against the end of the area will fail.

Then continuing on to line 24, we see the for loop starting at the
"index" value. Index was just returned by find_next_zero_bit, so we
know it's zero, and there is no reason to call test_bit on it. This is
just a spurious execution of the loop.

I would think you would want it to look like this:

-       if (end >= size)
+       if (end > size)
               return -1;
-       for (i = index; i < end; i++) {
+       for (i = index + 1; i < end; i++) {

Thanks,

-Kyle Hubert

                 reply	other threads:[~2009-10-13  9:01 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=9a158e2e0910130201m1f63a7d7h15c8a7445a36cd51@mail.gmail.com \
    --to=khubert@gmail.com \
    --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®