Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1467619

Re: [PATCH v3 4/5] bug: Provide toggle for BUG on data corruption

From Arnd Bergmann <arnd@arndb.de>
Newsgroups linux.kernel
Subject Re: [PATCH v3 4/5] bug: Provide toggle for BUG on data corruption
Date 2016-08-22 15:20 +0200
Message-ID <s8XiW-6LP-35@gated-at.bofh.it> (permalink)
References <s7gSJ-6Zu-3@gated-at.bofh.it> <s7gSK-6Zu-19@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


On Wednesday, August 17, 2016 2:42:11 PM CEST Kees Cook wrote:
> +
> +/*
> + * Since detected data corruption should stop operation on the affected
> + * structures, this returns false if the corruption condition is found.
> + */
> +#define CHECK_DATA_CORRUPTION(condition, fmt, ...)                      \
> +       do {                                                             \
> +               if (unlikely(condition)) {                               \
> +                       if (IS_ENABLED(CONFIG_BUG_ON_DATA_CORRUPTION)) { \
> +                               pr_err(fmt, ##__VA_ARGS__);              \
> +                               BUG();                                   \
> +                       } else                                           \
> +                               WARN(1, fmt, ##__VA_ARGS__);             \
> +                       return false;                                    \
> +               }                                                        \
> +       } while (0)
> +

I think the "return false" inside of the macro makes it easy to misread
what is actually going on.

How about making it a macro that returns the condition argument?

#define CHECK_DATA_CORRUPTION(condition, fmt, ...)	\
({	\
	bool _condition = unlikely(condition);	\
	if (_condition) {	\
		...
	}	\
	_condition;	\
})

	Arnd

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

[PATCH v3 0/5] bug: Provide toggle for BUG on data corruption Kees Cook <keescook@chromium.org> - 2016-08-17 23:50 +0200
  [PATCH v3 4/5] bug: Provide toggle for BUG on data corruption Kees Cook <keescook@chromium.org> - 2016-08-17 23:50 +0200
    Re: [PATCH v3 4/5] bug: Provide toggle for BUG on data corruption Arnd Bergmann <arnd@arndb.de> - 2016-08-22 15:20 +0200
      Re: [PATCH v3 4/5] bug: Provide toggle for BUG on data corruption "Paul E. McKenney" <paulmck@linux.vnet.ibm.com> - 2016-08-22 20:00 +0200
        Re: [kernel-hardening] Re: [PATCH v3 4/5] bug: Provide toggle for BUG  on data corruption Kees Cook <keescook@chromium.org> - 2016-08-23 00:40 +0200
  Re: [PATCH v3 0/5] bug: Provide toggle for BUG on data corruption Steven Rostedt <rostedt@goodmis.org> - 2016-08-18 15:50 +0200
    Re: [PATCH v3 0/5] bug: Provide toggle for BUG on data corruption "Paul E. McKenney" <paulmck@linux.vnet.ibm.com> - 2016-08-19 03:10 +0200
  Re: [kernel-hardening] [PATCH v3 0/5] bug: Provide toggle for BUG  on data corruption Rik van Riel <riel@redhat.com> - 2016-08-19 03:00 +0200
    Re: [kernel-hardening] [PATCH v3 0/5] bug: Provide toggle for BUG on  data corruption "Paul E. McKenney" <paulmck@linux.vnet.ibm.com> - 2016-08-19 03:30 +0200
      Re: [kernel-hardening] [PATCH v3 0/5] bug: Provide toggle for BUG  on data corruption Rik van Riel <riel@redhat.com> - 2016-08-19 05:00 +0200
        Re: [kernel-hardening] [PATCH v3 0/5] bug: Provide toggle for BUG on  data corruption "Paul E. McKenney" <paulmck@linux.vnet.ibm.com> - 2016-08-19 19:50 +0200

csiph-web