Skip to content

Commit

Permalink
mm/page_alloc: restrict and formalize compound_page_dtors[]
Browse files Browse the repository at this point in the history
Restrict elements in compound_page_dtors[] array per NR_COMPOUND_DTORS and
explicitly position them according to enum compound_dtor_id.  This
improves protection against possible misalignment between
compound_page_dtors[] and enum compound_dtor_id later on.

Signed-off-by: Anshuman Khandual <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Reviewed-by: David Hildenbrand <[email protected]>
Link: http://lkml.kernel.org/r/[email protected]
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
Anshuman Khandual authored and torvalds committed Jun 4, 2020
1 parent aa09259 commit ae70edd
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion include/linux/mm.h
Original file line number Diff line number Diff line change
Expand Up @@ -867,7 +867,7 @@ enum compound_dtor_id {
#endif
NR_COMPOUND_DTORS,
};
extern compound_page_dtor * const compound_page_dtors[];
extern compound_page_dtor * const compound_page_dtors[NR_COMPOUND_DTORS];

static inline void set_compound_page_dtor(struct page *page,
enum compound_dtor_id compound_dtor)
Expand Down
10 changes: 5 additions & 5 deletions mm/page_alloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -302,14 +302,14 @@ const char * const migratetype_names[MIGRATE_TYPES] = {
#endif
};

compound_page_dtor * const compound_page_dtors[] = {
NULL,
free_compound_page,
compound_page_dtor * const compound_page_dtors[NR_COMPOUND_DTORS] = {
[NULL_COMPOUND_DTOR] = NULL,
[COMPOUND_PAGE_DTOR] = free_compound_page,
#ifdef CONFIG_HUGETLB_PAGE
free_huge_page,
[HUGETLB_PAGE_DTOR] = free_huge_page,
#endif
#ifdef CONFIG_TRANSPARENT_HUGEPAGE
free_transhuge_page,
[TRANSHUGE_PAGE_DTOR] = free_transhuge_page,
#endif
};

Expand Down

0 comments on commit ae70edd

Please sign in to comment.