Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

sparc: fix size argument to find_next_zero_bit()

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
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by

Akinobu Mita and committed by
David S. Miller
711c71a0 e637804c

+2 -3
+2 -3
arch/sparc/kernel/iommu.c
··· 255 255 static int iommu_alloc_ctx(struct iommu *iommu) 256 256 { 257 257 int lowest = iommu->ctx_lowest_free; 258 - int sz = IOMMU_NUM_CTXS - lowest; 259 - int n = find_next_zero_bit(iommu->ctx_bitmap, sz, lowest); 258 + int n = find_next_zero_bit(iommu->ctx_bitmap, IOMMU_NUM_CTXS, lowest); 260 259 261 - if (unlikely(n == sz)) { 260 + if (unlikely(n == IOMMU_NUM_CTXS)) { 262 261 n = find_next_zero_bit(iommu->ctx_bitmap, lowest, 1); 263 262 if (unlikely(n == lowest)) { 264 263 printk(KERN_WARNING "IOMMU: Ran out of contexts.\n");