diff mbox

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

Message ID 1446769483-21586-4-git-send-email-drjones@redhat.com (mailing list archive)
State New, archived
Headers show

Commit Message

Andrew Jones Nov. 6, 2015, 12:24 a.m. UTC
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@redhat.com>
---
 lib/alloc.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

Comments

Paolo Bonzini Nov. 10, 2015, 4:24 p.m. UTC | #1
On 06/11/2015 01:24, Andrew Jones wrote:
> 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@redhat.com>
> ---
>  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;
>  
> 

Applied, thanks.

Paolo
--
To unsubscribe from this list: send the line "unsubscribe kvm" 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/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;