diff mbox

[slof] helpers: Fix SLOF_alloc_mem_aligned to meet callers expectation

Message ID 1426235812-3749-1-git-send-email-aik@ozlabs.ru (mailing list archive)
State Not Applicable
Headers show

Commit Message

Alexey Kardashevskiy March 13, 2015, 8:36 a.m. UTC
Every caller of SLOF_alloc_mem_aligned() assumes the size is the first
argument while it is not.

This switches align and size and fixes random memory corruptions.

This is grep for SLOF_alloc_mem_aligned with this patch applied:

include/helpers.h|27| extern void *SLOF_alloc_mem_aligned(long size, long align);
lib/libveth/veth.c|103| buffer_list = SLOF_alloc_mem_aligned(8192, 4096);
lib/libveth/veth.c|105| rx_queue = SLOF_alloc_mem_aligned(rx_queue_len, 16);
lib/libvirtio/virtio-net.c|101| vq[i].desc = SLOF_alloc_mem_aligned(virtio_vring_size(vq[i].size), 4096);
slof/helpers.c|70| void *SLOF_alloc_mem_aligned(long size, long align)

Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
---
 include/helpers.h | 2 +-
 slof/helpers.c    | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

Comments

Nikunj A Dadhania March 13, 2015, 8:55 a.m. UTC | #1
Alexey Kardashevskiy <aik@ozlabs.ru> writes:

> Every caller of SLOF_alloc_mem_aligned() assumes the size is the first
> argument while it is not.
>
> This switches align and size and fixes random memory corruptions.
>
> This is grep for SLOF_alloc_mem_aligned with this patch applied:
>
> include/helpers.h|27| extern void *SLOF_alloc_mem_aligned(long size, long align);
> lib/libveth/veth.c|103| buffer_list = SLOF_alloc_mem_aligned(8192, 4096);
> lib/libveth/veth.c|105| rx_queue = SLOF_alloc_mem_aligned(rx_queue_len, 16);
> lib/libvirtio/virtio-net.c|101| vq[i].desc = SLOF_alloc_mem_aligned(virtio_vring_size(vq[i].size), 4096);
> slof/helpers.c|70| void *SLOF_alloc_mem_aligned(long size, long align)
>
> Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>

Reviewed-by: Nikunj A Dadhania <nikunj@linux.vnet.ibm.com>

> ---
>  include/helpers.h | 2 +-
>  slof/helpers.c    | 2 +-
>  2 files changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/include/helpers.h b/include/helpers.h
> index f6d4375..fb10534 100644
> --- a/include/helpers.h
> +++ b/include/helpers.h
> @@ -24,7 +24,7 @@ extern void SLOF_usleep(uint32_t time);
>  extern void *SLOF_dma_alloc(long size);
>  extern void SLOF_dma_free(void *virt, long size);
>  extern void *SLOF_alloc_mem(long size);
> -extern void *SLOF_alloc_mem_aligned(long align, long size);
> +extern void *SLOF_alloc_mem_aligned(long size, long align);
>  extern void SLOF_free_mem(void *addr, long size);
>  extern long SLOF_dma_map_in(void *virt, long size, int cacheable);
>  extern void SLOF_dma_map_out(long phys, void *virt, long size);
> diff --git a/slof/helpers.c b/slof/helpers.c
> index c582996..d7c1888 100644
> --- a/slof/helpers.c
> +++ b/slof/helpers.c
> @@ -67,7 +67,7 @@ void *SLOF_alloc_mem(long size)
>  	return (void *)forth_pop();
>  }
>
> -void *SLOF_alloc_mem_aligned(long align, long size)
> +void *SLOF_alloc_mem_aligned(long size, long align)
>  {
>  	unsigned long addr = (unsigned long)SLOF_alloc_mem(size + align - 1);
>  	addr = addr + align - 1;
> -- 
> 2.0.0
diff mbox

Patch

diff --git a/include/helpers.h b/include/helpers.h
index f6d4375..fb10534 100644
--- a/include/helpers.h
+++ b/include/helpers.h
@@ -24,7 +24,7 @@  extern void SLOF_usleep(uint32_t time);
 extern void *SLOF_dma_alloc(long size);
 extern void SLOF_dma_free(void *virt, long size);
 extern void *SLOF_alloc_mem(long size);
-extern void *SLOF_alloc_mem_aligned(long align, long size);
+extern void *SLOF_alloc_mem_aligned(long size, long align);
 extern void SLOF_free_mem(void *addr, long size);
 extern long SLOF_dma_map_in(void *virt, long size, int cacheable);
 extern void SLOF_dma_map_out(long phys, void *virt, long size);
diff --git a/slof/helpers.c b/slof/helpers.c
index c582996..d7c1888 100644
--- a/slof/helpers.c
+++ b/slof/helpers.c
@@ -67,7 +67,7 @@  void *SLOF_alloc_mem(long size)
 	return (void *)forth_pop();
 }
 
-void *SLOF_alloc_mem_aligned(long align, long size)
+void *SLOF_alloc_mem_aligned(long size, long align)
 {
 	unsigned long addr = (unsigned long)SLOF_alloc_mem(size + align - 1);
 	addr = addr + align - 1;