linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Alexey Dobriyan <adobriyan@gmail.com>
To: dhowells@redhat.com
Cc: linux-kernel@vger.kernel.org
Subject: Re: [PATCH 34/45] C++: Fix up use of LIST_POISON*
Date: Mon, 2 Apr 2018 00:28:16 +0300	[thread overview]
Message-ID: <20180401212816.GA25507@avx2> (raw)

> -	entry->next = LIST_POISON1;
> -	entry->prev = LIST_POISON2;
> +	entry->next = static_cast<struct list_head *>(LIST_POISON1);
> +	entry->prev = static_cast<struct list_head *>(LIST_POISON2);

There is a better way ;-)

--- a/include/linux/poison.h
+++ b/include/linux/poison.h
@@ -2,6 +2,22 @@
 #ifndef _LINUX_POISON_H
 #define _LINUX_POISON_H
 
+class POISON {
+	unsigned long p;
+
+public:
+	explicit POISON(unsigned long val)
+		: p{val}
+	{
+	}
+
+	template<typename T>
+	operator T*() const
+	{
+		return p;
+	}
+};
+
 /********** include/linux/list.h **********/
 
 /*
@@ -20,15 +36,15 @@
  * under normal circumstances, used to verify that nobody uses
  * non-initialized list entries.
  */
-#define LIST_POISON1  ((void *) 0x100 + POISON_POINTER_DELTA)
-#define LIST_POISON2  ((void *) 0x200 + POISON_POINTER_DELTA)
+#define LIST_POISON1  POISON{0x100UL + POISON_POINTER_DELTA}
+#define LIST_POISON2  POISON{0x200UL + POISON_POINTER_DELTA}
 
 /********** include/linux/timer.h **********/
 /*
  * Magic number "tsta" to indicate a static timer initializer
  * for the object debugging code.
  */
-#define TIMER_ENTRY_STATIC	((void *) 0x300 + POISON_POINTER_DELTA)
+#define TIMER_ENTRY_STATIC	POISON{0x300UL + POISON_POINTER_DELTA}
 
 /********** mm/debug-pagealloc.c **********/
 #ifdef CONFIG_PAGE_POISONING_ZERO
@@ -39,7 +55,7 @@
 
 /********** mm/page_alloc.c ************/
 
-#define TAIL_MAPPING	((void *) 0x400 + POISON_POINTER_DELTA)
+#define TAIL_MAPPING	POISON{0x400UL + POISON_POINTER_DELTA}
 
 /********** mm/slab.c **********/
 /*
@@ -81,7 +97,7 @@
 /********** kernel/mutexes **********/
 #define MUTEX_DEBUG_INIT	0x11
 #define MUTEX_DEBUG_FREE	0x22
-#define MUTEX_POISON_WW_CTX	((void *) 0x500 + POISON_POINTER_DELTA)
+#define MUTEX_POISON_WW_CTX	POISON{0x500UL + POISON_POINTER_DELTA}
 
 /********** lib/flex_array.c **********/
 #define FLEX_ARRAY_FREE	0x6c	/* for use-after-free poisoning */

             reply	other threads:[~2018-04-01 21:28 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-04-01 21:28 Alexey Dobriyan [this message]
  -- strict thread matches above, loose matches on Subject: below --
2018-04-01 20:40 [PATCH 00/45] C++: Convert the kernel to C++ David Howells
2018-04-01 20:43 ` [PATCH 34/45] C++: Fix up use of LIST_POISON* David Howells

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=20180401212816.GA25507@avx2 \
    --to=adobriyan@gmail.com \
    --cc=dhowells@redhat.com \
    --cc=linux-kernel@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).