Skip to contentSkip to conversation

Removing dead code

PATCH In review Christian Dietrich 2 participants 10 messages Aug 10, 2010

lore
Share & tools
lore
#0 lore raw

cover Removing dead code

Hi all!

As part of the VAMOS[0] research project at the University of
Erlangen we are looking at multiple integrity errors in linux' configuration system.

I've been running a check on the arch/frv sourcetree for
config Items not defined in Kconfig and found 4 such cases. Sourcecode blocks depending on these Items are not reachable from a vanilla kernel -- dead code. I've seen such dead blocks made on purpose e.g. while integrating new features into the kernel but generally they're just useless.

Each of the patches in this patchset removes on such dead
config Item, I'd be glad if you consider applying them. I've been doing deeper analysis of such issues before and can do so again but I'm not so sure they were fastly usefull.

I wasn't able to build a vanilla kernel allyesconfig, therefore these patches might break something. But because they are just removing dead code it is unlikely.

Another problem i encountered was CONFIG_PREEMPT, which isn't selectable in frv Kconfig because it doesn include kernel/Kconfig.preempt. But there ist plenty of evidence for me, that there is preemption support in frv.

Please keep me informed of this patch getting confirmed /
merged so we can keep track of it.

Regards

Christian Dietrich

[0] http://vamos1.informatik.uni-erlangen.de/

Christian Dietrich (4):
arch/frv: Removing dead RAMKERNEL config option arch/frv: Removing dead HEARTBEAT config option arch/frv: Removing dead NO_KERNEL_MSG config option arch/frv: Removing dead DEBUG_STACK_USAGE config option

 arch/frv/include/asm/bug.h         |    4 ----
 arch/frv/include/asm/thread_info.h |   11 -----------
 arch/frv/kernel/debug-stub.c       |    2 --
 arch/frv/kernel/time.c             |    6 ------
 arch/frv/mm/init.c                 |   17 -----------------
 5 files changed, 0 insertions(+), 40 deletions(-)
#1 lore raw

PATCH 1/4 arch/frv: Removing dead RAMKERNEL config option

CONFIG_RAMKERNEL doesn't exist in Kconfig, therefore removing all references to it from the source.

---
 arch/frv/mm/init.c |   17 -----------------
 1 files changed, 0 insertions(+), 17 deletions(-)
arch/frv/mm/init.c +0 -17
index ed64588..73586ad 100644
@@ -170,23 +170,6 @@ void __init mem_init(void)
  */
 void free_initmem(void)
 {
-#if defined(CONFIG_RAMKERNEL) && !defined(CONFIG_PROTECT_KERNEL)
-	unsigned long start, end, addr;
-
-	start = PAGE_ALIGN((unsigned long) &__init_begin);	/* round up */
-	end   = ((unsigned long) &__init_end) & PAGE_MASK;	/* round down */
-
-	/* next to check that the page we free is not a partial page */
-	for (addr = start; addr < end; addr += PAGE_SIZE) {
-		ClearPageReserved(virt_to_page(addr));
-		init_page_count(virt_to_page(addr));
-		free_page(addr);
-		totalram_pages++;
-	}
-
-	printk("Freeing unused kernel memory: %ldKiB freed (0x%lx - 0x%lx)\n",
-	       (end - start) >> 10, start, end);
-#endif
 } /* end free_initmem() */
 
 /*****************************************************************************/
Signature · 1 line
1.7.0.4
#2 lore raw

Re: [PATCH 1/4] arch/frv: Removing dead RAMKERNEL config option

Hi,

Quoted 16 lines · ext Christian Dietrich
arch/frv/mm/init.c +0 -8
index ed64588..73586ad 100644
@@ -170,23 +170,6 @@ void __init mem_init(void)
 */
 void free_initmem(void)
 {
-#if defined(CONFIG_RAMKERNEL) && !defined(CONFIG_PROTECT_KERNEL)
-	unsigned long start, end, addr;
-
-	start = PAGE_ALIGN((unsigned long) &__init_begin);	/* round up */
-	end   = ((unsigned long) &__init_end) & PAGE_MASK;	/* round down */
-
-	/* next to check that the page we free is not a partial page */
-	for (addr = start; addr < end; addr += PAGE_SIZE) {

arch/frv/mm/init.c void __init mem_init(void) · line 173

Quoted 10 lines
arch/frv/mm/init.c +0 -9
-		ClearPageReserved(virt_to_page(addr));
-		init_page_count(virt_to_page(addr));
-		free_page(addr);
-		totalram_pages++;
-	}
-
-	printk("Freeing unused kernel memory: %ldKiB freed (0x%lx - 0x%lx)\n",
-	       (end - start) >> 10, start, end);
-#endif
 } /* end free_initmem() */

and now you have an empty function... how about removing the function completely and it's uses ?

Signature · 3 lines
balbi

DefectiveByDesign.org
#3 lore raw

Re: [PATCH 1/4] arch/frv: Removing dead RAMKERNEL config option

Quoted 24 lines · Felipe Balbi

Hi,

Quoted 21 lines · ext Christian Dietrich
arch/frv/mm/init.c +0 -13
index ed64588..73586ad 100644
@@ -170,23 +170,6 @@ void __init mem_init(void)
 */
 void free_initmem(void)
 {
-#if defined(CONFIG_RAMKERNEL) && !defined(CONFIG_PROTECT_KERNEL)
-	unsigned long start, end, addr;
-
-	start = PAGE_ALIGN((unsigned long) &__init_begin);	/* round up */
-	end   = ((unsigned long) &__init_end) & PAGE_MASK;	/* round down */
-
-	/* next to check that the page we free is not a partial page */
-	for (addr = start; addr < end; addr += PAGE_SIZE) {
-		ClearPageReserved(virt_to_page(addr));
-		init_page_count(virt_to_page(addr));
-		free_page(addr);
-		totalram_pages++;
-	}
Quoted 8 lines

arch/frv/mm/init.c void __init mem_init(void) · line 173

Quoted 5 lines
arch/frv/mm/init.c +0 -4
-
-	printk("Freeing unused kernel memory: %ldKiB freed (0x%lx - 0x%lx)\n",
-	       (end - start) >> 10, start, end);
-#endif
 } /* end free_initmem() */

and now you have an empty function... how about removing the function completely and it's uses ?

If you take a look at init/main.c:826 free_initmem() is called. perhaps this can be resolved with a macro, but if anybody in the future wants to add some functionality there, he won't be happy after grepping.

greetz didi

Signature · 3 lines
(λ x . x x) (λ x . x x) -- See how beatiful the lambda is
No documentation is better than bad documentation
-- Das Ausdrucken dieser Mail wird urheberrechtlich verfolgt.
#4 lore raw

Re: [PATCH 1/4] arch/frv: Removing dead RAMKERNEL config option

Quoted 3 lines · ext Christian Dietrich

If you take a look at init/main.c:826 free_initmem() is called. perhaps this can be resolved with a macro, but if anybody in the future wants to add some functionality there, he won't be happy after grepping.

ok, sorry for that. Makes sense.

Signature · 3 lines
balbi

DefectiveByDesign.org
#5 lore raw

PATCH 2/4 arch/frv: Removing dead HEARTBEAT config option

In reply to Christian Dietrich

CONFIG_HEARTBEAT doesn't exist in Kconfig, therefore removing all references to it from the source.

---
 arch/frv/kernel/time.c |    6 ------
 1 files changed, 0 insertions(+), 6 deletions(-)
arch/frv/kernel/time.c +0 -6
index 0ddbbae..e86df6c 100644
@@ -66,12 +66,6 @@ static irqreturn_t timer_interrupt(int irq, void *dummy)
 
 	do_timer(1);
 
-#ifdef CONFIG_HEARTBEAT
-	static unsigned short n;
-	n++;
-	__set_LEDS(n);
-#endif /* CONFIG_HEARTBEAT */
-
 	write_sequnlock(&xtime_lock);
 
 	update_process_times(user_mode(get_irq_regs()));
Signature · 1 line
1.7.0.4
#6 lore raw

Re: [PATCH 2/4] arch/frv: Removing dead HEARTBEAT config option

Hi,

arch/frv/kernel/time.c static irqreturn_t timer_interrupt(int irq, void *dummy) · line 69

Quoted 9 lines · ext Christian Dietrich
arch/frv/kernel/time.c +0 -1
index 0ddbbae..e86df6c 100644
@@ -66,12 +66,6 @@ static irqreturn_t timer_interrupt(int irq, void *dummy)
 
 	do_timer(1);
 
-#ifdef CONFIG_HEARTBEAT

should you instead change to CONFIG_LEDS_TRIGGER_HEARTBEAT ?

Signature · 3 lines
balbi

DefectiveByDesign.org
#7 lore raw

Re: [PATCH 2/4] arch/frv: Removing dead HEARTBEAT config option

Quoted 7 lines · Felipe Balbi
Quoted 6 lines · ext Christian Dietrich
arch/frv/kernel/time.c +0 -0
index 0ddbbae..e86df6c 100644
@@ -66,12 +66,6 @@ static irqreturn_t timer_interrupt(int irq, void *dummy)
 
Quoted 5 lines

arch/frv/kernel/time.c static irqreturn_t timer_interrupt(int irq, void *dummy) · line 69

Quoted 3 lines
arch/frv/kernel/time.c +0 -1
 	do_timer(1);
 
-#ifdef CONFIG_HEARTBEAT

should you instead change to CONFIG_LEDS_TRIGGER_HEARTBEAT ?

I didn't know of this config option, but i think this would be better. I attached a patch for it.

greetz didi

Signature · 3 lines
(λ x . x x) (λ x . x x) -- See how beatiful the lambda is
No documentation is better than bad documentation
-- Das Ausdrucken dieser Mail wird urheberrechtlich verfolgt.
Quoted 1 line

From 36cfe416d7b099097ed3f37bb62134c674fc68ce Mon Sep 17 00:00:00 2001

From: Christian Dietrich <[email protected]>
Date: Tue, 10 Aug 2010 13:02:30 +0200
Subject: [PATCH] arch/frv: Rename dead HEARTBEAT config option

Because CONFIG_HEARTBEAT isn't defined for the frv arch, this block would be dead. As suggested by Felipe Balbi CONFIG_HEARTBEAT was replaced by CONFIG_LEDS_TRIGGER_HEARTBEAT.

---
 arch/frv/kernel/time.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
arch/frv/kernel/time.c +2 -2
index 0ddbbae..d8fff7e 100644
@@ -66,11 +66,11 @@ static irqreturn_t timer_interrupt(int irq, void *dummy)
 
 	do_timer(1);
 
-#ifdef CONFIG_HEARTBEAT
+#ifdef CONFIG_LEDS_TRIGGER_HEARTBEAT
 	static unsigned short n;
 	n++;
 	__set_LEDS(n);
-#endif /* CONFIG_HEARTBEAT */
+#endif /* CONFIG_LEDS_TRIGGER_HEARTBEAT */
 
 	write_sequnlock(&xtime_lock);
 
Signature · 1 line
1.7.0.4
#8 lore raw

PATCH 3/4 arch/frv: Removing dead NO_KERNEL_MSG config option

In reply to Christian Dietrich

CONFIG_NO_KERNEL_MSG doesn't exist in Kconfig, therefore removing all references to it from the source.

---
 arch/frv/include/asm/bug.h   |    4 ----
 arch/frv/kernel/debug-stub.c |    2 --
 2 files changed, 0 insertions(+), 6 deletions(-)
arch/frv/include/asm/bug.h +0 -4
index 2e05450..ea6e986 100644
@@ -19,12 +19,8 @@
  */
 extern asmlinkage void __debug_bug_trap(int signr);
 
-#ifdef CONFIG_NO_KERNEL_MSG
-#define	_debug_bug_printk()
-#else
 extern void __debug_bug_printk(const char *file, unsigned line);
 #define	_debug_bug_printk() __debug_bug_printk(__FILE__, __LINE__)
-#endif
 
 #define _debug_bug_trap(signr)			\
 do {						\
arch/frv/kernel/debug-stub.c +0 -2
index 2845139..8752253 100644
@@ -250,10 +250,8 @@ int __init console_get_baud(void)
 /*
  * display BUG() info
  */
-#ifndef CONFIG_NO_KERNEL_MSG
 void __debug_bug_printk(const char *file, unsigned line)
 {
 	printk("kernel BUG at %s:%d!\n", file, line);
 
 } /* end __debug_bug_printk() */
-#endif
Signature · 1 line
1.7.0.4
#9 lore raw

PATCH 4/4 arch/frv: Removing dead DEBUG_STACK_USAGE config option

In reply to Christian Dietrich

CONFIG_DEBUG_STACK_USAGE doesn't exist in Kconfig, therefore removing all references to it from the source.

---
 arch/frv/include/asm/thread_info.h |   11 -----------
 1 files changed, 0 insertions(+), 11 deletions(-)
arch/frv/include/asm/thread_info.h +0 -11
index 11f33ea..89ab701 100644
@@ -83,18 +83,7 @@ register struct thread_info *__current_thread_info asm("gr15");
 #define __HAVE_ARCH_THREAD_INFO_ALLOCATOR
 
 /* thread information allocation */
-#ifdef CONFIG_DEBUG_STACK_USAGE
-#define alloc_thread_info(tsk)					\
-	({							\
-		struct thread_info *ret;			\
-								\
-		ret = kzalloc(THREAD_SIZE, GFP_KERNEL);		\
-								\
-		ret;						\
-	})
-#else
 #define alloc_thread_info(tsk)	kmalloc(THREAD_SIZE, GFP_KERNEL)
-#endif
 
 #define free_thread_info(info)	kfree(info)
 
Signature · 1 line
1.7.0.4