linux-arch.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Mike Rapoport <rppt@kernel.org>
To: Chunguang Xu <brookxu.cn@gmail.com>
Cc: arnd@arndb.de, linux-arch@vger.kernel.org
Subject: Re: [PATCH 1/1] include/asm-generic/bug.h: add ASSERT_FAIL() and ASSERT_WARN() wrapper
Date: Thu, 27 Aug 2020 09:24:31 +0300	[thread overview]
Message-ID: <20200827062431.GC69706@kernel.org> (raw)
In-Reply-To: <7d916ac76e7823efbf88828dc6c61737555434a1.1598481550.git.brookxu@tencent.com>

On Thu, Aug 27, 2020 at 07:04:53AM +0800, Chunguang Xu wrote:
> The kernel has not yet defined ASSERT(). Indeed, BUG() and WARN() are very
> clear and can cover most application scenarios. However, some applications
> require more debugging information and similar behavior to assert(), which
> cannot be directly provided by BUG() and WARN().
> 
> Therefore, many modules independently implement ASSERT(), and most of them
> are similar, but slightly different. This makes the code redundant and
> inconvenient to troubleshoot the system. Therefore, perhaps we need to
> define two wrappers for BUG() and WARN(), provide the implementation of
> ASSERT(), simplify the code and facilitate problem analysis.
> 
> Signed-off-by: Chunguang Xu <brookxu@tencent.com>
> ---
>  include/asm-generic/bug.h | 33 +++++++++++++++++++++++++++++++++
>  1 file changed, 33 insertions(+)

It would be useful to convert at least one occurrence of the existing
ASSERT()s to the new implementation in the same patch series.

> diff --git a/include/asm-generic/bug.h b/include/asm-generic/bug.h
> index 18b0f4e..28f8c27 100644
> --- a/include/asm-generic/bug.h
> +++ b/include/asm-generic/bug.h
> @@ -174,6 +174,31 @@ void __warn(const char *file, int line, void *caller, unsigned taint,
>  	unlikely(__ret_warn_once);				\
>  })
>  
> +/*
> + * ASSERT_FAIL() and ASSERT_WARN() can be used to check whether some
> + * conditions have failed. We generally use ASSERT_FAIL() to check
> + * critical conditions, and other use ASSERT_WARN().
> + */
> +#ifndef ASSERT_FAIL
> +#define ASSERT_FAIL(condition) do {					\
> +	if (unlikely(!(condition))) {					\
> +		pr_emerg("Assertion failed: %s, file: %s, line: %d\n",	\
> +			  #condition, __FILE__, __LINE__);		\
> +		BUG();							\
> +	}								\
> +} while (0)
> +#endif
> +
> +#ifndef ASSERT_WARN
> +#define ASSERT_WARN(condition) do {					\
> +	if (unlikely(!(condition))) {					\
> +		pr_warn("Assertion failed: %s, file: %s, line: %d\n",	\
> +			 #condition, __FILE__, __LINE__);		\
> +		WARN_ON(1);						\
> +	}								\
> +} while (0)
> +#endif
> +
>  #else /* !CONFIG_BUG */
>  #ifndef HAVE_ARCH_BUG
>  #define BUG() do {} while (1)
> @@ -203,6 +228,14 @@ void __warn(const char *file, int line, void *caller, unsigned taint,
>  #define WARN_TAINT(condition, taint, format...) WARN(condition, format)
>  #define WARN_TAINT_ONCE(condition, taint, format...) WARN(condition, format)
>  
> +#ifndef ASSERT_FAIL
> +#define ASSERT_FAIL(condition) do { } while (0)
> +#endif
> +
> +#ifndef ASSERT_WARN
> +#define ASSERT_WARN(condition) do { } while (0)
> +#endif
> +
>  #endif
>  
>  /*
> -- 
> 1.8.3.1
> 

-- 
Sincerely yours,
Mike.

  reply	other threads:[~2020-08-27  6:24 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-08-26 23:04 [PATCH 0/1] clean up the code related to ASSERT() Chunguang Xu
2020-08-26 23:04 ` [PATCH 1/1] include/asm-generic/bug.h: add ASSERT_FAIL() and ASSERT_WARN() wrapper Chunguang Xu
2020-08-27  6:24   ` Mike Rapoport [this message]
2020-08-27 16:32 ` [PATCH 0/1] clean up the code related to ASSERT() Arnd Bergmann

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=20200827062431.GC69706@kernel.org \
    --to=rppt@kernel.org \
    --cc=arnd@arndb.de \
    --cc=brookxu.cn@gmail.com \
    --cc=linux-arch@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).