diff mbox series

[kvm-unit-tests,v2,2/4] lib/alloc_page: change some parameter types

Message ID 20200706164324.81123-3-imbrenda@linux.ibm.com (mailing list archive)
State New, archived
Headers show
Series More lib/alloc cleanup and a minor improvement | expand

Commit Message

Claudio Imbrenda July 6, 2020, 4:43 p.m. UTC
For size parameters, size_t is probably semantically more appropriate
than unsigned long (although they map to the same value).

For order, unsigned long is just too big. Also, get_order returns an
unsigned int anyway.

Signed-off-by: Claudio Imbrenda <imbrenda@linux.ibm.com>
Reviewed-by: Andrew Jones <drjones@redhat.com>
---
 lib/alloc_page.h | 6 +++---
 lib/alloc_page.c | 8 ++++----
 2 files changed, 7 insertions(+), 7 deletions(-)

Comments

Jim Mattson July 6, 2020, 4:58 p.m. UTC | #1
On Mon, Jul 6, 2020 at 9:43 AM Claudio Imbrenda <imbrenda@linux.ibm.com> wrote:
>
> For size parameters, size_t is probably semantically more appropriate
> than unsigned long (although they map to the same value).
>
> For order, unsigned long is just too big. Also, get_order returns an
> unsigned int anyway.
>
> Signed-off-by: Claudio Imbrenda <imbrenda@linux.ibm.com>
> Reviewed-by: Andrew Jones <drjones@redhat.com>
Reviewed-by: Jim Mattson <jmattson@google.com>
Thomas Huth July 13, 2020, 3:16 p.m. UTC | #2
On 06/07/2020 18.43, Claudio Imbrenda wrote:
> For size parameters, size_t is probably semantically more appropriate
> than unsigned long (although they map to the same value).
> 
> For order, unsigned long is just too big. Also, get_order returns an
> unsigned int anyway.
> 
> Signed-off-by: Claudio Imbrenda <imbrenda@linux.ibm.com>
> Reviewed-by: Andrew Jones <drjones@redhat.com>
> ---
>  lib/alloc_page.h | 6 +++---
>  lib/alloc_page.c | 8 ++++----
>  2 files changed, 7 insertions(+), 7 deletions(-)
> 
> diff --git a/lib/alloc_page.h b/lib/alloc_page.h
> index 6181299..d9aceb7 100644
> --- a/lib/alloc_page.h
> +++ b/lib/alloc_page.h
> @@ -11,10 +11,10 @@
>  bool page_alloc_initialized(void);
>  void page_alloc_ops_enable(void);
>  void *alloc_page(void);
> -void *alloc_pages(unsigned long order);
> +void *alloc_pages(unsigned int order);
>  void free_page(void *page);
> -void free_pages(void *mem, unsigned long size);
> -void free_pages_by_order(void *mem, unsigned long order);
> +void free_pages(void *mem, size_t size);
> +void free_pages_by_order(void *mem, unsigned int order);
>  unsigned int get_order(size_t size);
>  
>  #endif
> diff --git a/lib/alloc_page.c b/lib/alloc_page.c
> index 8769c3f..f16eaad 100644
> --- a/lib/alloc_page.c
> +++ b/lib/alloc_page.c
> @@ -21,7 +21,7 @@ bool page_alloc_initialized(void)
>  	return freelist != 0;
>  }
>  
> -void free_pages(void *mem, unsigned long size)
> +void free_pages(void *mem, size_t size)

 Hi Claudio,

this patch broke 32-bit x86 and arm builds:

 https://travis-ci.com/github/huth/kvm-unit-tests/jobs/360418977#L693
 https://travis-ci.com/github/huth/kvm-unit-tests/jobs/360418980#L545

I think you either need to adjust the format string, or cast the argument.

 Thomas
diff mbox series

Patch

diff --git a/lib/alloc_page.h b/lib/alloc_page.h
index 6181299..d9aceb7 100644
--- a/lib/alloc_page.h
+++ b/lib/alloc_page.h
@@ -11,10 +11,10 @@ 
 bool page_alloc_initialized(void);
 void page_alloc_ops_enable(void);
 void *alloc_page(void);
-void *alloc_pages(unsigned long order);
+void *alloc_pages(unsigned int order);
 void free_page(void *page);
-void free_pages(void *mem, unsigned long size);
-void free_pages_by_order(void *mem, unsigned long order);
+void free_pages(void *mem, size_t size);
+void free_pages_by_order(void *mem, unsigned int order);
 unsigned int get_order(size_t size);
 
 #endif
diff --git a/lib/alloc_page.c b/lib/alloc_page.c
index 8769c3f..f16eaad 100644
--- a/lib/alloc_page.c
+++ b/lib/alloc_page.c
@@ -21,7 +21,7 @@  bool page_alloc_initialized(void)
 	return freelist != 0;
 }
 
-void free_pages(void *mem, unsigned long size)
+void free_pages(void *mem, size_t size)
 {
 	void *old_freelist;
 	void *end;
@@ -53,7 +53,7 @@  void free_pages(void *mem, unsigned long size)
 	spin_unlock(&lock);
 }
 
-void free_pages_by_order(void *mem, unsigned long order)
+void free_pages_by_order(void *mem, unsigned int order)
 {
 	free_pages(mem, 1ul << (order + PAGE_SHIFT));
 }
@@ -79,7 +79,7 @@  void *alloc_page()
  * Allocates (1 << order) physically contiguous and naturally aligned pages.
  * Returns NULL if there's no memory left.
  */
-void *alloc_pages(unsigned long order)
+void *alloc_pages(unsigned int order)
 {
 	/* Generic list traversal. */
 	void *prev;
@@ -150,7 +150,7 @@  void free_page(void *page)
 static void *page_memalign(size_t alignment, size_t size)
 {
 	unsigned long n = ALIGN(size, PAGE_SIZE) >> PAGE_SHIFT;
-	unsigned long order;
+	unsigned int order;
 
 	if (!size)
 		return NULL;