diff mbox

sparc: fix size argument to find_next_zero_bit()

Message ID 1297177190-1423-2-git-send-email-akinobu.mita@gmail.com
State Accepted
Delegated to: David Miller
Headers show

Commit Message

Akinobu Mita Feb. 8, 2011, 2:59 p.m. UTC
iommu_alloc_ctx() finds a zero bit in iommu->ctx_bitmap.  It starts
searching from iommu->ctx_lowest_free to the end of the bitmap.
But the size argument to find_next_zero_bit() in iommu_alloc_ctx()
is wrong.  It should be the bitmap size, not the maximum size to
search from the offset argument.

Fortunately iommu->ctx_lowest_free is almost unused and it will not
be more than 1. So the bug wasted only 1-bit at the end of
iommu->ctx_bitmap.

Signed-off-by: Akinobu Mita <akinobu.mita@gmail.com>
Cc: "David S. Miller" <davem@davemloft.net>
Cc: sparclinux@vger.kernel.org
---
 arch/sparc/kernel/iommu.c |    5 ++---
 1 files changed, 2 insertions(+), 3 deletions(-)

Comments

David Miller Feb. 9, 2011, 6:53 a.m. UTC | #1
From: Akinobu Mita <akinobu.mita@gmail.com>
Date: Tue,  8 Feb 2011 23:59:50 +0900

> iommu_alloc_ctx() finds a zero bit in iommu->ctx_bitmap.  It starts
> searching from iommu->ctx_lowest_free to the end of the bitmap.
> But the size argument to find_next_zero_bit() in iommu_alloc_ctx()
> is wrong.  It should be the bitmap size, not the maximum size to
> search from the offset argument.
> 
> Fortunately iommu->ctx_lowest_free is almost unused and it will not
> be more than 1. So the bug wasted only 1-bit at the end of
> iommu->ctx_bitmap.
> 
> Signed-off-by: Akinobu Mita <akinobu.mita@gmail.com>

Thank you for fixing this bug, applied!
--
To unsubscribe from this list: send the line "unsubscribe sparclinux" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/arch/sparc/kernel/iommu.c b/arch/sparc/kernel/iommu.c
index 47977a7..72509d0 100644
--- a/arch/sparc/kernel/iommu.c
+++ b/arch/sparc/kernel/iommu.c
@@ -255,10 +255,9 @@  static inline iopte_t *alloc_npages(struct device *dev, struct iommu *iommu,
 static int iommu_alloc_ctx(struct iommu *iommu)
 {
 	int lowest = iommu->ctx_lowest_free;
-	int sz = IOMMU_NUM_CTXS - lowest;
-	int n = find_next_zero_bit(iommu->ctx_bitmap, sz, lowest);
+	int n = find_next_zero_bit(iommu->ctx_bitmap, IOMMU_NUM_CTXS, lowest);
 
-	if (unlikely(n == sz)) {
+	if (unlikely(n == IOMMU_NUM_CTXS)) {
 		n = find_next_zero_bit(iommu->ctx_bitmap, lowest, 1);
 		if (unlikely(n == lowest)) {
 			printk(KERN_WARNING "IOMMU: Ran out of contexts.\n");