Skip to content

Commit 56039ef

Browse files
hkamezawatorvalds
authored andcommitted
memcg: fix ugly initialization of return value is in caller
Remove initialization of vaiable in caller of memory cgroup function. Actually, it's return value of memcg function but it's initialized in caller. Some memory cgroup uses following style to bring the result of start function to the end function for avoiding races. mem_cgroup_start_A(&(*ptr)) /* Something very complicated can happen here. */ mem_cgroup_end_A(*ptr) In some calls, *ptr should be initialized to NULL be caller. But it's ugly. This patch fixes that *ptr is initialized by _start function. Signed-off-by: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com> Acked-by: Johannes Weiner <hannes@cmpxchg.org> Acked-by: Daisuke Nishimura <nishimura@mxp.nes.nec.co.jp> Cc: Balbir Singh <balbir@linux.vnet.ibm.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 6c191cd commit 56039ef

4 files changed

Lines changed: 9 additions & 5 deletions

File tree

‎mm/memcontrol.c‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2475,7 +2475,7 @@ int mem_cgroup_cache_charge(struct page *page, struct mm_struct *mm,
24752475

24762476
/* shmem */
24772477
if (PageSwapCache(page)) {
2478-
struct mem_cgroup *mem = NULL;
2478+
struct mem_cgroup *mem;
24792479

24802480
ret = mem_cgroup_try_charge_swapin(mm, page, gfp_mask, &mem);
24812481
if (!ret)
@@ -2501,6 +2501,8 @@ int mem_cgroup_try_charge_swapin(struct mm_struct *mm,
25012501
struct mem_cgroup *mem;
25022502
int ret;
25032503

2504+
*ptr = NULL;
2505+
25042506
if (mem_cgroup_disabled())
25052507
return 0;
25062508

@@ -2916,6 +2918,8 @@ int mem_cgroup_prepare_migration(struct page *page,
29162918
enum charge_type ctype;
29172919
int ret = 0;
29182920

2921+
*ptr = NULL;
2922+
29192923
VM_BUG_ON(PageTransHuge(page));
29202924
if (mem_cgroup_disabled())
29212925
return 0;
@@ -3058,7 +3062,7 @@ int mem_cgroup_shmem_charge_fallback(struct page *page,
30583062
struct mm_struct *mm,
30593063
gfp_t gfp_mask)
30603064
{
3061-
struct mem_cgroup *mem = NULL;
3065+
struct mem_cgroup *mem;
30623066
int ret;
30633067

30643068
if (mem_cgroup_disabled())

‎mm/memory.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2767,7 +2767,7 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
27672767
swp_entry_t entry;
27682768
pte_t pte;
27692769
int locked;
2770-
struct mem_cgroup *ptr = NULL;
2770+
struct mem_cgroup *ptr;
27712771
int exclusive = 0;
27722772
int ret = 0;
27732773

‎mm/migrate.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -633,7 +633,7 @@ static int unmap_and_move(new_page_t get_new_page, unsigned long private,
633633
struct page *newpage = get_new_page(page, private, &result);
634634
int remap_swapcache = 1;
635635
int charge = 0;
636-
struct mem_cgroup *mem = NULL;
636+
struct mem_cgroup *mem;
637637
struct anon_vma *anon_vma = NULL;
638638

639639
if (!newpage)

‎mm/swapfile.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -880,7 +880,7 @@ unsigned int count_swap_pages(int type, int free)
880880
static int unuse_pte(struct vm_area_struct *vma, pmd_t *pmd,
881881
unsigned long addr, swp_entry_t entry, struct page *page)
882882
{
883-
struct mem_cgroup *ptr = NULL;
883+
struct mem_cgroup *ptr;
884884
spinlock_t *ptl;
885885
pte_t *pte;
886886
int ret = 1;

0 commit comments

Comments
 (0)