All of lore.kernel.org
 help / color / mirror / Atom feed
From: Nathan Chancellor <natechancellor@gmail.com>
To: kbuild-all@lists.01.org
Subject: Re: [djwong-xfs:realtime-rmap 245/249] fs/xfs/scrub/repair.c:2202:6: warning: variable 'is_free' is uninitialized when used here
Date: Mon, 21 Dec 2020 15:19:21 -0700	[thread overview]
Message-ID: <20201221221921.GA3388751@ubuntu-m3-large-x86> (raw)
In-Reply-To: <202012220357.ypoONHum-lkp@intel.com>

[-- Attachment #1: Type: text/plain, Size: 4348 bytes --]

On Tue, Dec 22, 2020 at 03:22:03AM +0800, kernel test robot wrote:
> tree:   https://git.kernel.org/pub/scm/linux/kernel/git/djwong/xfs-linux.git realtime-rmap
> head:   62eb0024d510607ecb04789e8b4f8c0975efb08b
> commit: f4188e5ab1984e1b140433a80f223ab4644801af [245/249] xfs: online repair of realtime file bmaps
> config: x86_64-randconfig-a011-20201217 (attached as .config)
> compiler: clang version 12.0.0 (https://github.com/llvm/llvm-project cee1e7d14f4628d6174b33640d502bff3b54ae45)
> reproduce (this is a W=1 build):
>         wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
>         chmod +x ~/bin/make.cross
>         # install x86_64 cross compiling tool for clang build
>         # apt-get install binutils-x86-64-linux-gnu
>         # https://git.kernel.org/pub/scm/linux/kernel/git/djwong/xfs-linux.git/commit/?id=f4188e5ab1984e1b140433a80f223ab4644801af
>         git remote add djwong-xfs https://git.kernel.org/pub/scm/linux/kernel/git/djwong/xfs-linux.git
>         git fetch --no-tags djwong-xfs realtime-rmap
>         git checkout f4188e5ab1984e1b140433a80f223ab4644801af
>         # save the attached .config to linux build tree
>         COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross ARCH=x86_64 
> 
> If you fix the issue, kindly add following tag as appropriate
> Reported-by: kernel test robot <lkp@intel.com>
> 
> All warnings (new ones prefixed by >>):
> 
> >> fs/xfs/scrub/repair.c:2202:6: warning: variable 'is_free' is uninitialized when used here [-Wuninitialized]
>            if (is_free)
>                ^~~~~~~
>    fs/xfs/scrub/repair.c:2189:16: note: initialize the variable 'is_free' to silence this warning
>            bool                    is_free;
>                                           ^
>                                            = 0
>    1 warning generated.
> 
> 
> vim +/is_free +2202 fs/xfs/scrub/repair.c
> 
>   2173	
>   2174	/*
>   2175	 * Check if any part of this range of rt blocks is free, so that we don't
>   2176	 * rebuild things with bad records.  Returns -EFSCORRUPTED if bad.
>   2177	 */
>   2178	int
>   2179	xrep_rtext_is_free(
>   2180		struct xfs_scrub	*sc,
>   2181		xfs_rtblock_t		rtbno,
>   2182		xfs_filblks_t		len)
>   2183	{
>   2184		struct xfs_mount	*mp = sc->mp;
>   2185		xfs_rtblock_t		startext;
>   2186		xfs_rtblock_t		endext;
>   2187		xfs_rtblock_t		extcount;
>   2188		uint32_t		mod;
>   2189		bool			is_free;
>   2190		int			error;
>   2191	
>   2192		/* Convert rt blocks to rt extents. */
>   2193		startext = div_u64_rem(rtbno, mp->m_sb.sb_rextsize, &mod);
>   2194		endext = div_u64_rem(rtbno + len - 1, mp->m_sb.sb_rextsize, &mod);
>   2195	
>   2196		/* Make sure this isn't free space. */
>   2197		extcount = endext - startext + 1;
>   2198		error = xfs_rtalloc_extent_is_free(mp, sc->tp, startext, extcount,
>   2199				&is_free);
>   2200		if (error)
>   2201			return error;
> > 2202		if (is_free)
>   2203			return -EFSCORRUPTED;
>   2204	
>   2205		return 0;
>   2206	}
>   2207	
> 
> ---
> 0-DAY CI Kernel Test Service, Intel Corporation
> https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org
> 

This appears to be a false positive. From the config:

# CONFIG_XFS_RT is not set

which means xfs_rtalloc_extent_is_free evaluates to ENOSYS and we never
actually make it to that if statement evaluation; however, clang cannot
see this because it is doing simple static analysis at this stage of the
pipeline, not seeing that it will never have to use is_free in this
configuration. A simple reproducer:

$ cat test.c
#define func(a) 22

int main() {
    int error;
    _Bool is_free;

    error = func(&is_free);
    if (error)
        return error;
    if (is_free)
        return -117;

    return 0;
}

$ clang -Wuninitialized -fsyntax-only test.c
test.c:10:9: warning: variable 'is_free' is uninitialized when used here [-Wuninitialized]
    if (is_free)
        ^~~~~~~
test.c:5:18: note: initialize the variable 'is_free' to silence this warning
    _Bool is_free;
                 ^
                  = 0
1 warning generated.

Obviously initializing is_free to false will avoid this warning, which
is probably the simplest fix.

Cheers,
Nathan

  reply	other threads:[~2020-12-21 22:19 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-12-21 19:22 [djwong-xfs:realtime-rmap 245/249] fs/xfs/scrub/repair.c:2202:6: warning: variable 'is_free' is uninitialized when used here kernel test robot
2020-12-21 22:19 ` Nathan Chancellor [this message]
2021-01-04 22:29   ` Darrick J. Wong

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=20201221221921.GA3388751@ubuntu-m3-large-x86 \
    --to=natechancellor@gmail.com \
    --cc=kbuild-all@lists.01.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.