Skip to content

Commit a94032b

Browse files
shakeelbakpm00
authored andcommitted
memcg: use proper type for mod_memcg_state
The memcg stats update functions can take arbitrary integer but the only input which make sense is enum memcg_stat_item and we don't want these functions to be called with arbitrary integer, so replace the parameter type with enum memcg_stat_item and compiler will be able to warn if memcg stat update functions are called with incorrect index value. Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: Shakeel Butt <[email protected]> Reviewed-by: T.J. Mercier <[email protected]> Reviewed-by: Roman Gushchin <[email protected]> Cc: Johannes Weiner <[email protected]> Cc: Michal Hocko <[email protected]> Cc: Muchun Song <[email protected]> Cc: Yosry Ahmed <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent acb5fe2 commit a94032b

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

include/linux/memcontrol.h

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -974,7 +974,8 @@ void mem_cgroup_print_oom_group(struct mem_cgroup *memcg);
974974
void folio_memcg_lock(struct folio *folio);
975975
void folio_memcg_unlock(struct folio *folio);
976976

977-
void __mod_memcg_state(struct mem_cgroup *memcg, int idx, int val);
977+
void __mod_memcg_state(struct mem_cgroup *memcg, enum memcg_stat_item idx,
978+
int val);
978979

979980
/* try to stablize folio_memcg() for all the pages in a memcg */
980981
static inline bool mem_cgroup_trylock_pages(struct mem_cgroup *memcg)
@@ -995,7 +996,7 @@ static inline void mem_cgroup_unlock_pages(void)
995996

996997
/* idx can be of type enum memcg_stat_item or node_stat_item */
997998
static inline void mod_memcg_state(struct mem_cgroup *memcg,
998-
int idx, int val)
999+
enum memcg_stat_item idx, int val)
9991000
{
10001001
unsigned long flags;
10011002

@@ -1005,7 +1006,7 @@ static inline void mod_memcg_state(struct mem_cgroup *memcg,
10051006
}
10061007

10071008
static inline void mod_memcg_page_state(struct page *page,
1008-
int idx, int val)
1009+
enum memcg_stat_item idx, int val)
10091010
{
10101011
struct mem_cgroup *memcg;
10111012

@@ -1491,19 +1492,19 @@ static inline void mem_cgroup_print_oom_group(struct mem_cgroup *memcg)
14911492
}
14921493

14931494
static inline void __mod_memcg_state(struct mem_cgroup *memcg,
1494-
int idx,
1495+
enum memcg_stat_item idx,
14951496
int nr)
14961497
{
14971498
}
14981499

14991500
static inline void mod_memcg_state(struct mem_cgroup *memcg,
1500-
int idx,
1501+
enum memcg_stat_item idx,
15011502
int nr)
15021503
{
15031504
}
15041505

15051506
static inline void mod_memcg_page_state(struct page *page,
1506-
int idx, int val)
1507+
enum memcg_stat_item idx, int val)
15071508
{
15081509
}
15091510

mm/memcontrol.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -955,7 +955,8 @@ static int memcg_state_val_in_pages(int idx, int val)
955955
* @idx: the stat item - can be enum memcg_stat_item or enum node_stat_item
956956
* @val: delta to add to the counter, can be negative
957957
*/
958-
void __mod_memcg_state(struct mem_cgroup *memcg, int idx, int val)
958+
void __mod_memcg_state(struct mem_cgroup *memcg, enum memcg_stat_item idx,
959+
int val)
959960
{
960961
int i = memcg_stats_index(idx);
961962

0 commit comments

Comments
 (0)