* [patch] md/raid0: check for create_strip_zones() errors
@ 2016-04-13 6:46 Dan Carpenter
2016-04-13 17:02 ` Shaohua Li
0 siblings, 1 reply; 5+ messages in thread
From: Dan Carpenter @ 2016-04-13 6:46 UTC (permalink / raw)
To: Shaohua Li, Krzysztof Wojcik; +Cc: linux-raid, linux-kernel, kernel-janitors
My static checker complains that if create_strip_zones() fails then we
use "priv_conf" without initializing it. Fix this by checking for
failure.
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
diff --git a/drivers/md/raid0.c b/drivers/md/raid0.c
index 2ea12c6..1d80e3c 100644
--- a/drivers/md/raid0.c
+++ b/drivers/md/raid0.c
@@ -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;
}
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [patch] md/raid0: check for create_strip_zones() errors
2016-04-13 6:46 [patch] md/raid0: check for create_strip_zones() errors Dan Carpenter
@ 2016-04-13 17:02 ` Shaohua Li
2016-04-13 17:53 ` Dan Carpenter
2016-04-14 9:31 ` [patch v2] md/raid0: fix uninitialized variable bug Dan Carpenter
0 siblings, 2 replies; 5+ messages in thread
From: Shaohua Li @ 2016-04-13 17:02 UTC (permalink / raw)
To: Dan Carpenter; +Cc: Krzysztof Wojcik, linux-raid, linux-kernel, kernel-janitors
On Wed, Apr 13, 2016 at 09:46:45AM +0300, Dan Carpenter wrote:
> 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
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [patch] md/raid0: check for create_strip_zones() errors
2016-04-13 17:02 ` Shaohua Li
@ 2016-04-13 17:53 ` Dan Carpenter
2016-04-14 9:31 ` [patch v2] md/raid0: fix uninitialized variable bug Dan Carpenter
1 sibling, 0 replies; 5+ messages in thread
From: Dan Carpenter @ 2016-04-13 17:53 UTC (permalink / raw)
To: Shaohua Li; +Cc: Krzysztof Wojcik, linux-raid, linux-kernel, kernel-janitors
On Wed, Apr 13, 2016 at 10:02:40AM -0700, Shaohua Li wrote:
> On Wed, Apr 13, 2016 at 09:46:45AM +0300, Dan Carpenter wrote:
> > 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
^ permalink raw reply [flat|nested] 5+ messages in thread
* [patch v2] md/raid0: fix uninitialized variable bug
2016-04-13 17:02 ` Shaohua Li
2016-04-13 17:53 ` Dan Carpenter
@ 2016-04-14 9:31 ` Dan Carpenter
2016-04-14 16:57 ` Shaohua Li
1 sibling, 1 reply; 5+ messages in thread
From: Dan Carpenter @ 2016-04-14 9:31 UTC (permalink / raw)
To: Shaohua Li; +Cc: linux-raid, linux-kernel, kernel-janitors
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.
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
---
v2: Shaohua suggested a different fix
diff --git a/drivers/md/raid0.c b/drivers/md/raid0.c
index 2ea12c6..f63dbb6 100644
--- a/drivers/md/raid0.c
+++ b/drivers/md/raid0.c
@@ -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) {
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [patch v2] md/raid0: fix uninitialized variable bug
2016-04-14 9:31 ` [patch v2] md/raid0: fix uninitialized variable bug Dan Carpenter
@ 2016-04-14 16:57 ` Shaohua Li
0 siblings, 0 replies; 5+ messages in thread
From: Shaohua Li @ 2016-04-14 16:57 UTC (permalink / raw)
To: Dan Carpenter; +Cc: linux-raid, linux-kernel, kernel-janitors
On Thu, Apr 14, 2016 at 12:31:49PM +0300, Dan Carpenter wrote:
> 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.
>
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
Applied, thanks!
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2016-04-14 16:57 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-04-13 6:46 [patch] md/raid0: check for create_strip_zones() errors Dan Carpenter
2016-04-13 17:02 ` Shaohua Li
2016-04-13 17:53 ` Dan Carpenter
2016-04-14 9:31 ` [patch v2] md/raid0: fix uninitialized variable bug Dan Carpenter
2016-04-14 16:57 ` Shaohua Li
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).