Skip to contentSkip to conversation

Initialize max_slots early

PATCH New Goldwyn Rodrigues 3 participants 3 messages Oct 11, 2010 OCFS2

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Initialize max_slots early

Functions such as ocfs2_recovery_init() make use of osb->max_slots. Initialize osb->max_slots early so the functions may use the correct value.

---

fs/ocfs2/super.c +9 -9
index fa1be1b..3894c7e 100644
@@ -2060,6 +2060,15 @@ static int ocfs2_initialize_super(struct super_block *sb,
 	snprintf(osb->dev_str, sizeof(osb->dev_str), "%u,%u",
 		 MAJOR(osb->sb->s_dev), MINOR(osb->sb->s_dev));
 
+	osb->max_slots = le16_to_cpu(di->id2.i_super.s_max_slots);
+	if (osb->max_slots > OCFS2_MAX_SLOTS || osb->max_slots == 0) {
+		mlog(ML_ERROR, "Invalid number of node slots (%u)\n",
+		     osb->max_slots);
+		status = -EINVAL;
+		goto bail;
+	}
+	mlog(0, "max_slots for this device: %u\n", osb->max_slots);
+
 	ocfs2_orphan_scan_init(osb);
 
 	status = ocfs2_recovery_init(osb);
@@ -2098,15 +2107,6 @@ static int ocfs2_initialize_super(struct super_block *sb,
 		goto bail;
 	}
 
-	osb->max_slots = le16_to_cpu(di->id2.i_super.s_max_slots);
-	if (osb->max_slots > OCFS2_MAX_SLOTS || osb->max_slots == 0) {
-		mlog(ML_ERROR, "Invalid number of node slots (%u)\n",
-		     osb->max_slots);
-		status = -EINVAL;
-		goto bail;
-	}
-	mlog(0, "max_slots for this device: %u\n", osb->max_slots);
-
 	osb->slot_recovery_generations =
 		kcalloc(osb->max_slots, sizeof(*osb->slot_recovery_generations),
 			GFP_KERNEL);
Signature · 1 line
Goldwyn
#1 lore raw

PATCH 1/1 Initialize max_slots early

wow... this bug has been in mainline for 2 years. How come we did not run into this problem earlier.

Quoted 44 lines · Goldwyn Rodrigues

Functions such as ocfs2_recovery_init() make use of osb->max_slots. Initialize osb->max_slots early so the functions may use the correct value.

---

fs/ocfs2/super.c +9 -9
index fa1be1b..3894c7e 100644
@@ -2060,6 +2060,15 @@ static int ocfs2_initialize_super(struct super_block *sb,
  	snprintf(osb->dev_str, sizeof(osb->dev_str), "%u,%u",
  		 MAJOR(osb->sb->s_dev), MINOR(osb->sb->s_dev));
 
+	osb->max_slots = le16_to_cpu(di->id2.i_super.s_max_slots);
+	if (osb->max_slots>  OCFS2_MAX_SLOTS || osb->max_slots == 0) {
+		mlog(ML_ERROR, "Invalid number of node slots (%u)\n",
+		     osb->max_slots);
+		status = -EINVAL;
+		goto bail;
+	}
+	mlog(0, "max_slots for this device: %u\n", osb->max_slots);
+
  	ocfs2_orphan_scan_init(osb);
 
  	status = ocfs2_recovery_init(osb);
@@ -2098,15 +2107,6 @@ static int ocfs2_initialize_super(struct super_block *sb,
  		goto bail;
  	}
 
-	osb->max_slots = le16_to_cpu(di->id2.i_super.s_max_slots);
-	if (osb->max_slots>  OCFS2_MAX_SLOTS || osb->max_slots == 0) {
-		mlog(ML_ERROR, "Invalid number of node slots (%u)\n",
-		     osb->max_slots);
-		status = -EINVAL;
-		goto bail;
-	}
-	mlog(0, "max_slots for this device: %u\n", osb->max_slots);
-
  	osb->slot_recovery_generations =
  		kcalloc(osb->max_slots, sizeof(*osb->slot_recovery_generations),
  			GFP_KERNEL);
#2 lore raw

PATCH 1/1 Initialize max_slots early

In reply to Goldwyn Rodrigues
Quoted 5 lines · Goldwyn Rodrigues

Functions such as ocfs2_recovery_init() make use of osb->max_slots. Initialize osb->max_slots early so the functions may use the correct value.

This patch is now in the merge-window branch of ocfs2.git.

Joel

Signature · 9 lines
Life's Little Instruction Book #157 

	"Take time to smell the roses."

Joel Becker
Consulting Software Developer
Oracle
E-mail: joel.becker at oracle.com
Phone: (650) 506-8127