All the mail mirrored from lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] xfsprogs: use abort() not ASSERT(0) for impossible switch case
@ 2014-08-21 17:32 Eric Sandeen
  2014-08-21 17:44 ` Christoph Hellwig
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Eric Sandeen @ 2014-08-21 17:32 UTC (permalink / raw
  To: xfs-oss

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 with abort().

Signed-off-by: Eric Sandeen <sandeen@redhat.com>
---

diff --git a/include/xfs_btree.h b/include/xfs_btree.h
index 2590d40..f4a1f61 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: abort(); /* 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: abort(); /* fucking gcc */ ; break;	\
 	}       \
 } while (0)
 

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

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

* Re: [PATCH] xfsprogs: use abort() not ASSERT(0) for impossible switch case
  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:50 ` [PATCH] xfsprogs: use abort() not ASSERT(0) " Dave Chinner
  2 siblings, 1 reply; 6+ messages in thread
From: Christoph Hellwig @ 2014-08-21 17:44 UTC (permalink / raw
  To: Eric Sandeen; +Cc: xfs-oss

On Thu, Aug 21, 2014 at 12:32: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 with abort().

This won't work in kernel space, and we'd like to keep this file in sync.

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

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

* Re: [PATCH] xfsprogs: use abort() not ASSERT(0) for impossible switch case
  2014-08-21 17:44 ` Christoph Hellwig
@ 2014-08-21 17:45   ` Eric Sandeen
  0 siblings, 0 replies; 6+ messages in thread
From: Eric Sandeen @ 2014-08-21 17:45 UTC (permalink / raw
  To: Christoph Hellwig; +Cc: xfs-oss

On 8/21/14, 12:44 PM, Christoph Hellwig wrote:
> On Thu, Aug 21, 2014 at 12:32: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 with abort().
> 
> This won't work in kernel space, and we'd like to keep this file in sync.

Ah, right, sorry - spaced out that it was shared.

I'll add ASSERT_ALWAYS() to userspace then, perhaps.

Thanks,
-Eric

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

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

* [PATCH V2] xfsprogs: use ASSERT_ALWAYS for impossible switch case
  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 18:27 ` Eric Sandeen
  2014-08-21 22:55   ` Dave Chinner
  2014-08-21 22:50 ` [PATCH] xfsprogs: use abort() not ASSERT(0) " Dave Chinner
  2 siblings, 1 reply; 6+ messages in thread
From: Eric Sandeen @ 2014-08-21 18:27 UTC (permalink / raw
  To: xfs-oss

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)
 
diff --git a/libxfs/xfs.h b/libxfs/xfs.h
index 30a316d..81d7cd9 100644
--- a/libxfs/xfs.h
+++ b/libxfs/xfs.h
@@ -48,6 +48,10 @@
 #undef ASSERT
 #define ASSERT(ex) assert(ex)
 
+#undef ASSERT_ALWAYS
+#define ASSERT_ALWAYS(ex) \
+	(unlikely(ex) ? (void)0 : abort())
+
 typedef __uint32_t		uint_t;
 typedef __uint32_t		inst_t;		/* an instruction */
 

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

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

* Re: [PATCH] xfsprogs: use abort() not ASSERT(0) for impossible switch case
  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 18:27 ` [PATCH V2] xfsprogs: use ASSERT_ALWAYS " Eric Sandeen
@ 2014-08-21 22:50 ` Dave Chinner
  2 siblings, 0 replies; 6+ messages in thread
From: Dave Chinner @ 2014-08-21 22:50 UTC (permalink / raw
  To: Eric Sandeen; +Cc: xfs-oss

On Thu, Aug 21, 2014 at 12:32:02PM -0500, Eric Sandeen wrote:
> The original reason for the expletive below has been lost
> in the mists of time

Oh, no it hasn't.

That's a switch statement using enums for the cases and so if you
don't define every enum value in the switch statement gcc throws
warnings. IOWs, the switch statement has to either define them all or
contain a "default" case, either of which *does not need to exist* because
other code guarantees that the value of cur->bc_btnum is within
the valid range.

So, we have to put an invalid value into the switch statement to
make gcc shut the fuck up, and the ASSERT(0) is there to indicate
that "this should never, ever happen".

> 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 with abort().

Random differences between kernel and user code to keep static
analysis checkers happy is not a good road to follow, because it
will just cause patch failures and people wondering "why is this
randomly different to the kernel code?". So, no, I don't really like
this approach.

Cheers,

Dave.
-- 
Dave Chinner
david@fromorbit.com

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

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

* Re: [PATCH V2] xfsprogs: use ASSERT_ALWAYS for impossible switch case
  2014-08-21 18:27 ` [PATCH V2] xfsprogs: use ASSERT_ALWAYS " Eric Sandeen
@ 2014-08-21 22:55   ` Dave Chinner
  0 siblings, 0 replies; 6+ messages in thread
From: Dave Chinner @ 2014-08-21 22:55 UTC (permalink / raw
  To: Eric Sandeen; +Cc: xfs-oss

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

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

end of thread, other threads:[~2014-08-21 22:55 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
2014-08-21 22:50 ` [PATCH] xfsprogs: use abort() not ASSERT(0) " Dave Chinner

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.