Skip to contentSkip to conversation

mm/hmm/test: fix an error code in hmm_dmirror_init()

PATCH In review Dan Carpenter 2 participants 2 messages May 13, 2020

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

PATCH 1/1 mm/hmm/test: fix an error code in hmm_dmirror_init()

If the allocation fails, then this should return -ENOMEM instead of success.

Fixes a149d2eb654b ("mm/hmm/test: add selftest driver for HMM")
---
 lib/test_hmm.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
lib/test_hmm.c +3 -1
index 00bca6116f930..b4d9434e49e72 100644
@@ -1119,8 +1119,10 @@ static int __init hmm_dmirror_init(void)
 	 * make the code here simpler (i.e., we need a struct page for it).
 	 */
 	dmirror_zero_page = alloc_page(GFP_HIGHUSER | __GFP_ZERO);
-	if (!dmirror_zero_page)
+	if (!dmirror_zero_page) {
+		ret = -ENOMEM;
 		goto err_chrdev;
+	}
 
 	pr_info("HMM test module loaded. This is only for testing HMM.\n");
 	return 0;
Signature · 1 line
2.26.2
#1 lore raw
Quoted 16 lines · Dan Carpenter

If the allocation fails, then this should return -ENOMEM instead of success.

Fixes a149d2eb654b ("mm/hmm/test: add selftest driver for HMM")
---
  lib/test_hmm.c | 4 +++-
  1 file changed, 3 insertions(+), 1 deletion(-)
lib/test_hmm.c +0 -0
index 00bca6116f930..b4d9434e49e72 100644
@@ -1119,8 +1119,10 @@ static int __init hmm_dmirror_init(void)
  	 * make the code here simpler (i.e., we need a struct page for it).

lib/test_hmm.c static int __init hmm_dmirror_init(void) · line 1128

Quoted 10 lines
lib/test_hmm.c +3 -1
  	 */
  	dmirror_zero_page = alloc_page(GFP_HIGHUSER | __GFP_ZERO);
-	if (!dmirror_zero_page)
+	if (!dmirror_zero_page) {
+		ret = -ENOMEM;
  		goto err_chrdev;
+	}
 
  	pr_info("HMM test module loaded. This is only for testing HMM.\n");
  	return 0;

Thanks for fixing this. It looks like Wei Yongjun beat you to it and Jason Gunthorpe has applied it to the hmm tree.

https://lore.kernel.org/linux-mm/[email protected]/