From: Dan Carpenter <dan.carpenter@oracle.com>
To: Dave Chinner <david@fromorbit.com>, Christoph Hellwig <hch@lst.de>
Cc: djwong@kernel.org, linux-xfs@vger.kernel.org
Subject: Re: [bug report] xfs: pass the goal of the incore inode walk to xfs_inode_walk()
Date: Fri, 13 Aug 2021 10:38:12 +0300 [thread overview]
Message-ID: <20210813073812.GX22532@kadam> (raw)
In-Reply-To: <20210812214048.GE3657114@dread.disaster.area>
On Fri, Aug 13, 2021 at 07:40:48AM +1000, Dave Chinner wrote:
> On Thu, Aug 12, 2021 at 09:42:22AM +0300, Dan Carpenter wrote:
> > Hello Darrick J. Wong,
> >
> > The patch c809d7e948a1: "xfs: pass the goal of the incore inode walk
> > to xfs_inode_walk()" from Jun 1, 2021, leads to the following
> > Smatch static checker warning:
> >
> > fs/xfs/xfs_icache.c:52 xfs_icwalk_tag()
> > warn: unsigned 'goal' is never less than zero.
> >
> > fs/xfs/xfs_icache.c
> > 49 static inline unsigned int
> > 50 xfs_icwalk_tag(enum xfs_icwalk_goal goal)
> > 51 {
> > --> 52 return goal < 0 ? XFS_ICWALK_NULL_TAG : goal;
> >
> > This enum will be unsigned in GCC, so "goal" can't be negative.
>
> I think this is incorrect. The original C standard defines enums as
> signed integers, not unsigned. And according to the GCC manual
> (section 4.9 Structures, Unions, Enumerations, and Bit-Fields)
> indicates that C90 first defines the enum type to be compatible with
> the declared values. IOWs, for a build using C89 like the kernel
> does, enums should always be signed.
>
> This enum is defined as:
>
> enum xfs_icwalk_goal {
> /* Goals that are not related to tags; these must be < 0. */
> XFS_ICWALK_DQRELE = -1,
>
> /* Goals directly associated with tagged inodes. */
> XFS_ICWALK_BLOCKGC = XFS_ICI_BLOCKGC_TAG,
> XFS_ICWALK_RECLAIM = XFS_ICI_RECLAIM_TAG,
> };
>
> i.e. the enum is defined to clearly contain negative values and so
> GCC should be defining it as a signed integer regardless of the
> version of C being used...
You're analysis is correct, but I'm looking at a newer version of the
code and I blamed the wrong commit. It should be commit 777eb1fa857e
("xfs: remove xfs_dqrele_all_inodes")
https://lore.kernel.org/linux-xfs/20210809065938.1199181-3-hch@lst.de/
That commit removes the "XFS_ICWALK_DQRELE = -1," line which
changes the enum type from int to unsigned int.
So this suggests that we should just remove the check for negative
values.
regards,
dan carpenter
>
> > Plus
> > we only pass 0-1 for goal (as far as Smatch can tell).
>
> Yup, smatch has definitely got that one wrong:
>
> xfs_dqrele_all_inodes()
> xfs_icwalk(mp, XFS_ICWALK_DQRELE, &icw);
> xfs_icwalk_get_perag(.... XFS_ICWALK_DQRELE)
> xfs_icwalk_tag(... XFS_ICWALK_DQRELE, ...)
>
> So this warning looks like an issue with smatch, not a bug in the
> code...
>
> Cheers,
>
> Dave.
> --
> Dave Chinner
> david@fromorbit.com
next prev parent reply other threads:[~2021-08-13 7:38 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-08-12 6:42 [bug report] xfs: pass the goal of the incore inode walk to xfs_inode_walk() Dan Carpenter
2021-08-12 21:40 ` Dave Chinner
2021-08-12 22:41 ` Darrick J. Wong
2021-08-12 23:57 ` Dave Chinner
2021-08-13 8:12 ` Dan Carpenter
2021-08-13 7:38 ` Dan Carpenter [this message]
2021-08-13 8:15 ` Christoph Hellwig
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=20210813073812.GX22532@kadam \
--to=dan.carpenter@oracle.com \
--cc=david@fromorbit.com \
--cc=djwong@kernel.org \
--cc=hch@lst.de \
--cc=linux-xfs@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.