diff mbox series

[kvm-unit-tests,v2,2/2] lib/alloc_page: Fix compilation issue on 32bit archs

Message ID 20200714130030.56037-3-imbrenda@linux.ibm.com (mailing list archive)
State New, archived
Headers show
Series Fix some compilation issues on 32bit | expand

Commit Message

Claudio Imbrenda July 14, 2020, 1 p.m. UTC
The assert in lib/alloc_page is hardcoded to long.

Use the z modifier instead, which is meant to be used for size_t.

Fixes: 73f4b202beb39 ("lib/alloc_page: change some parameter types")
Signed-off-by: Claudio Imbrenda <imbrenda@linux.ibm.com>
---
 lib/alloc_page.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Comments

Thomas Huth July 15, 2020, 2:19 p.m. UTC | #1
On 14/07/2020 15.00, Claudio Imbrenda wrote:
> The assert in lib/alloc_page is hardcoded to long.
> 
> Use the z modifier instead, which is meant to be used for size_t.
> 
> Fixes: 73f4b202beb39 ("lib/alloc_page: change some parameter types")
> Signed-off-by: Claudio Imbrenda <imbrenda@linux.ibm.com>
> ---
>  lib/alloc_page.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/lib/alloc_page.c b/lib/alloc_page.c
> index fa3c527..74fe726 100644
> --- a/lib/alloc_page.c
> +++ b/lib/alloc_page.c
> @@ -29,11 +29,11 @@ void free_pages(void *mem, size_t size)
>  	assert_msg((unsigned long) mem % PAGE_SIZE == 0,
>  		   "mem not page aligned: %p", mem);
>  
> -	assert_msg(size % PAGE_SIZE == 0, "size not page aligned: %#lx", size);
> +	assert_msg(size % PAGE_SIZE == 0, "size not page aligned: %#zx", size);
>  
>  	assert_msg(size == 0 || (uintptr_t)mem == -size ||
>  		   (uintptr_t)mem + size > (uintptr_t)mem,
> -		   "mem + size overflow: %p + %#lx", mem, size);
> +		   "mem + size overflow: %p + %#zx", mem, size);
>  
>  	if (size == 0) {
>  		freelist = NULL;

Reviewed-by: Thomas Huth <thuth@redhat.com>
Nadav Amit July 16, 2020, 7:11 a.m. UTC | #2
> On Jul 14, 2020, at 6:00 AM, Claudio Imbrenda <imbrenda@linux.ibm.com> wrote:
> 
> The assert in lib/alloc_page is hardcoded to long.
> 
> Use the z modifier instead, which is meant to be used for size_t.
> 
> Fixes: 73f4b202beb39 ("lib/alloc_page: change some parameter types")
> Signed-off-by: Claudio Imbrenda <imbrenda@linux.ibm.com>
> ---
> lib/alloc_page.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/lib/alloc_page.c b/lib/alloc_page.c
> index fa3c527..74fe726 100644
> --- a/lib/alloc_page.c
> +++ b/lib/alloc_page.c
> @@ -29,11 +29,11 @@ void free_pages(void *mem, size_t size)
> 	assert_msg((unsigned long) mem % PAGE_SIZE == 0,
> 		   "mem not page aligned: %p", mem);
> 
> -	assert_msg(size % PAGE_SIZE == 0, "size not page aligned: %#lx", size);
> +	assert_msg(size % PAGE_SIZE == 0, "size not page aligned: %#zx", size);
> 
> 	assert_msg(size == 0 || (uintptr_t)mem == -size ||
> 		   (uintptr_t)mem + size > (uintptr_t)mem,
> -		   "mem + size overflow: %p + %#lx", mem, size);
> +		   "mem + size overflow: %p + %#zx", mem, size);
> 
> 	if (size == 0) {
> 		freelist = NULL;
> — 
> 2.26.2

Sean sent a different patch ("lib/alloc_page: Revert to 'unsigned long’ for
@size params”) that changes size to unsigned long, so you really should
synchronize.
Claudio Imbrenda July 16, 2020, 9:55 a.m. UTC | #3
On Thu, 16 Jul 2020 00:11:31 -0700
Nadav Amit <nadav.amit@gmail.com> wrote:

> > On Jul 14, 2020, at 6:00 AM, Claudio Imbrenda
> > <imbrenda@linux.ibm.com> wrote:
> > 
> > The assert in lib/alloc_page is hardcoded to long.
> > 
> > Use the z modifier instead, which is meant to be used for size_t.
> > 
> > Fixes: 73f4b202beb39 ("lib/alloc_page: change some parameter types")
> > Signed-off-by: Claudio Imbrenda <imbrenda@linux.ibm.com>
> > ---
> > lib/alloc_page.c | 4 ++--
> > 1 file changed, 2 insertions(+), 2 deletions(-)
> > 
> > diff --git a/lib/alloc_page.c b/lib/alloc_page.c
> > index fa3c527..74fe726 100644
> > --- a/lib/alloc_page.c
> > +++ b/lib/alloc_page.c
> > @@ -29,11 +29,11 @@ void free_pages(void *mem, size_t size)
> > 	assert_msg((unsigned long) mem % PAGE_SIZE == 0,
> > 		   "mem not page aligned: %p", mem);
> > 
> > -	assert_msg(size % PAGE_SIZE == 0, "size not page aligned:
> > %#lx", size);
> > +	assert_msg(size % PAGE_SIZE == 0, "size not page aligned:
> > %#zx", size);
> > 
> > 	assert_msg(size == 0 || (uintptr_t)mem == -size ||
> > 		   (uintptr_t)mem + size > (uintptr_t)mem,
> > -		   "mem + size overflow: %p + %#lx", mem, size);
> > +		   "mem + size overflow: %p + %#zx", mem, size);
> > 
> > 	if (size == 0) {
> > 		freelist = NULL;
> > — 
> > 2.26.2  
> 
> Sean sent a different patch ("lib/alloc_page: Revert to 'unsigned
> long’ for @size params”) that changes size to unsigned long, so you
> really should synchronize.

I know, this is a (simpler) alternative to his patch.
diff mbox series

Patch

diff --git a/lib/alloc_page.c b/lib/alloc_page.c
index fa3c527..74fe726 100644
--- a/lib/alloc_page.c
+++ b/lib/alloc_page.c
@@ -29,11 +29,11 @@  void free_pages(void *mem, size_t size)
 	assert_msg((unsigned long) mem % PAGE_SIZE == 0,
 		   "mem not page aligned: %p", mem);
 
-	assert_msg(size % PAGE_SIZE == 0, "size not page aligned: %#lx", size);
+	assert_msg(size % PAGE_SIZE == 0, "size not page aligned: %#zx", size);
 
 	assert_msg(size == 0 || (uintptr_t)mem == -size ||
 		   (uintptr_t)mem + size > (uintptr_t)mem,
-		   "mem + size overflow: %p + %#lx", mem, size);
+		   "mem + size overflow: %p + %#zx", mem, size);
 
 	if (size == 0) {
 		freelist = NULL;