All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] ubifs: Remove a redundant null check on pointer lp
@ 2021-06-21 15:22 ` Colin King
  0 siblings, 0 replies; 10+ messages in thread
From: Colin King @ 2021-06-21 15:22 UTC (permalink / raw)
  To: Richard Weinberger, Dan Carpenter, linux-mtd
  Cc: kernel-janitors, linux-kernel

From: Colin Ian King <colin.king@canonical.com>

An earlier fix to replace an IS_ERR check on lp with a null check
on lp didn't remove a following null check on lp. The second null
check is redundant and can be removed.

Addresses-Coverity: ("Logically dead code")
Fixes: c770cd5190ba ("ubifs: fix an IS_ERR() vs NULL check")
Signed-off-by: Colin Ian King <colin.king@canonical.com>
---
 fs/ubifs/gc.c | 2 --
 1 file changed, 2 deletions(-)

diff --git a/fs/ubifs/gc.c b/fs/ubifs/gc.c
index 7cc22d7317ea..465beea52176 100644
--- a/fs/ubifs/gc.c
+++ b/fs/ubifs/gc.c
@@ -899,8 +899,6 @@ int ubifs_gc_start_commit(struct ubifs_info *c)
 			err = -ENOMEM;
 			goto out;
 		}
-		if (!lp)
-			break;
 		idx_gc = kmalloc(sizeof(struct ubifs_gced_idx_leb), GFP_NOFS);
 		if (!idx_gc) {
 			err = -ENOMEM;
-- 
2.31.1


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH] ubifs: Remove a redundant null check on pointer lp
@ 2021-06-21 15:22 ` Colin King
  0 siblings, 0 replies; 10+ messages in thread
From: Colin King @ 2021-06-21 15:22 UTC (permalink / raw)
  To: Richard Weinberger, Dan Carpenter, linux-mtd
  Cc: kernel-janitors, linux-kernel

From: Colin Ian King <colin.king@canonical.com>

An earlier fix to replace an IS_ERR check on lp with a null check
on lp didn't remove a following null check on lp. The second null
check is redundant and can be removed.

Addresses-Coverity: ("Logically dead code")
Fixes: c770cd5190ba ("ubifs: fix an IS_ERR() vs NULL check")
Signed-off-by: Colin Ian King <colin.king@canonical.com>
---
 fs/ubifs/gc.c | 2 --
 1 file changed, 2 deletions(-)

diff --git a/fs/ubifs/gc.c b/fs/ubifs/gc.c
index 7cc22d7317ea..465beea52176 100644
--- a/fs/ubifs/gc.c
+++ b/fs/ubifs/gc.c
@@ -899,8 +899,6 @@ int ubifs_gc_start_commit(struct ubifs_info *c)
 			err = -ENOMEM;
 			goto out;
 		}
-		if (!lp)
-			break;
 		idx_gc = kmalloc(sizeof(struct ubifs_gced_idx_leb), GFP_NOFS);
 		if (!idx_gc) {
 			err = -ENOMEM;
-- 
2.31.1


______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* Re: [PATCH] ubifs: Remove a redundant null check on pointer lp
  2021-06-21 15:22 ` Colin King
@ 2021-06-22  2:38   ` Zhihao Cheng
  -1 siblings, 0 replies; 10+ messages in thread
From: Zhihao Cheng @ 2021-06-22  2:38 UTC (permalink / raw)
  To: Colin King, Richard Weinberger, Dan Carpenter, linux-mtd
  Cc: kernel-janitors, linux-kernel

在 2021/6/21 23:22, Colin King 写道:
> From: Colin Ian King <colin.king@canonical.com>
> 
> An earlier fix to replace an IS_ERR check on lp with a null check
> on lp didn't remove a following null check on lp. The second null
> check is redundant and can be removed.
> 
> Addresses-Coverity: ("Logically dead code")
> Fixes: c770cd5190ba ("ubifs: fix an IS_ERR() vs NULL check")
> Signed-off-by: Colin Ian King <colin.king@canonical.com>
> ---
>   fs/ubifs/gc.c | 2 --
>   1 file changed, 2 deletions(-)
> 
> diff --git a/fs/ubifs/gc.c b/fs/ubifs/gc.c
> index 7cc22d7317ea..465beea52176 100644
> --- a/fs/ubifs/gc.c
> +++ b/fs/ubifs/gc.c
> @@ -899,8 +899,6 @@ int ubifs_gc_start_commit(struct ubifs_info *c)
>   			err = -ENOMEM;
>   			goto out;
>   		}
Hi Colin,
I just found out about it today thanks to your patch. Commit 
c770cd5190ba ("ubifs: fix an IS_ERR() vs NULL check") did import a new 
problem that ubifs_gc_start_commit() may return -ENOMEM while syncing fs.
I guess ubifs_fast_find_frdi_idx() return NULL pointer is the 
termination condition in while-loop, which means we cannot get a 
freeable index LEB in ubifs_gc_start_commit().

> -		if (!lp)
> -			break;
>   		idx_gc = kmalloc(sizeof(struct ubifs_gced_idx_leb), GFP_NOFS);
>   		if (!idx_gc) {
>   			err = -ENOMEM;
> 
BTW, the following modifications may be what you want?
diff --git a/fs/ubifs/gc.c b/fs/ubifs/gc.c
index 7cc22d7317ea..b1f276599b04 100644
--- a/fs/ubifs/gc.c
+++ b/fs/ubifs/gc.c
@@ -895,10 +895,6 @@ int ubifs_gc_start_commit(struct ubifs_info *c)
         /* Record index freeable LEBs for unmapping after commit */
         while (1) {
                 lp = ubifs_fast_find_frdi_idx(c);
-               if (!lp) {
-                       err = -ENOMEM;
-                       goto out;
-               }
                 if (!lp)
                         break;
                 idx_gc = kmalloc(sizeof(struct ubifs_gced_idx_leb), 
GFP_NOFS);

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* Re: [PATCH] ubifs: Remove a redundant null check on pointer lp
@ 2021-06-22  2:38   ` Zhihao Cheng
  0 siblings, 0 replies; 10+ messages in thread
From: Zhihao Cheng @ 2021-06-22  2:38 UTC (permalink / raw)
  To: Colin King, Richard Weinberger, Dan Carpenter, linux-mtd
  Cc: kernel-janitors, linux-kernel

在 2021/6/21 23:22, Colin King 写道:
> From: Colin Ian King <colin.king@canonical.com>
> 
> An earlier fix to replace an IS_ERR check on lp with a null check
> on lp didn't remove a following null check on lp. The second null
> check is redundant and can be removed.
> 
> Addresses-Coverity: ("Logically dead code")
> Fixes: c770cd5190ba ("ubifs: fix an IS_ERR() vs NULL check")
> Signed-off-by: Colin Ian King <colin.king@canonical.com>
> ---
>   fs/ubifs/gc.c | 2 --
>   1 file changed, 2 deletions(-)
> 
> diff --git a/fs/ubifs/gc.c b/fs/ubifs/gc.c
> index 7cc22d7317ea..465beea52176 100644
> --- a/fs/ubifs/gc.c
> +++ b/fs/ubifs/gc.c
> @@ -899,8 +899,6 @@ int ubifs_gc_start_commit(struct ubifs_info *c)
>   			err = -ENOMEM;
>   			goto out;
>   		}
Hi Colin,
I just found out about it today thanks to your patch. Commit 
c770cd5190ba ("ubifs: fix an IS_ERR() vs NULL check") did import a new 
problem that ubifs_gc_start_commit() may return -ENOMEM while syncing fs.
I guess ubifs_fast_find_frdi_idx() return NULL pointer is the 
termination condition in while-loop, which means we cannot get a 
freeable index LEB in ubifs_gc_start_commit().

> -		if (!lp)
> -			break;
>   		idx_gc = kmalloc(sizeof(struct ubifs_gced_idx_leb), GFP_NOFS);
>   		if (!idx_gc) {
>   			err = -ENOMEM;
> 
BTW, the following modifications may be what you want?
diff --git a/fs/ubifs/gc.c b/fs/ubifs/gc.c
index 7cc22d7317ea..b1f276599b04 100644
--- a/fs/ubifs/gc.c
+++ b/fs/ubifs/gc.c
@@ -895,10 +895,6 @@ int ubifs_gc_start_commit(struct ubifs_info *c)
         /* Record index freeable LEBs for unmapping after commit */
         while (1) {
                 lp = ubifs_fast_find_frdi_idx(c);
-               if (!lp) {
-                       err = -ENOMEM;
-                       goto out;
-               }
                 if (!lp)
                         break;
                 idx_gc = kmalloc(sizeof(struct ubifs_gced_idx_leb), 
GFP_NOFS);

______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* Re: [PATCH] ubifs: Remove a redundant null check on pointer lp
  2021-06-22  2:38   ` Zhihao Cheng
@ 2021-06-22  6:44     ` Dan Carpenter
  -1 siblings, 0 replies; 10+ messages in thread
From: Dan Carpenter @ 2021-06-22  6:44 UTC (permalink / raw)
  To: Zhihao Cheng
  Cc: Colin King, Richard Weinberger, linux-mtd, kernel-janitors, linux-kernel

On Tue, Jun 22, 2021 at 10:38:52AM +0800, Zhihao Cheng wrote:
> 在 2021/6/21 23:22, Colin King 写道:
> > From: Colin Ian King <colin.king@canonical.com>
> > 
> > An earlier fix to replace an IS_ERR check on lp with a null check
> > on lp didn't remove a following null check on lp. The second null
> > check is redundant and can be removed.
> > 
> > Addresses-Coverity: ("Logically dead code")
> > Fixes: c770cd5190ba ("ubifs: fix an IS_ERR() vs NULL check")
> > Signed-off-by: Colin Ian King <colin.king@canonical.com>
> > ---
> >   fs/ubifs/gc.c | 2 --
> >   1 file changed, 2 deletions(-)
> > 
> > diff --git a/fs/ubifs/gc.c b/fs/ubifs/gc.c
> > index 7cc22d7317ea..465beea52176 100644
> > --- a/fs/ubifs/gc.c
> > +++ b/fs/ubifs/gc.c
> > @@ -899,8 +899,6 @@ int ubifs_gc_start_commit(struct ubifs_info *c)
> >   			err = -ENOMEM;
> >   			goto out;
> >   		}
> Hi Colin,
> I just found out about it today thanks to your patch. Commit c770cd5190ba
> ("ubifs: fix an IS_ERR() vs NULL check") did import a new problem that
> ubifs_gc_start_commit() may return -ENOMEM while syncing fs.
> I guess ubifs_fast_find_frdi_idx() return NULL pointer is the termination
> condition in while-loop, which means we cannot get a freeable index LEB in
> ubifs_gc_start_commit().

Ugh...  I'm so sorry.  My patch was clearly wrong.  I've tried before to
add a Smatch check which warns about duplicative NULL checks, but I
think this gives me a new idea to try.  Hopefully, it will prevent this
in the future.

Yeah, and it's my check which needs to be deleted, not the other one.

regards,
dan carpenter


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] ubifs: Remove a redundant null check on pointer lp
@ 2021-06-22  6:44     ` Dan Carpenter
  0 siblings, 0 replies; 10+ messages in thread
From: Dan Carpenter @ 2021-06-22  6:44 UTC (permalink / raw)
  To: Zhihao Cheng
  Cc: Colin King, Richard Weinberger, linux-mtd, kernel-janitors, linux-kernel

On Tue, Jun 22, 2021 at 10:38:52AM +0800, Zhihao Cheng wrote:
> 在 2021/6/21 23:22, Colin King 写道:
> > From: Colin Ian King <colin.king@canonical.com>
> > 
> > An earlier fix to replace an IS_ERR check on lp with a null check
> > on lp didn't remove a following null check on lp. The second null
> > check is redundant and can be removed.
> > 
> > Addresses-Coverity: ("Logically dead code")
> > Fixes: c770cd5190ba ("ubifs: fix an IS_ERR() vs NULL check")
> > Signed-off-by: Colin Ian King <colin.king@canonical.com>
> > ---
> >   fs/ubifs/gc.c | 2 --
> >   1 file changed, 2 deletions(-)
> > 
> > diff --git a/fs/ubifs/gc.c b/fs/ubifs/gc.c
> > index 7cc22d7317ea..465beea52176 100644
> > --- a/fs/ubifs/gc.c
> > +++ b/fs/ubifs/gc.c
> > @@ -899,8 +899,6 @@ int ubifs_gc_start_commit(struct ubifs_info *c)
> >   			err = -ENOMEM;
> >   			goto out;
> >   		}
> Hi Colin,
> I just found out about it today thanks to your patch. Commit c770cd5190ba
> ("ubifs: fix an IS_ERR() vs NULL check") did import a new problem that
> ubifs_gc_start_commit() may return -ENOMEM while syncing fs.
> I guess ubifs_fast_find_frdi_idx() return NULL pointer is the termination
> condition in while-loop, which means we cannot get a freeable index LEB in
> ubifs_gc_start_commit().

Ugh...  I'm so sorry.  My patch was clearly wrong.  I've tried before to
add a Smatch check which warns about duplicative NULL checks, but I
think this gives me a new idea to try.  Hopefully, it will prevent this
in the future.

Yeah, and it's my check which needs to be deleted, not the other one.

regards,
dan carpenter


______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] ubifs: Remove a redundant null check on pointer lp
  2021-06-22  2:38   ` Zhihao Cheng
@ 2021-06-22  7:24     ` Richard Weinberger
  -1 siblings, 0 replies; 10+ messages in thread
From: Richard Weinberger @ 2021-06-22  7:24 UTC (permalink / raw)
  To: chengzhihao1
  Cc: Colin Ian King, Dan Carpenter, linux-mtd, kernel-janitors, linux-kernel

----- Ursprüngliche Mail -----
> I just found out about it today thanks to your patch. Commit
> c770cd5190ba ("ubifs: fix an IS_ERR() vs NULL check") did import a new
> problem that ubifs_gc_start_commit() may return -ENOMEM while syncing fs.
> I guess ubifs_fast_find_frdi_idx() return NULL pointer is the
> termination condition in while-loop, which means we cannot get a
> freeable index LEB in ubifs_gc_start_commit().

Good catch! :-)

>> -		if (!lp)
>> -			break;
>>   		idx_gc = kmalloc(sizeof(struct ubifs_gced_idx_leb), GFP_NOFS);
>>   		if (!idx_gc) {
>>   			err = -ENOMEM;
>> 
> BTW, the following modifications may be what you want?
> diff --git a/fs/ubifs/gc.c b/fs/ubifs/gc.c
> index 7cc22d7317ea..b1f276599b04 100644
> --- a/fs/ubifs/gc.c
> +++ b/fs/ubifs/gc.c
> @@ -895,10 +895,6 @@ int ubifs_gc_start_commit(struct ubifs_info *c)
>         /* Record index freeable LEBs for unmapping after commit */
>         while (1) {
>                 lp = ubifs_fast_find_frdi_idx(c);
> -               if (!lp) {
> -                       err = -ENOMEM;
> -                       goto out;
> -               }
>                 if (!lp)
>                         break;
>                 idx_gc = kmalloc(sizeof(struct ubifs_gced_idx_leb),
> GFP_NOFS);

I'll drop Dan's patch from -next. Do you want to send a followup patch which removes the
in vain check?

Thanks,
//richard

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] ubifs: Remove a redundant null check on pointer lp
@ 2021-06-22  7:24     ` Richard Weinberger
  0 siblings, 0 replies; 10+ messages in thread
From: Richard Weinberger @ 2021-06-22  7:24 UTC (permalink / raw)
  To: chengzhihao1
  Cc: Colin Ian King, Dan Carpenter, linux-mtd, kernel-janitors, linux-kernel

----- Ursprüngliche Mail -----
> I just found out about it today thanks to your patch. Commit
> c770cd5190ba ("ubifs: fix an IS_ERR() vs NULL check") did import a new
> problem that ubifs_gc_start_commit() may return -ENOMEM while syncing fs.
> I guess ubifs_fast_find_frdi_idx() return NULL pointer is the
> termination condition in while-loop, which means we cannot get a
> freeable index LEB in ubifs_gc_start_commit().

Good catch! :-)

>> -		if (!lp)
>> -			break;
>>   		idx_gc = kmalloc(sizeof(struct ubifs_gced_idx_leb), GFP_NOFS);
>>   		if (!idx_gc) {
>>   			err = -ENOMEM;
>> 
> BTW, the following modifications may be what you want?
> diff --git a/fs/ubifs/gc.c b/fs/ubifs/gc.c
> index 7cc22d7317ea..b1f276599b04 100644
> --- a/fs/ubifs/gc.c
> +++ b/fs/ubifs/gc.c
> @@ -895,10 +895,6 @@ int ubifs_gc_start_commit(struct ubifs_info *c)
>         /* Record index freeable LEBs for unmapping after commit */
>         while (1) {
>                 lp = ubifs_fast_find_frdi_idx(c);
> -               if (!lp) {
> -                       err = -ENOMEM;
> -                       goto out;
> -               }
>                 if (!lp)
>                         break;
>                 idx_gc = kmalloc(sizeof(struct ubifs_gced_idx_leb),
> GFP_NOFS);

I'll drop Dan's patch from -next. Do you want to send a followup patch which removes the
in vain check?

Thanks,
//richard

______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] ubifs: Remove a redundant null check on pointer lp
  2021-06-22  6:44     ` Dan Carpenter
@ 2021-06-22  7:26       ` Richard Weinberger
  -1 siblings, 0 replies; 10+ messages in thread
From: Richard Weinberger @ 2021-06-22  7:26 UTC (permalink / raw)
  To: Dan Carpenter
  Cc: chengzhihao1, Colin Ian King, linux-mtd, kernel-janitors, linux-kernel

----- Ursprüngliche Mail -----
> Ugh...  I'm so sorry.  My patch was clearly wrong.  I've tried before to

No need to worry. :)

> add a Smatch check which warns about duplicative NULL checks, but I
> think this gives me a new idea to try.  Hopefully, it will prevent this
> in the future.

Sounds great!

Thanks,
//richard

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] ubifs: Remove a redundant null check on pointer lp
@ 2021-06-22  7:26       ` Richard Weinberger
  0 siblings, 0 replies; 10+ messages in thread
From: Richard Weinberger @ 2021-06-22  7:26 UTC (permalink / raw)
  To: Dan Carpenter
  Cc: chengzhihao1, Colin Ian King, linux-mtd, kernel-janitors, linux-kernel

----- Ursprüngliche Mail -----
> Ugh...  I'm so sorry.  My patch was clearly wrong.  I've tried before to

No need to worry. :)

> add a Smatch check which warns about duplicative NULL checks, but I
> think this gives me a new idea to try.  Hopefully, it will prevent this
> in the future.

Sounds great!

Thanks,
//richard

______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2021-06-22  7:26 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-21 15:22 [PATCH] ubifs: Remove a redundant null check on pointer lp Colin King
2021-06-21 15:22 ` Colin King
2021-06-22  2:38 ` Zhihao Cheng
2021-06-22  2:38   ` Zhihao Cheng
2021-06-22  6:44   ` Dan Carpenter
2021-06-22  6:44     ` Dan Carpenter
2021-06-22  7:26     ` Richard Weinberger
2021-06-22  7:26       ` Richard Weinberger
2021-06-22  7:24   ` Richard Weinberger
2021-06-22  7:24     ` Richard Weinberger

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.