Subject: [PATCH] Reiserfs commit default fix
From: Bart Samwel <[email-masked]>
To: Andrew Morton <[email-masked]>
Cc: Micha Feigin <[email-masked]>
Date: Mon, 26 Apr 2004 13:28:52 +0200

Hi Andrew,

This patch from Micha Feigin fixes some bugs in the earlier reiserfs 
commit default patch. The changelog:

* If you remounted without any commit=NNN option, it would assume 
commit=0 and restore the defaults. This patch makes it leave the current 
state alone if you don't pass commit=NNN.

* Added range check for cast from unsigned long to unsigned int.

--Bart
diff -ruN linux-2.6.6-rc2-mm1/fs/reiserfs/super.c linux-2.6.6-rc2-mm1-reiserfs_fix/fs/reiserfs/super.c
--- linux-2.6.6-rc2-mm1/fs/reiserfs/super.c	2004-04-26 13:28:42.000000000 +0300
+++ linux-2.6.6-rc2-mm1-reiserfs_fix/fs/reiserfs/super.c	2004-04-26 13:57:30.000000000 +0300
@@ -707,13 +707,13 @@
 
 	if ( c == 'c' ) {
 		char *p = 0;
-		int val = simple_strtoul (arg, &p, 0);
+		unsigned long val = simple_strtoul (arg, &p, 0);
 		/* commit=NNN (time in seconds) */
-		if ( *p != '\0' || val < 0) {
+		if ( *p != '\0' || val >= (unsigned int)-1) {
 			printk ("reiserfs_parse_options: bad value %s\n", arg);
 			return 0;
 		}
-		*commit_max_age = val;
+		*commit_max_age = (unsigned int)val;
 	}
 
 	if ( c == 'w' ) {
@@ -796,7 +796,7 @@
   unsigned long blocks;
   unsigned long mount_options = REISERFS_SB(s)->s_mount_opt;
   unsigned long safe_mask = 0;
-  unsigned int commit_max_age = 0;
+  unsigned int commit_max_age = (unsigned int)-1;
 
   rs = SB_DISK_SUPER_BLOCK (s);
 
@@ -818,11 +818,11 @@
    * the bits we're not allowed to change here */
   REISERFS_SB(s)->s_mount_opt = (REISERFS_SB(s)->s_mount_opt & ~safe_mask) |  (mount_options & safe_mask);
 
-  if(commit_max_age != 0) {
+  if(commit_max_age != 0 && commit_max_age != (unsigned int)-1) {
     SB_JOURNAL_MAX_COMMIT_AGE(s) = commit_max_age;
     SB_JOURNAL_MAX_TRANS_AGE(s) = commit_max_age;
   }
-  else
+  else if(commit_max_age == 0)
   {
     /* 0 means restore defaults. */
     SB_JOURNAL_MAX_COMMIT_AGE(s) = SB_JOURNAL_DEFAULT_MAX_COMMIT_AGE(s);
@@ -1282,7 +1282,7 @@
     struct reiserfs_transaction_handle th ;
     int old_format = 0;
     unsigned long blocks;
-	unsigned int commit_max_age = 0;
+    unsigned int commit_max_age = 0;
     int jinit_done = 0 ;
     struct reiserfs_iget_args args ;
     struct reiserfs_super_block * rs;