* iommu-helper.c -> find_next_zero_area errors
@ 2009-10-13 9:01 Kyle Hubert
0 siblings, 0 replies; only message in thread
From: Kyle Hubert @ 2009-10-13 9:01 UTC (permalink / raw)
To: linux-kernel
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
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2009-10-13 9:01 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-10-13 9:01 iommu-helper.c -> find_next_zero_area errors Kyle Hubert
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®