public inbox for linux-xfs@vger.kernel.org
 help / color / mirror / Atom feed
From: Dave Chinner <david@fromorbit.com>
To: Eric Sandeen <sandeen@sandeen.net>
Cc: xfs-oss <xfs@oss.sgi.com>
Subject: Re: [PATCH V2] xfsprogs: use ASSERT_ALWAYS for impossible switch case
Date: Fri, 22 Aug 2014 08:55:21 +1000	[thread overview]
Message-ID: <20140821225521.GR26465@dastard> (raw)
In-Reply-To: <53F639F6.6050905@sandeen.net>

On Thu, Aug 21, 2014 at 01:27:02PM -0500, Eric Sandeen wrote:
> The original reason for the expletive below has been lost
> in the mists of time, but at any rate, ASSERT() goes away in
> libxfs, and this leads static analysis checkers to believe that
> XFS_BTNUM_MAX is possible, and that we might overflow an array
> later when using it as an index.
> 
> We can shut this up and mark it as truly impossible by adding
> a userspace definition for ASSERT_ALWAYS and using it.
> 
> Signed-off-by: Eric Sandeen <sandeen@redhat.com>
> ---
> 
> V2: do it in a kernel-compatible way.
> 
> diff --git a/include/xfs_btree.h b/include/xfs_btree.h
> index 2590d40..f24f787 100644
> --- a/include/xfs_btree.h
> +++ b/include/xfs_btree.h
> @@ -69,7 +69,7 @@ do {    \
>  	case XFS_BTNUM_BMAP: __XFS_BTREE_STATS_INC(bmbt, stat); break;	\
>  	case XFS_BTNUM_INO: __XFS_BTREE_STATS_INC(ibt, stat); break;	\
>  	case XFS_BTNUM_FINO: __XFS_BTREE_STATS_INC(fibt, stat); break;	\
> -	case XFS_BTNUM_MAX: ASSERT(0); /* fucking gcc */ ; break;	\
> +	case XFS_BTNUM_MAX: ASSERT_ALWAYS(0); /* fucking gcc */ ; break; \
>  	}       \
>  } while (0)
>  
> @@ -83,7 +83,7 @@ do {    \
>  	case XFS_BTNUM_BMAP: __XFS_BTREE_STATS_ADD(bmbt, stat, val); break; \
>  	case XFS_BTNUM_INO: __XFS_BTREE_STATS_ADD(ibt, stat, val); break; \
>  	case XFS_BTNUM_FINO: __XFS_BTREE_STATS_ADD(fibt, stat, val); break; \
> -	case XFS_BTNUM_MAX: ASSERT(0); /* fucking gcc */ ; break;	\
> +	case XFS_BTNUM_MAX: ASSERT_ALWAYS(0); /* fucking gcc */ ; break; \
>  	}       \
>  } while (0)

Which we don't want in kernel space, because we want that case to be
optimised out by the compiler for production kernels....

What we should really do is properly abstract the btree stats
structure and put a pointer into the cursor so that the switch
statement can go away....

Cheers,

Dave.
-- 
Dave Chinner
david@fromorbit.com

_______________________________________________
xfs mailing list
xfs@oss.sgi.com
http://oss.sgi.com/mailman/listinfo/xfs

  reply	other threads:[~2014-08-21 22:55 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-08-21 17:32 [PATCH] xfsprogs: use abort() not ASSERT(0) for impossible switch case Eric Sandeen
2014-08-21 17:44 ` Christoph Hellwig
2014-08-21 17:45   ` Eric Sandeen
2014-08-21 18:27 ` [PATCH V2] xfsprogs: use ASSERT_ALWAYS " Eric Sandeen
2014-08-21 22:55   ` Dave Chinner [this message]
2014-08-21 22:50 ` [PATCH] xfsprogs: use abort() not ASSERT(0) " Dave Chinner

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=20140821225521.GR26465@dastard \
    --to=david@fromorbit.com \
    --cc=sandeen@sandeen.net \
    --cc=xfs@oss.sgi.com \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox