[kvm-unit-tests PATCH 03/18] trivial: alloc: don't use 'top' outside spinlock

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This is a fix just due to being too much of a type-A person.
I noticed the issue while reading over the function, and
decided to fix it, even though it's unlikely to be a problem
ever because top is read-mostly (like written once, then only
read, type of mostly).

Signed-off-by: Andrew Jones <drjones@xxxxxxxxxx>
---
 lib/alloc.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/lib/alloc.c b/lib/alloc.c
index ad6761430c965..34f71a337d868 100644
--- a/lib/alloc.c
+++ b/lib/alloc.c
@@ -61,15 +61,17 @@ static phys_addr_t phys_alloc_aligned_safe(phys_addr_t size,
 {
 	static bool warned = false;
 	phys_addr_t addr, size_orig = size;
-	u64 top_safe = top;
+	u64 top_safe;
+
+	spin_lock(&lock);
+
+	top_safe = top;
 
 	if (safe && sizeof(long) == 4)
 		top_safe = MIN(top, 1ULL << 32);
 
 	align = MAX(align, align_min);
 
-	spin_lock(&lock);
-
 	addr = ALIGN(base, align);
 	size += addr - base;
 
-- 
2.4.3

--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [KVM ARM]     [KVM ia64]     [KVM ppc]     [Virtualization Tools]     [Spice Development]     [Libvirt]     [Libvirt Users]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite Questions]     [Linux Kernel]     [Linux SCSI]     [XFree86]
  Powered by Linux