Skip to contentSkip to conversation

md/raid0: check for create_strip_zones() errors

PATCH In review Dan Carpenter 2 participants 5 messages Apr 13, 2016 – Apr 14, 2016

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 md/raid0: check for create_strip_zones() errors

My static checker complains that if create_strip_zones() fails then we use "priv_conf" without initializing it. Fix this by checking for failure.

drivers/md/raid0.c +12 -3
index 2ea12c6..1d80e3c 100644
@@ -507,6 +507,7 @@ static void *raid0_takeover_raid45(struct mddev *mddev)
 {
 	struct md_rdev *rdev;
 	struct r0conf *priv_conf;
+	int ret;
 
 	if (mddev->degraded != 1) {
 		printk(KERN_ERR "md/raid0:%s: raid5 must be degraded! Degraded disks: %d\n",
@@ -534,13 +535,16 @@ static void *raid0_takeover_raid45(struct mddev *mddev)
 	/* make sure it will be not marked as dirty */
 	mddev->recovery_cp = MaxSector;
 
-	create_strip_zones(mddev, &priv_conf);
+	ret = create_strip_zones(mddev, &priv_conf);
+	if (ret)
+		return ERR_PTR(ret);
 	return priv_conf;
 }
 
 static void *raid0_takeover_raid10(struct mddev *mddev)
 {
 	struct r0conf *priv_conf;
+	int ret;
 
 	/* Check layout:
 	 *  - far_copies must be 1
@@ -575,7 +579,9 @@ static void *raid0_takeover_raid10(struct mddev *mddev)
 	/* make sure it will be not marked as dirty */
 	mddev->recovery_cp = MaxSector;
 
-	create_strip_zones(mddev, &priv_conf);
+	ret = create_strip_zones(mddev, &priv_conf);
+	if (ret)
+		return ERR_PTR(ret);
 	return priv_conf;
 }
 
@@ -583,6 +589,7 @@ static void *raid0_takeover_raid1(struct mddev *mddev)
 {
 	struct r0conf *priv_conf;
 	int chunksect;
+	int ret;
 
 	/* Check layout:
 	 *  - (N - 1) mirror drives must be already faulty
@@ -617,7 +624,9 @@ static void *raid0_takeover_raid1(struct mddev *mddev)
 	/* make sure it will be not marked as dirty */
 	mddev->recovery_cp = MaxSector;
 
-	create_strip_zones(mddev, &priv_conf);
+	ret = create_strip_zones(mddev, &priv_conf);
+	if (ret)
+		return ERR_PTR(ret);
 	return priv_conf;
 }
 
#1 lore raw
Quoted 3 lines · Dan Carpenter

My static checker complains that if create_strip_zones() fails then we use "priv_conf" without initializing it. Fix this by checking for failure.

It's more convenient setting '*private_conf = ERR_PTR(-ENOMEM);' at the begining of create_strip_zones() when it returns -ENOMEM. create_strip_zones already sets private_conf correctly in other cases.

Thanks,
Shaohua

#2 lore raw
Quoted 9 lines · Shaohua Li
Quoted 3 lines · Dan Carpenter

My static checker complains that if create_strip_zones() fails then we use "priv_conf" without initializing it. Fix this by checking for failure.

It's more convenient setting '*private_conf = ERR_PTR(-ENOMEM);' at the begining of create_strip_zones() when it returns -ENOMEM. create_strip_zones already sets private_conf correctly in other cases.

Yeah. I'll send v2.

regards,
dan carpenter

#3 lore raw

PATCH v2 1/1 md/raid0: fix uninitialized variable bug

In reply to Shaohua Li

If this function fails the callers expect that *private_conf is set to an ERR_PTR() but that isn't true for the first error path where we can't allocate "conf". It leads to some uninitialized variable bugs.

---
v2: Shaohua suggested a different fix

drivers/md/raid0.c +1 -0
index 2ea12c6..f63dbb6 100644
@@ -85,6 +85,7 @@ static int create_strip_zones(struct mddev *mddev, struct r0conf **private_conf)
 	struct r0conf *conf = kzalloc(sizeof(*conf), GFP_KERNEL);
 	unsigned short blksize = 512;
 
+	*private_conf = ERR_PTR(-ENOMEM);
 	if (!conf)
 		return -ENOMEM;
 	rdev_for_each(rdev1, mddev) {
Applied
#4 lore raw

Re: [patch v2] md/raid0: fix uninitialized variable bug

Quoted 5 lines · Dan Carpenter

If this function fails the callers expect that *private_conf is set to an ERR_PTR() but that isn't true for the first error path where we can't allocate "conf". It leads to some uninitialized variable bugs.

Applied, thanks!