Commit 9ee5d17
mm/hugetlb: fix incorrect error return from hugetlb_reserve_pages()
The function hugetlb_reserve_pages() returns the number of pages added
to the reservation map on success and a negative error code on failure
(e.g. -EINVAL, -ENOMEM). However, in some error paths, it may return -1
directly.
For example, a failure at:
if (hugetlb_acct_memory(h, gbl_reserve) < 0)
goto out_put_pages;
results in returning -1 (since add = -1), which may be misinterpreted
in userspace as -EPERM.
Fix this by explicitly capturing and propagating the return values from
helper functions, and using -EINVAL for all other failure cases.
Link: https://lkml.kernel.org/r/20251125171350.86441-1-skolothumtho@nvidia.com
Fixes: 986f5f2 ("mm/hugetlb: make hugetlb_reserve_pages() return nr of entries updated")
Signed-off-by: Shameer Kolothum <skolothumtho@nvidia.com>
Reviewed-by: Joshua Hahn <joshua.hahnjy@gmail.com>
Reviewed-by: Jason Gunthorpe <jgg@nvidia.com>
Acked-by: Oscar Salvador <osalvador@suse.de>
Cc: Matthew R. Ochs <mochs@nvidia.com>
Cc: Muchun Song <muchun.song@linux.dev>
Cc: Nicolin Chen <nicolinc@nvidia.com>
Cc: Vivek Kasireddy <vivek.kasireddy@intel.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>1 parent 40a4af5 commit 9ee5d17
1 file changed
Lines changed: 18 additions & 7 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6579 | 6579 | | |
6580 | 6580 | | |
6581 | 6581 | | |
| 6582 | + | |
6582 | 6583 | | |
6583 | 6584 | | |
6584 | 6585 | | |
| |||
6612 | 6613 | | |
6613 | 6614 | | |
6614 | 6615 | | |
6615 | | - | |
| 6616 | + | |
| 6617 | + | |
6616 | 6618 | | |
| 6619 | + | |
6617 | 6620 | | |
6618 | 6621 | | |
6619 | 6622 | | |
6620 | 6623 | | |
6621 | 6624 | | |
6622 | 6625 | | |
6623 | 6626 | | |
6624 | | - | |
| 6627 | + | |
| 6628 | + | |
| 6629 | + | |
6625 | 6630 | | |
| 6631 | + | |
6626 | 6632 | | |
6627 | | - | |
6628 | | - | |
| 6633 | + | |
| 6634 | + | |
| 6635 | + | |
6629 | 6636 | | |
6630 | 6637 | | |
6631 | 6638 | | |
| |||
6641 | 6648 | | |
6642 | 6649 | | |
6643 | 6650 | | |
6644 | | - | |
| 6651 | + | |
| 6652 | + | |
6645 | 6653 | | |
| 6654 | + | |
6646 | 6655 | | |
6647 | 6656 | | |
6648 | 6657 | | |
6649 | 6658 | | |
6650 | 6659 | | |
6651 | | - | |
| 6660 | + | |
| 6661 | + | |
6652 | 6662 | | |
6653 | 6663 | | |
6654 | 6664 | | |
| |||
6667 | 6677 | | |
6668 | 6678 | | |
6669 | 6679 | | |
| 6680 | + | |
6670 | 6681 | | |
6671 | 6682 | | |
6672 | 6683 | | |
| |||
6726 | 6737 | | |
6727 | 6738 | | |
6728 | 6739 | | |
6729 | | - | |
| 6740 | + | |
6730 | 6741 | | |
6731 | 6742 | | |
6732 | 6743 | | |
| |||
0 commit comments