[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-devel] [PATCH] report serial devices created with -device in t
From: |
Paolo Bonzini |
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 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:5.0) Gecko/20110707 Thunderbird/5.0 |
+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
Re: [Qemu-devel] [PATCH] report serial devices created with -device in the PIIX4 config space, Anthony Liguori, 2011/07/23