Skip to contentSkip to conversation

Fix shadowed variables in fs/binfmt_elf.c

PATCH In review WANG Cong 2 participants 3 messages Feb 15, 2008 – Feb 16, 2008

Subsystems (2)
lore
Share & tools
lore

WANG Cong

author
#0 lore raw

PATCH 1/1 Fix shadowed variables in fs/binfmt_elf.c

Fix these sparse warings:
fs/binfmt_elf.c:1749:29: warning: symbol 'tmp' shadows an earlier one fs/binfmt_elf.c:1734:28: originally declared here fs/binfmt_elf.c:2009:26: warning: symbol 'vma' shadows an earlier one fs/binfmt_elf.c:1892:24: originally declared here

---

fs/binfmt_elf.c +6 -6
index 41a958a..6562563 100644
@@ -1746,11 +1746,11 @@ static int fill_note_info(struct elfhdr *elf, int phdrs,
 		while_each_thread(g, p);
 		rcu_read_unlock();
 		list_for_each(t, &info->thread_list) {
-			struct elf_thread_status *tmp;
+			struct elf_thread_status *temp;
 			int sz;
 
-			tmp = list_entry(t, struct elf_thread_status, list);
-			sz = elf_dump_thread_status(signr, tmp);
+			temp = list_entry(t, struct elf_thread_status, list);
+			sz = elf_dump_thread_status(signr, temp);
 			info->thread_status_size += sz;
 		}
 	}
@@ -2006,10 +2006,10 @@ static int elf_core_dump(long signr, struct pt_regs *regs, struct file *file, un
 
 		for (addr = vma->vm_start; addr < end; addr += PAGE_SIZE) {
 			struct page *page;
-			struct vm_area_struct *vma;
+			struct vm_area_struct *tmp_vma;
 
 			if (get_user_pages(current, current->mm, addr, 1, 0, 1,
-						&page, &vma) <= 0) {
+						&page, &tmp_vma) <= 0) {
 				DUMP_SEEK(PAGE_SIZE);
 			} else {
 				if (page == ZERO_PAGE(0)) {
@@ -2019,7 +2019,7 @@ static int elf_core_dump(long signr, struct pt_regs *regs, struct file *file, un
 					}
 				} else {
 					void *kaddr;
-					flush_cache_page(vma, addr,
+					flush_cache_page(tmp_vma, addr,
 							 page_to_pfn(page));
 					kaddr = kmap(page);
 					if ((size += PAGE_SIZE) > limit ||
#1 lore raw
Quoted 19 lines · On Fri, 15 Feb 2008 21:58:02 +0800 (CST) WANG Cong <[email protected]>…

Fix these sparse warings:
fs/binfmt_elf.c:1749:29: warning: symbol 'tmp' shadows an earlier one fs/binfmt_elf.c:1734:28: originally declared here fs/binfmt_elf.c:2009:26: warning: symbol 'vma' shadows an earlier one fs/binfmt_elf.c:1892:24: originally declared here

---

fs/binfmt_elf.c +0 -1
index 41a958a..6562563 100644
@@ -1746,11 +1746,11 @@ static int fill_note_info(struct elfhdr *elf, int phdrs,
 		while_each_thread(g, p);
 		rcu_read_unlock();
 		list_for_each(t, &info->thread_list) {
-			struct elf_thread_status *tmp;

fs/binfmt_elf.c static int fill_note_info(struct elfhdr *elf, int phdrs, · line 1756

Quoted 10 lines
fs/binfmt_elf.c +3 -2
+			struct elf_thread_status *temp;
 			int sz;
 
-			tmp = list_entry(t, struct elf_thread_status, list);
-			sz = elf_dump_thread_status(signr, tmp);
+			temp = list_entry(t, struct elf_thread_status, list);
+			sz = elf_dump_thread_status(signr, temp);
 			info->thread_status_size += sz;
 		}
 	}

`tmp' is an awful identifier, and renaming it to "temp" hardly improves it. Please take any opportunity to fix this sort of thing.

I chose "ets" which is a bit weird but once one understand what it means, it makes the code much easier to follow.

Also used the same local for both loops. There seems little point in instantiating a second one.

fs/binfmt_elf.c renamed from fs/binfmt_elf.c~elf-fix-shadowed-variables-in-fs-binfmt_elfc +10 -11
diff -puN fs/binfmt_elf.c~elf-fix-shadowed-variables-in-fs-binfmt_elfc fs/binfmt_elf.c
@@ -1728,26 +1728,25 @@ static int fill_note_info(struct elfhdr 
 
 	info->thread_status_size = 0;
 	if (signr) {
-		struct elf_thread_status *tmp;
+		struct elf_thread_status *ets;
 		rcu_read_lock();
 		do_each_thread(g, p)
 			if (current->mm == p->mm && current != p) {
-				tmp = kzalloc(sizeof(*tmp), GFP_ATOMIC);
-				if (!tmp) {
+				ets = kzalloc(sizeof(*ets), GFP_ATOMIC);
+				if (!ets) {
 					rcu_read_unlock();
 					return 0;
 				}
-				tmp->thread = p;
-				list_add(&tmp->list, &info->thread_list);
+				ets->thread = p;
+				list_add(&ets->list, &info->thread_list);
 			}
 		while_each_thread(g, p);
 		rcu_read_unlock();
 		list_for_each(t, &info->thread_list) {
-			struct elf_thread_status *tmp;
 			int sz;
 
-			tmp = list_entry(t, struct elf_thread_status, list);
-			sz = elf_dump_thread_status(signr, tmp);
+			ets = list_entry(t, struct elf_thread_status, list);
+			sz = elf_dump_thread_status(signr, ets);
 			info->thread_status_size += sz;
 		}
 	}
@@ -2003,10 +2002,10 @@ static int elf_core_dump(long signr, str
 
 		for (addr = vma->vm_start; addr < end; addr += PAGE_SIZE) {
 			struct page *page;
-			struct vm_area_struct *vma;
+			struct vm_area_struct *tmp_vma;
 
 			if (get_user_pages(current, current->mm, addr, 1, 0, 1,
-						&page, &vma) <= 0) {
+						&page, &tmp_vma) <= 0) {
 				DUMP_SEEK(PAGE_SIZE);
 			} else {
 				if (page == ZERO_PAGE(0)) {
@@ -2016,7 +2015,7 @@ static int elf_core_dump(long signr, str
 					}
 				} else {
 					void *kaddr;
-					flush_cache_page(vma, addr,
+					flush_cache_page(tmp_vma, addr,
 							 page_to_pfn(page));
 					kaddr = kmap(page);
 					if ((size += PAGE_SIZE) > limit ||

_

author
#2 lore raw

From: Andrew Morton <[email protected]>
Subject: Re: [Patch] Fix shadowed variables in fs/binfmt_elf.c
Date: Fri, 15 Feb 2008 12:34:59 -0800
Message-ID: <[email protected]>

Quoted 36 lines
Quoted 19 lines · On Fri, 15 Feb 2008 21:58:02 +0800 (CST) WANG Cong <[email protected]>…

Fix these sparse warings:
fs/binfmt_elf.c:1749:29: warning: symbol 'tmp' shadows an earlier one fs/binfmt_elf.c:1734:28: originally declared here fs/binfmt_elf.c:2009:26: warning: symbol 'vma' shadows an earlier one fs/binfmt_elf.c:1892:24: originally declared here

---

fs/binfmt_elf.c +0 -1
index 41a958a..6562563 100644
@@ -1746,11 +1746,11 @@ static int fill_note_info(struct elfhdr *elf, int phdrs,
 		while_each_thread(g, p);
 		rcu_read_unlock();
 		list_for_each(t, &info->thread_list) {
-			struct elf_thread_status *tmp;

fs/binfmt_elf.c static int fill_note_info(struct elfhdr *elf, int phdrs, · line 1756

Quoted 10 lines
fs/binfmt_elf.c +3 -2
+			struct elf_thread_status *temp;
 			int sz;
 
-			tmp = list_entry(t, struct elf_thread_status, list);
-			sz = elf_dump_thread_status(signr, tmp);
+			temp = list_entry(t, struct elf_thread_status, list);
+			sz = elf_dump_thread_status(signr, temp);
 			info->thread_status_size += sz;
 		}
 	}

`tmp' is an awful identifier, and renaming it to "temp" hardly improves it. Please take any opportunity to fix this sort of thing.

Quoted 5 lines

I chose "ets" which is a bit weird but once one understand what it means, it makes the code much easier to follow.

Also used the same local for both loops. There seems little point in instantiating a second one.

I agree. The first 'tmp' you showed is really not good, 'ets' is better.

Thanks, Andrew!