Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

KAMEZAWA Hiroyuki and committed by
Linus Torvalds
56039efa 6c191cd0

+9 -5
+6 -2
mm/memcontrol.c
··· 2475 2475 2476 2476 /* shmem */ 2477 2477 if (PageSwapCache(page)) { 2478 - struct mem_cgroup *mem = NULL; 2478 + struct mem_cgroup *mem; 2479 2479 2480 2480 ret = mem_cgroup_try_charge_swapin(mm, page, gfp_mask, &mem); 2481 2481 if (!ret) ··· 2500 2500 { 2501 2501 struct mem_cgroup *mem; 2502 2502 int ret; 2503 + 2504 + *ptr = NULL; 2503 2505 2504 2506 if (mem_cgroup_disabled()) 2505 2507 return 0; ··· 2918 2916 enum charge_type ctype; 2919 2917 int ret = 0; 2920 2918 2919 + *ptr = NULL; 2920 + 2921 2921 VM_BUG_ON(PageTransHuge(page)); 2922 2922 if (mem_cgroup_disabled()) 2923 2923 return 0; ··· 3062 3058 struct mm_struct *mm, 3063 3059 gfp_t gfp_mask) 3064 3060 { 3065 - struct mem_cgroup *mem = NULL; 3061 + struct mem_cgroup *mem; 3066 3062 int ret; 3067 3063 3068 3064 if (mem_cgroup_disabled())
+1 -1
mm/memory.c
··· 2767 2767 swp_entry_t entry; 2768 2768 pte_t pte; 2769 2769 int locked; 2770 - struct mem_cgroup *ptr = NULL; 2770 + struct mem_cgroup *ptr; 2771 2771 int exclusive = 0; 2772 2772 int ret = 0; 2773 2773
+1 -1
mm/migrate.c
··· 633 633 struct page *newpage = get_new_page(page, private, &result); 634 634 int remap_swapcache = 1; 635 635 int charge = 0; 636 - struct mem_cgroup *mem = NULL; 636 + struct mem_cgroup *mem; 637 637 struct anon_vma *anon_vma = NULL; 638 638 639 639 if (!newpage)
+1 -1
mm/swapfile.c
··· 880 880 static int unuse_pte(struct vm_area_struct *vma, pmd_t *pmd, 881 881 unsigned long addr, swp_entry_t entry, struct page *page) 882 882 { 883 - struct mem_cgroup *ptr = NULL; 883 + struct mem_cgroup *ptr; 884 884 spinlock_t *ptl; 885 885 pte_t *pte; 886 886 int ret = 1;