All of lore.kernel.org
 help / color / mirror / Atom feed
From: Paolo Bonzini <pbonzini@redhat.com>
To: Anthony Liguori <anthony@codemonkey.ws>
Cc: "Andreas Färber" <andreas.faerber@web.de>,
	"QEMU Developers" <qemu-devel@nongnu.org>,
	"Gleb Natapov" <gleb@redhat.com>,
	"Markus Armbruster" <armbru@redhat.com>
Subject: Re: [Qemu-devel] [PATCH] report serial devices created with -device in the PIIX4 config space
Date: Mon, 25 Jul 2011 11:11:08 +0200	[thread overview]
Message-ID: <4E2D332C.3020004@redhat.com> (raw)
In-Reply-To: <4E2AEF1B.8020101@redhat.com>


>>> +static void piix4_pm_machine_ready(struct Notifier* n)
>>> +{
>>> + PIIX4PMState *s = container_of(n, PIIX4PMState, machine_ready);
>>
>> DO_UPCAST()? I assume we have it for a reason.
>
> NIH is the reason we have it.

DO_UPCAST checks that the offset of the field is zero:

#ifdef __GNUC__
#define DO_UPCAST(type, field, dev) ( __extension__ ( { \
     char __attribute__((unused)) offset_must_be_zero[ \
         -offsetof(type, field)]; \
     container_of(dev, type, field);}))
#else
#define DO_UPCAST(type, field, dev) container_of(dev, type, field)
#endif

This isn't the case here, we really want container_of.

BTW, DO_UPCAST actually is used to do a _down_cast (base to derived).  A 
compile-time checked upcast (derived to base) could be done like this:

#ifdef __GNUC__
#define DO_UPCAST(type, field, dev) ( __extension__ ( { \
     char __attribute__((unused)) offset_must_be_zero[ \
         -offsetof(type, field)]; \
     char __attribute__((unused)) type_matches = \
         type_check(type, __typeof__(dev));
     &(dev)->field);}))
#else
#define DO_UPCAST(type, field, dev) &(dev)->field
#endif

Paolo

  reply	other threads:[~2011-07-25  9:11 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-07-15 15:10 [Qemu-devel] [PATCH] report serial devices created with -device in the PIIX4 config space Paolo Bonzini
2011-07-15 21:00 ` Andreas Färber
2011-07-23 15:56   ` Anthony Liguori
2011-07-25  9:11     ` Paolo Bonzini [this message]
2011-07-16 14:39 ` Anthony Liguori
2011-07-24 18:45   ` Paolo Bonzini
2011-07-24 18:57     ` Anthony Liguori
2011-07-24 21:35       ` Andreas Färber
2011-07-25  1:45         ` Anthony Liguori
2011-07-25  6:33           ` Paolo Bonzini
2011-07-23 16:14 ` Anthony Liguori

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=4E2D332C.3020004@redhat.com \
    --to=pbonzini@redhat.com \
    --cc=andreas.faerber@web.de \
    --cc=anthony@codemonkey.ws \
    --cc=armbru@redhat.com \
    --cc=gleb@redhat.com \
    --cc=qemu-devel@nongnu.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.