2018-01-18 14:00:07

by Wei Yongjun

[permalink] [raw]
Subject: [PATCH -next] mtd: ubi: wl: Fix error return code in ubi_wl_init()

Fix to return error code -ENOMEM from the kmem_cache_alloc() error
handling case instead of 0, as done elsewhere in this function.

Signed-off-by: Wei Yongjun <[email protected]>
---
drivers/mtd/ubi/wl.c | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/drivers/mtd/ubi/wl.c b/drivers/mtd/ubi/wl.c
index 77ab49f..2052a64 100644
--- a/drivers/mtd/ubi/wl.c
+++ b/drivers/mtd/ubi/wl.c
@@ -1617,8 +1617,10 @@ int ubi_wl_init(struct ubi_device *ubi, struct ubi_attach_info *ai)
cond_resched();

e = kmem_cache_alloc(ubi_wl_entry_slab, GFP_KERNEL);
- if (!e)
+ if (!e) {
+ err = -ENOMEM;
goto out_free;
+ }

e->pnum = aeb->pnum;
e->ec = aeb->ec;
@@ -1637,8 +1639,10 @@ int ubi_wl_init(struct ubi_device *ubi, struct ubi_attach_info *ai)
cond_resched();

e = kmem_cache_alloc(ubi_wl_entry_slab, GFP_KERNEL);
- if (!e)
+ if (!e) {
+ err = -ENOMEM;
goto out_free;
+ }

e->pnum = aeb->pnum;
e->ec = aeb->ec;



2018-01-18 14:09:57

by Boris Brezillon

[permalink] [raw]
Subject: Re: [PATCH -next] mtd: ubi: wl: Fix error return code in ubi_wl_init()

On Thu, 18 Jan 2018 14:05:05 +0000
Wei Yongjun <[email protected]> wrote:

> Fix to return error code -ENOMEM from the kmem_cache_alloc() error
> handling case instead of 0, as done elsewhere in this function.

I guess you've used a static analysis code to detect this problem, can
you name it in the commit message, and paste the error/warning message
it reported next time you submit this kind of patch.

>
> Signed-off-by: Wei Yongjun <[email protected]>

NAck. I you read the code you'll see that err is initialized to -ENOMEM
here [1], so these changes are actually not needed.

> ---
> drivers/mtd/ubi/wl.c | 8 ++++++--
> 1 file changed, 6 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/mtd/ubi/wl.c b/drivers/mtd/ubi/wl.c
> index 77ab49f..2052a64 100644
> --- a/drivers/mtd/ubi/wl.c
> +++ b/drivers/mtd/ubi/wl.c
> @@ -1617,8 +1617,10 @@ int ubi_wl_init(struct ubi_device *ubi, struct ubi_attach_info *ai)
> cond_resched();
>
> e = kmem_cache_alloc(ubi_wl_entry_slab, GFP_KERNEL);
> - if (!e)
> + if (!e) {
> + err = -ENOMEM;
> goto out_free;
> + }
>
> e->pnum = aeb->pnum;
> e->ec = aeb->ec;
> @@ -1637,8 +1639,10 @@ int ubi_wl_init(struct ubi_device *ubi, struct ubi_attach_info *ai)
> cond_resched();
>
> e = kmem_cache_alloc(ubi_wl_entry_slab, GFP_KERNEL);
> - if (!e)
> + if (!e) {
> + err = -ENOMEM;
> goto out_free;
> + }
>
> e->pnum = aeb->pnum;
> e->ec = aeb->ec;
>

[1]https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git/tree/drivers/mtd/ubi/wl.c?h=next-20180118#n1596

2018-01-18 14:12:13

by Boris Brezillon

[permalink] [raw]
Subject: Re: [PATCH -next] mtd: ubi: wl: Fix error return code in ubi_wl_init()

On Thu, 18 Jan 2018 15:08:01 +0100
Boris Brezillon <[email protected]> wrote:

> On Thu, 18 Jan 2018 14:05:05 +0000
> Wei Yongjun <[email protected]> wrote:
>
> > Fix to return error code -ENOMEM from the kmem_cache_alloc() error
> > handling case instead of 0, as done elsewhere in this function.
>
> I guess you've used a static analysis code to detect this problem, can
> you name it in the commit message, and paste the error/warning message
> it reported next time you submit this kind of patch.
>
> >
> > Signed-off-by: Wei Yongjun <[email protected]>
>
> NAck. I you read the code you'll see that err is initialized to -ENOMEM
> here [1], so these changes are actually not needed.

Sorry, just realized I was wrong. It seems that err can be overridden by
[2]. So this patch is indeed fixing a real problem.

Reviewed-by: Boris Brezillon <[email protected]>

>
> > ---
> > drivers/mtd/ubi/wl.c | 8 ++++++--
> > 1 file changed, 6 insertions(+), 2 deletions(-)
> >
> > diff --git a/drivers/mtd/ubi/wl.c b/drivers/mtd/ubi/wl.c
> > index 77ab49f..2052a64 100644
> > --- a/drivers/mtd/ubi/wl.c
> > +++ b/drivers/mtd/ubi/wl.c
> > @@ -1617,8 +1617,10 @@ int ubi_wl_init(struct ubi_device *ubi, struct ubi_attach_info *ai)
> > cond_resched();
> >
> > e = kmem_cache_alloc(ubi_wl_entry_slab, GFP_KERNEL);
> > - if (!e)
> > + if (!e) {
> > + err = -ENOMEM;
> > goto out_free;
> > + }
> >
> > e->pnum = aeb->pnum;
> > e->ec = aeb->ec;
> > @@ -1637,8 +1639,10 @@ int ubi_wl_init(struct ubi_device *ubi, struct ubi_attach_info *ai)
> > cond_resched();
> >
> > e = kmem_cache_alloc(ubi_wl_entry_slab, GFP_KERNEL);
> > - if (!e)
> > + if (!e) {
> > + err = -ENOMEM;
> > goto out_free;
> > + }
> >
> > e->pnum = aeb->pnum;
> > e->ec = aeb->ec;
> >
>
> [1]https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git/tree/drivers/mtd/ubi/wl.c?h=next-20180118#n1596

[2]https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git/tree/drivers/mtd/ubi/wl.c?h=next-20180118#n1609

2018-01-18 16:25:21

by Boris Brezillon

[permalink] [raw]
Subject: Re: [PATCH -next] mtd: ubi: wl: Fix error return code in ubi_wl_init()

On Thu, 18 Jan 2018 15:11:32 +0100
Boris Brezillon <[email protected]> wrote:

> On Thu, 18 Jan 2018 15:08:01 +0100
> Boris Brezillon <[email protected]> wrote:
>
> > On Thu, 18 Jan 2018 14:05:05 +0000
> > Wei Yongjun <[email protected]> wrote:
> >
> > > Fix to return error code -ENOMEM from the kmem_cache_alloc() error
> > > handling case instead of 0, as done elsewhere in this function.
> >
> > I guess you've used a static analysis code to detect this problem, can
> > you name it in the commit message, and paste the error/warning message
> > it reported next time you submit this kind of patch.
> >
> > >
> > > Signed-off-by: Wei Yongjun <[email protected]>
> >
> > NAck. I you read the code you'll see that err is initialized to -ENOMEM
> > here [1], so these changes are actually not needed.
>
> Sorry, just realized I was wrong. It seems that err can be overridden by
> [2]. So this patch is indeed fixing a real problem.
>
> Reviewed-by: Boris Brezillon <[email protected]>

Oh, and you can add:

Fixes: f78e5623f45b ("ubi: fastmap: Erase outdated anchor PEBs during attach")

>
> >
> > > ---
> > > drivers/mtd/ubi/wl.c | 8 ++++++--
> > > 1 file changed, 6 insertions(+), 2 deletions(-)
> > >
> > > diff --git a/drivers/mtd/ubi/wl.c b/drivers/mtd/ubi/wl.c
> > > index 77ab49f..2052a64 100644
> > > --- a/drivers/mtd/ubi/wl.c
> > > +++ b/drivers/mtd/ubi/wl.c
> > > @@ -1617,8 +1617,10 @@ int ubi_wl_init(struct ubi_device *ubi, struct ubi_attach_info *ai)
> > > cond_resched();
> > >
> > > e = kmem_cache_alloc(ubi_wl_entry_slab, GFP_KERNEL);
> > > - if (!e)
> > > + if (!e) {
> > > + err = -ENOMEM;
> > > goto out_free;
> > > + }
> > >
> > > e->pnum = aeb->pnum;
> > > e->ec = aeb->ec;
> > > @@ -1637,8 +1639,10 @@ int ubi_wl_init(struct ubi_device *ubi, struct ubi_attach_info *ai)
> > > cond_resched();
> > >
> > > e = kmem_cache_alloc(ubi_wl_entry_slab, GFP_KERNEL);
> > > - if (!e)
> > > + if (!e) {
> > > + err = -ENOMEM;
> > > goto out_free;
> > > + }
> > >
> > > e->pnum = aeb->pnum;
> > > e->ec = aeb->ec;
> > >
> >
> > [1]https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git/tree/drivers/mtd/ubi/wl.c?h=next-20180118#n1596
>
> [2]https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git/tree/drivers/mtd/ubi/wl.c?h=next-20180118#n1609
>
> ______________________________________________________
> Linux MTD discussion mailing list
> http://lists.infradead.org/mailman/listinfo/linux-mtd/


2018-01-18 16:28:24

by Richard Weinberger

[permalink] [raw]
Subject: Re: [PATCH -next] mtd: ubi: wl: Fix error return code in ubi_wl_init()

Boris, Wei Yongjun,

Am Donnerstag, 18. Januar 2018, 16:34:45 CET schrieb Boris Brezillon:
> On Thu, 18 Jan 2018 15:11:32 +0100
>
> Boris Brezillon <[email protected]> wrote:
> > On Thu, 18 Jan 2018 15:08:01 +0100
> >
> > Boris Brezillon <[email protected]> wrote:
> > > On Thu, 18 Jan 2018 14:05:05 +0000
> > >
> > > Wei Yongjun <[email protected]> wrote:
> > > > Fix to return error code -ENOMEM from the kmem_cache_alloc() error
> > > > handling case instead of 0, as done elsewhere in this function.
> > >
> > > I guess you've used a static analysis code to detect this problem, can
> > > you name it in the commit message, and paste the error/warning message
> > > it reported next time you submit this kind of patch.
> > >
> > > > Signed-off-by: Wei Yongjun <[email protected]>
> > >
> > > NAck. I you read the code you'll see that err is initialized to -ENOMEM
> > > here [1], so these changes are actually not needed.
> >
> > Sorry, just realized I was wrong. It seems that err can be overridden by
> > [2]. So this patch is indeed fixing a real problem.
> >
> > Reviewed-by: Boris Brezillon <[email protected]>
>
> Oh, and you can add:
>
> Fixes: f78e5623f45b ("ubi: fastmap: Erase outdated anchor PEBs during
> attach")

Good catch!

Thanks,
//richard