From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([140.186.70.92]:48670) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QlHBx-00060y-2Z for qemu-devel@nongnu.org; Mon, 25 Jul 2011 05:11:13 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1QlHBw-0005pH-8D for qemu-devel@nongnu.org; Mon, 25 Jul 2011 05:11:12 -0400 Received: from mx1.redhat.com ([209.132.183.28]:48387) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QlHBv-0005p6-TY for qemu-devel@nongnu.org; Mon, 25 Jul 2011 05:11:12 -0400 Message-ID: <4E2D332C.3020004@redhat.com> Date: Mon, 25 Jul 2011 11:11:08 +0200 From: Paolo Bonzini MIME-Version: 1.0 References: <1310742615-23901-1-git-send-email-pbonzini@redhat.com> <4E2AEF1B.8020101@redhat.com> In-Reply-To: <4E2AEF1B.8020101@redhat.com> Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH] report serial devices created with -device in the PIIX4 config space List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Anthony Liguori Cc: =?windows-1252?Q?Andreas_F=E4rber?= , QEMU Developers , Gleb Natapov , Markus Armbruster >>> +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