From mboxrd@z Thu Jan 1 00:00:00 1970 From: Andrew Jones Subject: [kvm-unit-tests PATCH 03/18] trivial: alloc: don't use 'top' outside spinlock Date: Thu, 5 Nov 2015 18:24:28 -0600 Message-ID: <1446769483-21586-4-git-send-email-drjones@redhat.com> References: <1446769483-21586-1-git-send-email-drjones@redhat.com> Cc: alex.bennee@linaro.org, cov@codeaurora.org To: pbonzini@redhat.com, kvm@vger.kernel.org Return-path: Received: from mx1.redhat.com ([209.132.183.28]:45083 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S965779AbbKFAY7 (ORCPT ); Thu, 5 Nov 2015 19:24:59 -0500 In-Reply-To: <1446769483-21586-1-git-send-email-drjones@redhat.com> Sender: kvm-owner@vger.kernel.org List-ID: 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 --- 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