Skip to contentSkip to conversation

mm: huge_memory: Replace obsolete memalign() with posix_memalign()

PATCH In review Deming Wang 2 participants 2 messages Apr 12, 2023

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mm: huge_memory: Replace obsolete memalign() with posix_memalign()

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).

---
 tools/testing/selftests/mm/split_huge_page_test.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
tools/testing/selftests/mm/split_huge_page_test.c +3 -3
index cbb5e6893cbf..8f48f07bc821 100644
@@ -96,10 +96,10 @@ void split_pmd_thp(void)
 	char *one_page;
 	size_t len = 4 * pmd_pagesize;
 	size_t i;
+	int ret;
 
-	one_page = memalign(pmd_pagesize, len);
-
-	if (!one_page) {
+	ret = posix_memalign((void **)(&one_page), pmd_pagesize, len);
+	if (ret < 0) {
 		printf("Fail to allocate memory\n");
 		exit(EXIT_FAILURE);
 	}
Signature · 1 line
2.27.0
#1 lore raw
Quoted 4 lines · Deming Wang

memalign() is obsolete according to its manpage.

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

Comment does not apply.

Quoted 5 lines

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).

Comment does not apply.

Quoted 11 lines
---
  tools/testing/selftests/mm/split_huge_page_test.c | 6 +++---
  1 file changed, 3 insertions(+), 3 deletions(-)
tools/testing/selftests/mm/split_huge_page_test.c +0 -0
index cbb5e6893cbf..8f48f07bc821 100644

tools/testing/selftests/mm/split_huge_page_test.c void split_pmd_thp(void) · line 101

Quoted 9 lines
tools/testing/selftests/mm/split_huge_page_test.c +2 -3
@@ -96,10 +96,10 @@ void split_pmd_thp(void)
  	char *one_page;
  	size_t len = 4 * pmd_pagesize;
  	size_t i;
+	int ret;
 
-	one_page = memalign(pmd_pagesize, len);
-
-	if (!one_page) {
+	ret = posix_memalign((void **)(&one_page), pmd_pagesize, len);

ret = posix_memalign((void **)&one_page, pmd_pagesize, len);

Should do.

Quoted 4 lines
tools/testing/selftests/mm/split_huge_page_test.c +1 -0
+	if (ret < 0) {
  		printf("Fail to allocate memory\n");
  		exit(EXIT_FAILURE);
  	}
Signature · 3 lines
Thanks,

David / dhildenb