mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Felipe Balbi <balbi@ti.com>
To: Greg KH <gregkh@linuxfoundation.org>
Cc: Luciano Coelho <coelho@ti.com>,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>
Subject: container_of() doubt
Date: Wed, 27 Feb 2013 21:13:22 +0200	[thread overview]
Message-ID: <20130227191322.GA27264@arwen.pp.htv.fi> (raw)

[-- Attachment #1: Type: text/plain, Size: 888 bytes --]

Hi Greg,

hehe, you must've answered this over and over again, but I don't see the
need for __mptr in the container_of() macro. I tried googling it but
couldn't find much.

I get the macro, but not the need __mptr. Wouldn't this work the same
way ?

diff --git a/include/linux/kernel.h b/include/linux/kernel.h
index 80d3687..bbce857 100644
--- a/include/linux/kernel.h
+++ b/include/linux/kernel.h
@@ -717,8 +717,7 @@ static inline void ftrace_dump(enum ftrace_dump_mode oops_dump_mode) { }
  *
  */
 #define container_of(ptr, type, member) ({			\
-	const typeof( ((type *)0)->member ) *__mptr = (ptr);	\
-	(type *)( (char *)__mptr - offsetof(type,member) );})
+	(type *)( (char *)(ptr) - offsetof(type,member) );})
 
 /* Trap pasters of __FUNCTION__ at compile-time */
 #define __FUNCTION__ (__func__)

why do we need this type * NULL ?

thanks

-- 
balbi

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 836 bytes --]

             reply	other threads:[~2013-02-27 19:13 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-02-27 19:13 Felipe Balbi [this message]
2013-02-27 19:14 ` Felipe Balbi

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=20130227191322.GA27264@arwen.pp.htv.fi \
    --to=balbi@ti.com \
    --cc=coelho@ti.com \
    --cc=gregkh@linuxfoundation.org \
    --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

all inboxes | Powered by JetHome®