public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Jason Gunthorpe <jgg@mellanox.com>
To: "linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	NeilBrown <neilb@suse.com>, Jiri Kosina <trivial@kernel.org>
Subject: [PATCH trivial] kernel.h: Make container_of_safe type safe
Date: Thu, 24 Jan 2019 20:55:05 +0000	[thread overview]
Message-ID: <20190124205451.GA19634@ziepe.ca> (raw)

The final ternary expression is given void * and type * as arguments, so
the resulting type of the macro ends up being void *.

container_of returns a type which maches the argument, this provides type
safety and allows the expression to be immediately used as the target
type.

Explicitly cast ERR_CAST() to get the correct type.

Fixes: 05e6557b8ed8 ("staging: lustre: add container_of_safe()")
Signed-off-by: Jason Gunthorpe <jgg@mellanox.com>
---
 include/linux/kernel.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Jiri, can you take this? Thanks

Jason

diff --git a/include/linux/kernel.h b/include/linux/kernel.h
index 8f0e68e250a760..7b85aa607eb876 100644
--- a/include/linux/kernel.h
+++ b/include/linux/kernel.h
@@ -1013,7 +1013,7 @@ static inline void ftrace_dump(enum ftrace_dump_mode oops_dump_mode) { }
 	BUILD_BUG_ON_MSG(!__same_type(*(ptr), ((type *)0)->member) &&	\
 			 !__same_type(*(ptr), void),			\
 			 "pointer type mismatch in container_of()");	\
-	IS_ERR_OR_NULL(__mptr) ? ERR_CAST(__mptr) :			\
+	IS_ERR_OR_NULL(__mptr) ? ((type *)ERR_CAST(__mptr)) :		\
 		((type *)(__mptr - offsetof(type, member))); })
 
 /* Rebuild everything on CONFIG_FTRACE_MCOUNT_RECORD */
-- 
2.20.1


             reply	other threads:[~2019-01-24 20:55 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-01-24 20:55 Jason Gunthorpe [this message]
2019-01-28 13:42 ` [PATCH trivial] kernel.h: Make container_of_safe type safe Christoph Hellwig
2019-01-28 18:44   ` Jason Gunthorpe
2019-01-29  7:40     ` Christoph Hellwig

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=20190124205451.GA19634@ziepe.ca \
    --to=jgg@mellanox.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=neilb@suse.com \
    --cc=trivial@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