* [bug report] UBI: Fastmap: Do not add vol if it already exists
@ 2016-10-25 20:46 Dan Carpenter
2016-10-26 1:46 ` Sheng Yong
0 siblings, 1 reply; 6+ messages in thread
From: Dan Carpenter @ 2016-10-25 20:46 UTC (permalink / raw)
To: shengyong1; +Cc: linux-mtd
Hello shengyong,
The patch e96a8a3bb671: "UBI: Fastmap: Do not add vol if it already
exists" from May 26, 2015, leads to the following static checker
warning:
drivers/mtd/ubi/fastmap.c:712 ubi_attach_fastmap()
warn: PTR_ERR(av) is never (-22)
drivers/mtd/ubi/fastmap.c
703
704 av = add_vol(ai, be32_to_cpu(fmvhdr->vol_id),
705 be32_to_cpu(fmvhdr->used_ebs),
706 be32_to_cpu(fmvhdr->data_pad),
707 fmvhdr->vol_type,
708 be32_to_cpu(fmvhdr->last_eb_bytes));
709
710 if (!av)
711 goto fail_bad;
712 if (PTR_ERR(av) == -EINVAL) {
av is either -EEXIST or -ENOMEM. It's never -EINVAL.
713 ubi_err(ubi, "volume (ID %i) already exists",
714 fmvhdr->vol_id);
715 goto fail_bad;
716 }
717
regards,
dan carpenter
^ permalink raw reply [flat|nested] 6+ messages in thread* Re: [bug report] UBI: Fastmap: Do not add vol if it already exists 2016-10-25 20:46 [bug report] UBI: Fastmap: Do not add vol if it already exists Dan Carpenter @ 2016-10-26 1:46 ` Sheng Yong 2016-10-26 8:25 ` Dan Carpenter 0 siblings, 1 reply; 6+ messages in thread From: Sheng Yong @ 2016-10-26 1:46 UTC (permalink / raw) To: Dan Carpenter; +Cc: linux-mtd Hi Dan, On 10/26/2016 4:46 AM, Dan Carpenter wrote: > Hello shengyong, > > The patch e96a8a3bb671: "UBI: Fastmap: Do not add vol if it already > exists" from May 26, 2015, leads to the following static checker > warning: > > drivers/mtd/ubi/fastmap.c:712 ubi_attach_fastmap() > warn: PTR_ERR(av) is never (-22) > > drivers/mtd/ubi/fastmap.c > 703 > 704 av = add_vol(ai, be32_to_cpu(fmvhdr->vol_id), > 705 be32_to_cpu(fmvhdr->used_ebs), > 706 be32_to_cpu(fmvhdr->data_pad), > 707 fmvhdr->vol_type, > 708 be32_to_cpu(fmvhdr->last_eb_bytes)); > 709 > 710 if (!av) > 711 goto fail_bad; > 712 if (PTR_ERR(av) == -EINVAL) { > > av is either -EEXIST or -ENOMEM. It's never -EINVAL. The commit e96a8a3bb671 ("UBI: Fastmap: Do not add vol if it already exists") adds a "return ERR_PTR(-EINVAL);" to add_vol(). So I think av could be -EINVAL. You mean add_vol should return -EEXIST instead of -EINVAL? thanks, Sheng > > 713 ubi_err(ubi, "volume (ID %i) already exists", > 714 fmvhdr->vol_id); > 715 goto fail_bad; > 716 } > 717 > > regards, > dan carpenter > > . > ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [bug report] UBI: Fastmap: Do not add vol if it already exists 2016-10-26 1:46 ` Sheng Yong @ 2016-10-26 8:25 ` Dan Carpenter 2016-10-26 9:23 ` Boris Brezillon 2016-10-26 11:28 ` Sheng Yong 0 siblings, 2 replies; 6+ messages in thread From: Dan Carpenter @ 2016-10-26 8:25 UTC (permalink / raw) To: Sheng Yong, Boris Brezillon; +Cc: linux-mtd On Wed, Oct 26, 2016 at 09:46:51AM +0800, Sheng Yong wrote: > Hi Dan, > > On 10/26/2016 4:46 AM, Dan Carpenter wrote: > > Hello shengyong, > > > > The patch e96a8a3bb671: "UBI: Fastmap: Do not add vol if it already > > exists" from May 26, 2015, leads to the following static checker > > warning: > > > > drivers/mtd/ubi/fastmap.c:712 ubi_attach_fastmap() > > warn: PTR_ERR(av) is never (-22) > > > > drivers/mtd/ubi/fastmap.c > > 703 > > 704 av = add_vol(ai, be32_to_cpu(fmvhdr->vol_id), > > 705 be32_to_cpu(fmvhdr->used_ebs), > > 706 be32_to_cpu(fmvhdr->data_pad), > > 707 fmvhdr->vol_type, > > 708 be32_to_cpu(fmvhdr->last_eb_bytes)); > > 709 > > 710 if (!av) > > 711 goto fail_bad; > > 712 if (PTR_ERR(av) == -EINVAL) { > > > > av is either -EEXIST or -ENOMEM. It's never -EINVAL. > The commit e96a8a3bb671 ("UBI: Fastmap: Do not add vol if it already exists") > adds a "return ERR_PTR(-EINVAL);" to add_vol(). So I think av could be -EINVAL. > You mean add_vol should return -EEXIST instead of -EINVAL? > Oh, ah. I'm on linux-next. Commit de4c455b3e9f ("UBI: factorize code used to manipulate volumes at attach time") removed the -EINVAL. It's really Boris to blame for this warning. I'm not sure what the fix is. regards, dan carpenter ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [bug report] UBI: Fastmap: Do not add vol if it already exists 2016-10-26 8:25 ` Dan Carpenter @ 2016-10-26 9:23 ` Boris Brezillon 2016-10-26 11:30 ` Sheng Yong 2016-10-26 11:28 ` Sheng Yong 1 sibling, 1 reply; 6+ messages in thread From: Boris Brezillon @ 2016-10-26 9:23 UTC (permalink / raw) To: Dan Carpenter; +Cc: Sheng Yong, linux-mtd, Richard Weinberger + Richard On Wed, 26 Oct 2016 11:25:36 +0300 Dan Carpenter <dan.carpenter@oracle.com> wrote: > On Wed, Oct 26, 2016 at 09:46:51AM +0800, Sheng Yong wrote: > > Hi Dan, > > > > On 10/26/2016 4:46 AM, Dan Carpenter wrote: > > > Hello shengyong, > > > > > > The patch e96a8a3bb671: "UBI: Fastmap: Do not add vol if it already > > > exists" from May 26, 2015, leads to the following static checker > > > warning: > > > > > > drivers/mtd/ubi/fastmap.c:712 ubi_attach_fastmap() > > > warn: PTR_ERR(av) is never (-22) > > > > > > drivers/mtd/ubi/fastmap.c > > > 703 > > > 704 av = add_vol(ai, be32_to_cpu(fmvhdr->vol_id), > > > 705 be32_to_cpu(fmvhdr->used_ebs), > > > 706 be32_to_cpu(fmvhdr->data_pad), > > > 707 fmvhdr->vol_type, > > > 708 be32_to_cpu(fmvhdr->last_eb_bytes)); > > > 709 > > > 710 if (!av) > > > 711 goto fail_bad; > > > 712 if (PTR_ERR(av) == -EINVAL) { > > > > > > av is either -EEXIST or -ENOMEM. It's never -EINVAL. > > The commit e96a8a3bb671 ("UBI: Fastmap: Do not add vol if it already exists") > > adds a "return ERR_PTR(-EINVAL);" to add_vol(). So I think av could be -EINVAL. > > You mean add_vol should return -EEXIST instead of -EINVAL? > > > > Oh, ah. I'm on linux-next. Commit de4c455b3e9f ("UBI: factorize code > used to manipulate volumes at attach time") removed the -EINVAL. > > It's really Boris to blame for this warning. I'm not sure what the fix > is. Yes, sorry, I didn't notice the caller was explicitly testing for -EINVAL. Here is a patch fixing the problem: --->8--- From 66d46bb212a8fcdcdd54def051492abb1668f1b2 Mon Sep 17 00:00:00 2001 From: Boris Brezillon <boris.brezillon@free-electrons.com> Date: Wed, 26 Oct 2016 11:17:03 +0200 Subject: [PATCH] UBI: fastmap: Fix add_vol() return value test in ubi_attach_fastmap() Commit e96a8a3bb671 ("UBI: Fastmap: Do not add vol if it already exists") introduced a bug by changing the possible error codes returned by add_vol(): - this functions no longer returns NULL in case of allocation failure but return ERR_PTR(-ENOMEM) - when a duplicate entry in the volume RB tree is found it returns ERR_PTR(-EEXIST) instead of ERR_PTR(-EINVAL) Fix the tests done of add_vol() return value accordingly. Fixes: e96a8a3bb671 ("UBI: Fastmap: Do not add vol if it already exists") Signed-off-by: Boris Brezillon <boris.brezillon@free-electrons.com> --- drivers/mtd/ubi/fastmap.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/drivers/mtd/ubi/fastmap.c b/drivers/mtd/ubi/fastmap.c index d6384d965788..eb39c44726e3 100644 --- a/drivers/mtd/ubi/fastmap.c +++ b/drivers/mtd/ubi/fastmap.c @@ -707,11 +707,11 @@ static int ubi_attach_fastmap(struct ubi_device *ubi, fmvhdr->vol_type, be32_to_cpu(fmvhdr->last_eb_bytes)); - if (!av) - goto fail_bad; - if (PTR_ERR(av) == -EINVAL) { - ubi_err(ubi, "volume (ID %i) already exists", - fmvhdr->vol_id); + if (IS_ERR(av)) { + if (PTR_ERR(av) == -EEXIST) + ubi_err(ubi, "volume (ID %i) already exists", + fmvhdr->vol_id); + goto fail_bad; } ^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [bug report] UBI: Fastmap: Do not add vol if it already exists 2016-10-26 9:23 ` Boris Brezillon @ 2016-10-26 11:30 ` Sheng Yong 0 siblings, 0 replies; 6+ messages in thread From: Sheng Yong @ 2016-10-26 11:30 UTC (permalink / raw) To: Boris Brezillon, Dan Carpenter; +Cc: linux-mtd, Richard Weinberger On 10/26/2016 5:23 PM, Boris Brezillon wrote: > + Richard > > On Wed, 26 Oct 2016 11:25:36 +0300 > Dan Carpenter <dan.carpenter@oracle.com> wrote: > >> On Wed, Oct 26, 2016 at 09:46:51AM +0800, Sheng Yong wrote: >>> Hi Dan, >>> >>> On 10/26/2016 4:46 AM, Dan Carpenter wrote: >>>> Hello shengyong, >>>> >>>> The patch e96a8a3bb671: "UBI: Fastmap: Do not add vol if it already >>>> exists" from May 26, 2015, leads to the following static checker >>>> warning: >>>> >>>> drivers/mtd/ubi/fastmap.c:712 ubi_attach_fastmap() >>>> warn: PTR_ERR(av) is never (-22) >>>> >>>> drivers/mtd/ubi/fastmap.c >>>> 703 >>>> 704 av = add_vol(ai, be32_to_cpu(fmvhdr->vol_id), >>>> 705 be32_to_cpu(fmvhdr->used_ebs), >>>> 706 be32_to_cpu(fmvhdr->data_pad), >>>> 707 fmvhdr->vol_type, >>>> 708 be32_to_cpu(fmvhdr->last_eb_bytes)); >>>> 709 >>>> 710 if (!av) >>>> 711 goto fail_bad; >>>> 712 if (PTR_ERR(av) == -EINVAL) { >>>> >>>> av is either -EEXIST or -ENOMEM. It's never -EINVAL. >>> The commit e96a8a3bb671 ("UBI: Fastmap: Do not add vol if it already exists") >>> adds a "return ERR_PTR(-EINVAL);" to add_vol(). So I think av could be -EINVAL. >>> You mean add_vol should return -EEXIST instead of -EINVAL? >>> >> >> Oh, ah. I'm on linux-next. Commit de4c455b3e9f ("UBI: factorize code >> used to manipulate volumes at attach time") removed the -EINVAL. >> >> It's really Boris to blame for this warning. I'm not sure what the fix >> is. > > Yes, sorry, I didn't notice the caller was explicitly testing for > -EINVAL. > > Here is a patch fixing the problem: > > --->8--- >>From 66d46bb212a8fcdcdd54def051492abb1668f1b2 Mon Sep 17 00:00:00 2001 > From: Boris Brezillon <boris.brezillon@free-electrons.com> > Date: Wed, 26 Oct 2016 11:17:03 +0200 > Subject: [PATCH] UBI: fastmap: Fix add_vol() return value test in > ubi_attach_fastmap() > > Commit e96a8a3bb671 ("UBI: Fastmap: Do not add vol if it already > exists") introduced a bug by changing the possible error codes returned > by add_vol(): > - this functions no longer returns NULL in case of allocation failure > but return ERR_PTR(-ENOMEM) > - when a duplicate entry in the volume RB tree is found it returns > ERR_PTR(-EEXIST) instead of ERR_PTR(-EINVAL) > > Fix the tests done of add_vol() return value accordingly. > > Fixes: e96a8a3bb671 ("UBI: Fastmap: Do not add vol if it already exists") > Signed-off-by: Boris Brezillon <boris.brezillon@free-electrons.com> > --- > drivers/mtd/ubi/fastmap.c | 10 +++++----- > 1 file changed, 5 insertions(+), 5 deletions(-) > > diff --git a/drivers/mtd/ubi/fastmap.c b/drivers/mtd/ubi/fastmap.c > index d6384d965788..eb39c44726e3 100644 > --- a/drivers/mtd/ubi/fastmap.c > +++ b/drivers/mtd/ubi/fastmap.c > @@ -707,11 +707,11 @@ static int ubi_attach_fastmap(struct ubi_device *ubi, > fmvhdr->vol_type, > be32_to_cpu(fmvhdr->last_eb_bytes)); > > - if (!av) > - goto fail_bad; > - if (PTR_ERR(av) == -EINVAL) { > - ubi_err(ubi, "volume (ID %i) already exists", > - fmvhdr->vol_id); > + if (IS_ERR(av)) { > + if (PTR_ERR(av) == -EEXIST) > + ubi_err(ubi, "volume (ID %i) already exists", > + fmvhdr->vol_id); > + > goto fail_bad; > } > > . > Acked-by: Sheng Yong <shengyong1@huawei.com> thanks, Sheng ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [bug report] UBI: Fastmap: Do not add vol if it already exists 2016-10-26 8:25 ` Dan Carpenter 2016-10-26 9:23 ` Boris Brezillon @ 2016-10-26 11:28 ` Sheng Yong 1 sibling, 0 replies; 6+ messages in thread From: Sheng Yong @ 2016-10-26 11:28 UTC (permalink / raw) To: Dan Carpenter, Boris Brezillon; +Cc: linux-mtd On 10/26/2016 4:25 PM, Dan Carpenter wrote: > On Wed, Oct 26, 2016 at 09:46:51AM +0800, Sheng Yong wrote: >> Hi Dan, >> >> On 10/26/2016 4:46 AM, Dan Carpenter wrote: >>> Hello shengyong, >>> >>> The patch e96a8a3bb671: "UBI: Fastmap: Do not add vol if it already >>> exists" from May 26, 2015, leads to the following static checker >>> warning: >>> >>> drivers/mtd/ubi/fastmap.c:712 ubi_attach_fastmap() >>> warn: PTR_ERR(av) is never (-22) >>> >>> drivers/mtd/ubi/fastmap.c >>> 703 >>> 704 av = add_vol(ai, be32_to_cpu(fmvhdr->vol_id), >>> 705 be32_to_cpu(fmvhdr->used_ebs), >>> 706 be32_to_cpu(fmvhdr->data_pad), >>> 707 fmvhdr->vol_type, >>> 708 be32_to_cpu(fmvhdr->last_eb_bytes)); >>> 709 >>> 710 if (!av) >>> 711 goto fail_bad; >>> 712 if (PTR_ERR(av) == -EINVAL) { >>> >>> av is either -EEXIST or -ENOMEM. It's never -EINVAL. >> The commit e96a8a3bb671 ("UBI: Fastmap: Do not add vol if it already exists") >> adds a "return ERR_PTR(-EINVAL);" to add_vol(). So I think av could be -EINVAL. >> You mean add_vol should return -EEXIST instead of -EINVAL? >> > > Oh, ah. I'm on linux-next. Commit de4c455b3e9f ("UBI: factorize code > used to manipulate volumes at attach time") removed the -EINVAL. Sorry, my bad. I didn't check linux-next. You're right, the caller of add_vol should have checked -EEXIST. And Boris's patch could fix it. Thanks Dan for pointing that out. thanks, Sheng > > It's really Boris to blame for this warning. I'm not sure what the fix > is. > > regards, > dan carpenter > > > . > ^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2016-10-26 11:33 UTC | newest] Thread overview: 6+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2016-10-25 20:46 [bug report] UBI: Fastmap: Do not add vol if it already exists Dan Carpenter 2016-10-26 1:46 ` Sheng Yong 2016-10-26 8:25 ` Dan Carpenter 2016-10-26 9:23 ` Boris Brezillon 2016-10-26 11:30 ` Sheng Yong 2016-10-26 11:28 ` Sheng Yong
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox