Skip to contentSkip to conversation

Check return code in mm/vmscan.c

PATCH In review Eugene Teo 3 participants 10 messages Jan 3, 2004 – Feb 16, 2004

Subsystems (4)
lore
Share & tools
lore

Eugene Teo

author
#0 lore raw

PATCH 1/1 Check return code in mm/vmscan.c

http://www.anomalistic.org/patches/vmscan-check-ret-kernel_thread-fix-2.6.1-rc1-mm1.patch

mm/vmscan.c +8 -2
diff -Naur -X /home/amnesia/w/dontdiff 2.6.1-rc1-mm1/mm/vmscan.c 2.6.1-rc1-mm1-fix/mm/vmscan.c
@@ -1093,10 +1093,16 @@
 
 static int __init kswapd_init(void)
 {
+	int ret;
 	pg_data_t *pgdat;
 	swap_setup();
-	for_each_pgdat(pgdat)
-		kernel_thread(kswapd, pgdat, CLONE_KERNEL);
+	for_each_pgdat(pgdat) {
+		ret = kernel_thread(kswapd, pgdat, CLONE_KERNEL);
+		if (ret < 0) {
+			printk("%s: unable to start kernel thread\n", __FUNCTION__);
+			return ret;
+		}
+	}
 	total_memory = nr_free_pagecache_pages();
 	return 0;
 }
Signature · 8 lines
Eugene TEO   <[email protected]>   <http://www.anomalistic.org/>
1024D/14A0DDE5 print D851 4574 E357 469C D308  A01E 7321 A38A 14A0 DDE5
main(i) { putchar(182623909 >> (i-1) * 5&31|!!(i<7)<<6) && main(++i); }

_______________________________________________
Kernel-janitors mailing list
[email protected]
http://lists.osdl.org/mailman/listinfo/kernel-janitors
author
#1 lore raw

PATCH 1/1 Check return code in

http://www.anomalistic.org/patches/setup-check-ret-alloc_bootmem_low-fix-2.6.1-rc1-mm1.patch

arch/i386/kernel/setup.c +6 -0
diff -Naur -X /home/amnesia/w/dontdiff 2.6.1-rc1-mm1/arch/i386/kernel/setup.c 2.6.1-rc1-mm1-fix/arch/i386/kernel/setup.c
@@ -17,6 +17,8 @@
  *  Provisions for empty E820 memory regions (reported by certain BIOSes).
  *  Alex Achenbach <[email protected]>, December 2002.
  *
+ *  Check the return value of alloc_bootmem_low.
+ *  Eugene Teo <[email protected]>, January 2004.
  */
 
 /*
@@ -875,6 +877,10 @@
 		if (e820.map[i].addr + e820.map[i].size > 0x100000000ULL)
 			continue;
 		res = alloc_bootmem_low(sizeof(struct resource));
+		if (!res) {
+			printk(KERN_ERR "Cannot allocate lowmem\n");
+			return;
+		}
 		switch (e820.map[i].type) {
 		case E820_RAM:	res->name = "System RAM"; break;
 		case E820_ACPI:	res->name = "ACPI Tables"; break;
Signature · 8 lines
Eugene TEO   <[email protected]>   <http://www.anomalistic.org/>
1024D/14A0DDE5 print D851 4574 E357 469C D308  A01E 7321 A38A 14A0 DDE5
main(i) { putchar(182623909 >> (i-1) * 5&31|!!(i<7)<<6) && main(++i); }

_______________________________________________
Kernel-janitors mailing list
[email protected]
http://lists.osdl.org/mailman/listinfo/kernel-janitors
author
#2 lore raw

PATCH 1/1 Check return code in mm/pdflush.c

In reply to Eugene Teo

http://www.anomalistic.org/patches/pdflush-check-ret-kernel_thread-fix-2.6.1-rc1-mm1.patch

mm/pdflush.c +5 -1
diff -Naur -X /home/amnesia/w/dontdiff 2.6.1-rc1-mm1/mm/pdflush.c 2.6.1-rc1-mm1-fix/mm/pdflush.c
@@ -223,7 +223,11 @@
 
 static void start_one_pdflush_thread(void)
 {
-	kernel_thread(pdflush, NULL, CLONE_KERNEL);
+	int ret;
+	
+	ret = kernel_thread(pdflush, NULL, CLONE_KERNEL);
+	if (ret < 0) 
+		printk("%s: unable to start kernel thread\n", __FUNCTION__);
 }
 
 static int __init pdflush_init(void)
Signature · 8 lines
Eugene TEO   <[email protected]>   <http://www.anomalistic.org/>
1024D/14A0DDE5 print D851 4574 E357 469C D308  A01E 7321 A38A 14A0 DDE5
main(i) { putchar(182623909 >> (i-1) * 5&31|!!(i<7)<<6) && main(++i); }

_______________________________________________
Kernel-janitors mailing list
[email protected]
http://lists.osdl.org/mailman/listinfo/kernel-janitors
#3 lore raw
In reply to Eugene Teo
Quoted 14 lines · Eugene Teo

http://www.anomalistic.org/patches/vmscan-check-ret-kernel_thread-fix-2.6.1-rc1-mm1.patch

diff -Naur -X /home/amnesia/w/dontdiff 2.6.1-rc1-mm1/mm/vmscan.c 2.6.1-rc1-mm1-fix/mm/vmscan.c

mm/vmscan.c +1 -2
@@ -1093,10 +1093,16 @@
 
 static int __init kswapd_init(void)
 {
+	int ret;
 	pg_data_t *pgdat;
 	swap_setup();
-	for_each_pgdat(pgdat)
-		kernel_thread(kswapd, pgdat, CLONE_KERNEL);

mm/vmscan.c line 1108

Quoted 10 lines
mm/vmscan.c +7 -0
+	for_each_pgdat(pgdat) {
+		ret = kernel_thread(kswapd, pgdat, CLONE_KERNEL);
+		if (ret < 0) {
+			printk("%s: unable to start kernel thread\n", __FUNCTION__);
+			return ret;
+		}
+	}
 	total_memory = nr_free_pagecache_pages();
 	return 0;
 }

If your new code is triggered, we've just failed to set up total_memory. I expect the system to behave very oddly after this ;-)

Signature · 10 lines
"Next the statesmen will invent cheap lies, putting the blame upon 
the nation that is attacked, and every man will be glad of those
conscience-soothing falsities, and will diligently study them, and refuse
to examine any refutations of them; and thus he will by and by convince 
himself that the war is just, and will thank God for the better sleep 
he enjoys after this process of grotesque self-deception." -- Mark Twain
_______________________________________________
Kernel-janitors mailing list
[email protected]
http://lists.osdl.org/mailman/listinfo/kernel-janitors
#6 lore raw

Re: [Kernel-janitors] [PATCH] Check return code in

In reply to Eugene Teo
Quoted 6 lines · Eugene Teo

http://www.anomalistic.org/patches/setup-check-ret-alloc_bootmem_low-fix-2.6.1-rc1-mm1.patch

diff -Naur -X /home/amnesia/w/dontdiff 2.6.1-rc1-mm1/arch/i386/kernel/setup.c 2.6.1-rc1-mm1-fix/arch/i386/kernel/setup.c

arch/i386/kernel/setup.c line 886

Quoted 10 lines
arch/i386/kernel/setup.c +4 -0
@@ -875,6 +877,10 @@
 		if (e820.map[i].addr + e820.map[i].size > 0x100000000ULL)
 			continue;
 		res = alloc_bootmem_low(sizeof(struct resource));
+		if (!res) {
+			printk(KERN_ERR "Cannot allocate lowmem\n");
+			return;
+		}
 		switch (e820.map[i].type) {
 		case E820_RAM:	res->name = "System RAM"; break;
 		case E820_ACPI:	res->name = "ACPI Tables"; break;

I'd rather panic() at this point, otherwise we're going to start allocating areas twice and have some really unexplainable crashes. say something like ... panic("Insufficient memory to boot\n");

Signature · 10 lines
"Next the statesmen will invent cheap lies, putting the blame upon 
the nation that is attacked, and every man will be glad of those
conscience-soothing falsities, and will diligently study them, and refuse
to examine any refutations of them; and thus he will by and by convince 
himself that the war is just, and will thank God for the better sleep 
he enjoys after this process of grotesque self-deception." -- Mark Twain
_______________________________________________
Kernel-janitors mailing list
[email protected]
http://lists.osdl.org/mailman/listinfo/kernel-janitors
author
#7 lore raw

Re: [Kernel-janitors] [PATCH] Check return code in

In reply to Eugene Teo

<quote sender="Matthew Wilcox">

Quoted 4 lines · Eugene Teo
Quoted 3 lines

http://www.anomalistic.org/patches/setup-check-ret-alloc_bootmem_low-fix-2.6.1-rc1-mm1.patch

diff -Naur -X /home/amnesia/w/dontdiff 2.6.1-rc1-mm1/arch/i386/kernel/setup.c 2.6.1-rc1-mm1-fix/arch/i386/kernel/setup.c

[snip]

Quoted 3 lines

I'd rather panic() at this point, otherwise we're going to start allocating areas twice and have some really unexplainable crashes. say something like ... panic("Insufficient memory to boot\n");

Hehe, I can't imagine how nasty it would be if we didn't panic :)

http://www.anomalistic.org/patches/setup-check-ret-alloc_bootmem_low-fix-2.6.1-rc1-mm1.patch

arch/i386/kernel/setup.c +2 -0
diff -Naur -X /home/amnesia/w/dontdiff 2.6.1-rc1-mm1/arch/i386/kernel/setup.c 2.6.1-rc1-mm1-fix/arch/i386/kernel/setup.c
@@ -875,6 +875,8 @@
 		if (e820.map[i].addr + e820.map[i].size > 0x100000000ULL)
 			continue;
 		res = alloc_bootmem_low(sizeof(struct resource));
+		if (!res) 
+			panic("Insufficient memory to boot\n");
 		switch (e820.map[i].type) {
 		case E820_RAM:	res->name = "System RAM"; break;
 		case E820_ACPI:	res->name = "ACPI Tables"; break;
Signature · 8 lines
Eugene TEO   <[email protected]>   <http://www.anomalistic.org/>
1024D/14A0DDE5 print D851 4574 E357 469C D308  A01E 7321 A38A 14A0 DDE5
main(i) { putchar(182623909 >> (i-1) * 5&31|!!(i<7)<<6) && main(++i); }

_______________________________________________
Kernel-janitors mailing list
[email protected]
http://lists.osdl.org/mailman/listinfo/kernel-janitors
author
#4 lore raw
In reply to Matthew Wilcox

<quote sender="Matthew Wilcox">

Quoted 20 lines · Eugene Teo
Quoted 19 lines

http://www.anomalistic.org/patches/vmscan-check-ret-kernel_thread-fix-2.6.1-rc1-mm1.patch

diff -Naur -X /home/amnesia/w/dontdiff 2.6.1-rc1-mm1/mm/vmscan.c 2.6.1-rc1-mm1-fix/mm/vmscan.c

mm/vmscan.c +6 -2
@@ -1093,10 +1093,16 @@
 
 static int __init kswapd_init(void)
 {
+	int ret;
 	pg_data_t *pgdat;
 	swap_setup();
-	for_each_pgdat(pgdat)
-		kernel_thread(kswapd, pgdat, CLONE_KERNEL);
+	for_each_pgdat(pgdat) {
+		ret = kernel_thread(kswapd, pgdat, CLONE_KERNEL);
+		if (ret < 0) {
+			printk("%s: unable to start kernel thread\n", __FUNCTION__);
+			return ret;
Quoted 8 lines

mm/vmscan.c line 1108

Quoted 5 lines
mm/vmscan.c +2 -0
+		}
+	}
 	total_memory = nr_free_pagecache_pages();
 	return 0;
 }

If your new code is triggered, we've just failed to set up total_memory. I expect the system to behave very oddly after this ;-)

a panic call seems to be more appropriate :)

Here is the new fix. Patch compiles, and tested.

http://www.anomalistic.org/patches/vmscan-check-ret-kernel_thread-fix-2.6.1-rc1-mm1.patch

mm/vmscan.c +6 -2
diff -Naur -X /home/amnesia/w/dontdiff 2.6.1-rc1-mm1/mm/vmscan.c 2.6.1-rc1-mm1-fix/mm/vmscan.c
@@ -1093,10 +1093,14 @@
 
 static int __init kswapd_init(void)
 {
+	int ret;
 	pg_data_t *pgdat;
 	swap_setup();
-	for_each_pgdat(pgdat)
-		kernel_thread(kswapd, pgdat, CLONE_KERNEL);
+	for_each_pgdat(pgdat) {
+		ret = kernel_thread(kswapd, pgdat, CLONE_KERNEL);
+		if (ret < 0)
+			panic("%s: unable to initialise kswapd\n", __FUNCTION__);
+	}
 	total_memory = nr_free_pagecache_pages();
 	return 0;
 }
Signature · 8 lines
Eugene TEO   <[email protected]>   <http://www.anomalistic.org/>
1024D/14A0DDE5 print D851 4574 E357 469C D308  A01E 7321 A38A 14A0 DDE5
main(i) { putchar(182623909 >> (i-1) * 5&31|!!(i<7)<<6) && main(++i); }

_______________________________________________
Kernel-janitors mailing list
[email protected]
http://lists.osdl.org/mailman/listinfo/kernel-janitors
#8 lore raw

Re: [Kernel-janitors] [PATCH] Check return code in mm/pdflush.c

In reply to Eugene Teo

On Sat, 3 Jan 2004 21:26:56 +0800 Eugene Teo <[email protected]> wrote:

| http://www.anomalistic.org/patches/pdflush-check-ret-kernel_thread-fix-2.6.1-rc1-mm1.patch
| 
| diff -Naur -X /home/amnesia/w/dontdiff 2.6.1-rc1-mm1/mm/pdflush.c 2.6.1-rc1-mm1-fix/mm/pdflush.c
| --- 2.6.1-rc1-mm1/mm/pdflush.c	2004-01-03 17:58:11.000000000 +0800
| +++ 2.6.1-rc1-mm1-fix/mm/pdflush.c	2004-01-03 20:25:30.000000000 +0800
| @@ -223,7 +223,11 @@
|  
|  static void start_one_pdflush_thread(void)
|  {
| -	kernel_thread(pdflush, NULL, CLONE_KERNEL);
| +	int ret;
| +	
| +	ret = kernel_thread(pdflush, NULL, CLONE_KERNEL);
| +	if (ret < 0) 
| +		printk("%s: unable to start kernel thread\n", __FUNCTION__);

This patch adds trailing whitespace (on the "if" line). Please be more careful about that -- we don't want that. I fixed this one.

I run a simple script that searches for gotchas like this:
grep -nH "^+.*[ ]$" $1 | more

(that's SPACE and TAB inside the square brackets)

--
~Randy
MOTD: Always include version info.
_______________________________________________
Kernel-janitors mailing list
[email protected]
http://lists.osdl.org/mailman/listinfo/kernel-janitors

author
#9 lore raw

Re: [Kernel-janitors] [PATCH] Check return code in mm/pdflush.c

In reply to Eugene Teo

<quote sender="Randy.Dunlap">

Quoted 18 lines · On Sat, 3 Jan 2004 21:26:56 +0800 Eugene Teo <[email protected]> wrote:
| http://www.anomalistic.org/patches/pdflush-check-ret-kernel_thread-fix-2.6.1-rc1-mm1.patch
| 
| diff -Naur -X /home/amnesia/w/dontdiff 2.6.1-rc1-mm1/mm/pdflush.c 2.6.1-rc1-mm1-fix/mm/pdflush.c
| --- 2.6.1-rc1-mm1/mm/pdflush.c	2004-01-03 17:58:11.000000000 +0800
| +++ 2.6.1-rc1-mm1-fix/mm/pdflush.c	2004-01-03 20:25:30.000000000 +0800
| @@ -223,7 +223,11 @@
|  
|  static void start_one_pdflush_thread(void)
|  {
| -	kernel_thread(pdflush, NULL, CLONE_KERNEL);
| +	int ret;
| +	
| +	ret = kernel_thread(pdflush, NULL, CLONE_KERNEL);
| +	if (ret < 0) 
| +		printk("%s: unable to start kernel thread\n", __FUNCTION__);
Quoted 8 lines

This patch adds trailing whitespace (on the "if" line). Please be more careful about that -- we don't want that. I fixed this one.

I run a simple script that searches for gotchas like this:
grep -nH "^+.*[ ]$" $1 | more

(that's SPACE and TAB inside the square brackets)

Useful regexp. Will be careful.

Eugene

Quoted 5 lines

--
~Randy
MOTD: Always include version info.

Signature · 8 lines
Eugene TEO   <[email protected]>   <http://www.anomalistic.org/>
1024D/14A0DDE5 print D851 4574 E357 469C D308  A01E 7321 A38A 14A0 DDE5
main(i) { putchar(182623909 >> (i-1) * 5&31|!!(i<7)<<6) && main(++i); }

_______________________________________________
Kernel-janitors mailing list
[email protected]
http://lists.osdl.org/mailman/listinfo/kernel-janitors
#5 lore raw
In reply to Eugene Teo

On Sun, 4 Jan 2004 13:11:26 +0800 Eugene Teo <[email protected]> wrote:

| <quote sender="Matthew Wilcox">
| > On Sat, Jan 03, 2004 at 09:25:24PM +0800, Eugene Teo wrote:
| > > http://www.anomalistic.org/patches/vmscan-check-ret-kernel_thread-fix-2.6.1-rc1-mm1.patch
| > > 
| > > diff -Naur -X /home/amnesia/w/dontdiff 2.6.1-rc1-mm1/mm/vmscan.c 2.6.1-rc1-mm1-fix/mm/vmscan.c
| > > --- 2.6.1-rc1-mm1/mm/vmscan.c	2004-01-03 20:33:39.000000000 +0800
| > > +++ 2.6.1-rc1-mm1-fix/mm/vmscan.c	2004-01-03 21:16:30.000000000 +0800
| > > @@ -1093,10 +1093,16 @@
| > >  
| > >  static int __init kswapd_init(void)
| > >  {
| > > +	int ret;
| > >  	pg_data_t *pgdat;
| > >  	swap_setup();
| > > -	for_each_pgdat(pgdat)
| > > -		kernel_thread(kswapd, pgdat, CLONE_KERNEL);
| > > +	for_each_pgdat(pgdat) {
| > > +		ret = kernel_thread(kswapd, pgdat, CLONE_KERNEL);
| > > +		if (ret < 0) {
| > > +			printk("%s: unable to start kernel thread\n", __FUNCTION__);
| > > +			return ret;
| > > +		}
| > > +	}
| > >  	total_memory = nr_free_pagecache_pages();
| > >  	return 0;
| > >  }
| > 
| > If your new code is triggered, we've just failed to set up total_memory.
| > I expect the system to behave very oddly after this ;-)
| 
| a panic call seems to be more appropriate :)
| 
| Here is the new fix. Patch compiles, and tested.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Eugene, patch is tested how? What do you mean by "tested"? In what conditions?

| http://www.anomalistic.org/patches/vmscan-check-ret-kernel_thread-fix-2.6.1-rc1-mm1.patch
| 
| diff -Naur -X /home/amnesia/w/dontdiff 2.6.1-rc1-mm1/mm/vmscan.c 2.6.1-rc1-mm1-fix/mm/vmscan.c
| --- 2.6.1-rc1-mm1/mm/vmscan.c	2004-01-04 10:29:24.000000000 +0800
| +++ 2.6.1-rc1-mm1-fix/mm/vmscan.c	2004-01-04 13:04:52.000000000 +0800
| @@ -1093,10 +1093,14 @@
|  
|  static int __init kswapd_init(void)
|  {
| +	int ret;
|  	pg_data_t *pgdat;
|  	swap_setup();
| -	for_each_pgdat(pgdat)
| -		kernel_thread(kswapd, pgdat, CLONE_KERNEL);
| +	for_each_pgdat(pgdat) {
| +		ret = kernel_thread(kswapd, pgdat, CLONE_KERNEL);
| +		if (ret < 0)
| +			panic("%s: unable to initialise kswapd\n", __FUNCTION__);
| +	}
|  	total_memory = nr_free_pagecache_pages();
|  	return 0;
|  }
| 

--
~Randy
kernel-janitors project: http://janitor.kernelnewbies.org/
_______________________________________________
Kernel-janitors mailing list [email protected]
http://lists.osdl.org/mailman/listinfo/kernel-janitors