Skip to content

Commit

Permalink
selftests/resctrl: Replace obsolete memalign() with posix_memalign()
Browse files Browse the repository at this point in the history
memalign() is obsolete according to its manpage.

Replace memalign() with posix_memalign() and remove malloc.h include
that was there for memalign().

As a pointer is passed into posix_memalign(), initialize *p to NULL
to silence a warning about the function's return value being used as
uninitialized (which is not valid anyway because the error is properly
checked before p is returned).

Suggested-by: Reinette Chatre <reinette.chatre@intel.com>
Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
Reviewed-by: Reinette Chatre <reinette.chatre@intel.com>
Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>
  • Loading branch information
Ilpo Järvinen authored and Shuah Khan committed Apr 10, 2023
1 parent 0d45c83 commit 5d869d7
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions tools/testing/selftests/resctrl/fill_buf.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
#include <sys/types.h>
#include <sys/wait.h>
#include <inttypes.h>
#include <malloc.h>
#include <string.h>

#include "resctrl.h"
Expand Down Expand Up @@ -64,11 +63,13 @@ static void mem_flush(void *p, size_t s)

static void *malloc_and_init_memory(size_t s)
{
void *p = NULL;
uint64_t *p64;
size_t s64;
int ret;

void *p = memalign(PAGE_SIZE, s);
if (!p)
ret = posix_memalign(&p, PAGE_SIZE, s);
if (ret < 0)
return NULL;

p64 = (uint64_t *)p;
Expand Down

0 comments on commit 5d869d7

Please sign in to comment.