All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Colin King (gmail)" <colin.i.king@gmail.com>
To: Jaegeuk Kim <jaegeuk@kernel.org>, Chao Yu <chao@kernel.org>,
	linux-f2fs-devel@lists.sourceforge.net
Cc: "linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: re: f2fs: factor out discard_cmd usage from general rb_tree use
Date: Fri, 24 Mar 2023 11:21:11 +0000	[thread overview]
Message-ID: <e50ebe1a-73a0-5800-71e3-0ddd366727ac@gmail.com> (raw)

Hi,

static analysis with clang scan build has detected a potential issue 
introduced by the following commit:

commit 7e9775a516ff6c1e73ee2b42ec563cafee38f42f
Author: Jaegeuk Kim <jaegeuk@kernel.org>
Date:   Fri Mar 10 11:12:35 2023 -0800

f2fs: factor out discard_cmd usage from general rb_tree use


The warning is as follows:

fs/f2fs/segment.c:1425:4: warning: Value stored to 'tdc' is never read 
[deadcode.DeadStores]

The while loop in function __update_discard_tree_range is as follows (+ 
my annotations):


         while (1) {
                 struct rb_node *node;
                 struct discard_cmd *tdc = NULL;

### tdc is set to NULL

                 if (prev_dc) {
                         di.lstart = prev_dc->di.lstart + prev_dc->di.len;
                         if (di.lstart < lstart)
                                 di.lstart = lstart;
                         if (di.lstart >= end)
                                 break;

                         if (!next_dc || next_dc->di.lstart > end)
                                 di.len = end - di.lstart;
                         else
                                 di.len = next_dc->di.lstart - di.lstart;
                         di.start = start + di.lstart - lstart;
                 }

                 if (!di.len)
                         goto next;

                 if (prev_dc && prev_dc->state == D_PREP &&
                         prev_dc->bdev == bdev &&
                         __is_discard_back_mergeable(&di, &prev_dc->di,
 
max_discard_blocks)) {
                         prev_dc->di.len += di.len;
                         dcc->undiscard_blks += di.len;
                         __relocate_discard_cmd(dcc, prev_dc);
                         di = prev_dc->di;
                         tdc = prev_dc;

### tdc is set to prev_dc, however, it is not not read any more with th 
introduction of the "goto next"" statement introduced in the commit 
mentioned earlier

                         goto next;
                 }

                 if (next_dc && next_dc->state == D_PREP &&
                         next_dc->bdev == bdev &&
                         __is_discard_front_mergeable(&di, &next_dc->di,
 
max_discard_blocks)) {
                         next_dc->di.lstart = di.lstart;
                         next_dc->di.len += di.len;
                         next_dc->di.start = di.start;
                         dcc->undiscard_blks += di.len;
                         __relocate_discard_cmd(dcc, next_dc);

### tdc is always NULL, there is no path to this code where tdc is ever 
set to a non-NULL value.

                         if (tdc)
                                 __remove_discard_cmd(sbi, tdc);
                         goto next;
                 }

                 __insert_discard_cmd(sbi, bdev, di.lstart, di.start, 
di.len);
  next:
                 prev_dc = next_dc;
                 if (!prev_dc)
                         break;

                 node = rb_next(&prev_dc->rb_node);
                 next_dc = rb_entry_safe(node, struct discard_cmd, rb_node);
         }



WARNING: multiple messages have this Message-ID (diff)
From: "Colin King (gmail)" <colin.i.king@gmail.com>
To: Jaegeuk Kim <jaegeuk@kernel.org>, Chao Yu <chao@kernel.org>,
	linux-f2fs-devel@lists.sourceforge.net
Cc: "linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: Re: [f2fs-dev] f2fs: factor out discard_cmd usage from general rb_tree use
Date: Fri, 24 Mar 2023 11:21:11 +0000	[thread overview]
Message-ID: <e50ebe1a-73a0-5800-71e3-0ddd366727ac@gmail.com> (raw)

Hi,

static analysis with clang scan build has detected a potential issue 
introduced by the following commit:

commit 7e9775a516ff6c1e73ee2b42ec563cafee38f42f
Author: Jaegeuk Kim <jaegeuk@kernel.org>
Date:   Fri Mar 10 11:12:35 2023 -0800

f2fs: factor out discard_cmd usage from general rb_tree use


The warning is as follows:

fs/f2fs/segment.c:1425:4: warning: Value stored to 'tdc' is never read 
[deadcode.DeadStores]

The while loop in function __update_discard_tree_range is as follows (+ 
my annotations):


         while (1) {
                 struct rb_node *node;
                 struct discard_cmd *tdc = NULL;

### tdc is set to NULL

                 if (prev_dc) {
                         di.lstart = prev_dc->di.lstart + prev_dc->di.len;
                         if (di.lstart < lstart)
                                 di.lstart = lstart;
                         if (di.lstart >= end)
                                 break;

                         if (!next_dc || next_dc->di.lstart > end)
                                 di.len = end - di.lstart;
                         else
                                 di.len = next_dc->di.lstart - di.lstart;
                         di.start = start + di.lstart - lstart;
                 }

                 if (!di.len)
                         goto next;

                 if (prev_dc && prev_dc->state == D_PREP &&
                         prev_dc->bdev == bdev &&
                         __is_discard_back_mergeable(&di, &prev_dc->di,
 
max_discard_blocks)) {
                         prev_dc->di.len += di.len;
                         dcc->undiscard_blks += di.len;
                         __relocate_discard_cmd(dcc, prev_dc);
                         di = prev_dc->di;
                         tdc = prev_dc;

### tdc is set to prev_dc, however, it is not not read any more with th 
introduction of the "goto next"" statement introduced in the commit 
mentioned earlier

                         goto next;
                 }

                 if (next_dc && next_dc->state == D_PREP &&
                         next_dc->bdev == bdev &&
                         __is_discard_front_mergeable(&di, &next_dc->di,
 
max_discard_blocks)) {
                         next_dc->di.lstart = di.lstart;
                         next_dc->di.len += di.len;
                         next_dc->di.start = di.start;
                         dcc->undiscard_blks += di.len;
                         __relocate_discard_cmd(dcc, next_dc);

### tdc is always NULL, there is no path to this code where tdc is ever 
set to a non-NULL value.

                         if (tdc)
                                 __remove_discard_cmd(sbi, tdc);
                         goto next;
                 }

                 __insert_discard_cmd(sbi, bdev, di.lstart, di.start, 
di.len);
  next:
                 prev_dc = next_dc;
                 if (!prev_dc)
                         break;

                 node = rb_next(&prev_dc->rb_node);
                 next_dc = rb_entry_safe(node, struct discard_cmd, rb_node);
         }




_______________________________________________
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

             reply	other threads:[~2023-03-24 11:21 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-24 11:21 Colin King (gmail) [this message]
2023-03-24 11:21 ` [f2fs-dev] f2fs: factor out discard_cmd usage from general rb_tree use Colin King (gmail)
2023-03-24 16:55 ` Jaegeuk Kim
2023-03-24 16:55   ` [f2fs-dev] " Jaegeuk Kim

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=e50ebe1a-73a0-5800-71e3-0ddd366727ac@gmail.com \
    --to=colin.i.king@gmail.com \
    --cc=chao@kernel.org \
    --cc=jaegeuk@kernel.org \
    --cc=linux-f2fs-devel@lists.sourceforge.net \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.