Skip to content

Commit 7ea434a

Browse files
Naoya Horiguchitorvalds
authored andcommitted
mm/hwpoison-inject: fix refcounting in no-injection case
Hwpoison injection via debugfs:hwpoison/corrupt-pfn takes a refcount of the target page. But current code doesn't release it if the target page is not supposed to be injected, which results in memory leak. This patch simply adds the refcount releasing code. Signed-off-by: Naoya Horiguchi <n-horiguchi@ah.jp.nec.com> Acked-by: Dean Nelson <dnelson@redhat.com> Cc: Andi Kleen <andi@firstfloor.org> Cc: Andrea Arcangeli <aarcange@redhat.com> Cc: Hidetoshi Seto <seto.hidetoshi@jp.fujitsu.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 602498f commit 7ea434a

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

mm/hwpoison-inject.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ static int hwpoison_inject(void *data, u64 val)
4040
* This implies unable to support non-LRU pages.
4141
*/
4242
if (!PageLRU(p) && !PageHuge(p))
43-
return 0;
43+
goto put_out;
4444

4545
/*
4646
* do a racy check with elevated page count, to make sure PG_hwpoison
@@ -52,11 +52,14 @@ static int hwpoison_inject(void *data, u64 val)
5252
err = hwpoison_filter(hpage);
5353
unlock_page(hpage);
5454
if (err)
55-
return 0;
55+
goto put_out;
5656

5757
inject:
5858
pr_info("Injecting memory failure at pfn %#lx\n", pfn);
5959
return memory_failure(pfn, 18, MF_COUNT_INCREASED);
60+
put_out:
61+
put_page(hpage);
62+
return 0;
6063
}
6164

6265
static int hwpoison_unpoison(void *data, u64 val)

0 commit comments

Comments
 (0)