From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from [140.186.70.92] (port=57650 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OOJy6-0004mQ-Fw for qemu-devel@nongnu.org; Mon, 14 Jun 2010 20:25:35 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1OOJy3-0006N3-18 for qemu-devel@nongnu.org; Mon, 14 Jun 2010 20:25:28 -0400 Received: from mail.codesourcery.com ([38.113.113.100]:46914) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OOJy2-0006Mo-Oa for qemu-devel@nongnu.org; Mon, 14 Jun 2010 20:25:26 -0400 From: Paul Brook Subject: Re: [Qemu-devel] [PATCH v2 2/7] ioapic: convert to qdev Date: Tue, 15 Jun 2010 01:25:22 +0100 References: In-Reply-To: MIME-Version: 1.0 Content-Type: Text/Plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <201006150125.22743.paul@codesourcery.com> List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Blue Swirl , Markus Armbruster > >> -static void ioapic_reset(void *opaque) > >> +static void ioapic_reset(DeviceState *d) > >> { > >> - IOAPICState *s = opaque; > >> + IOAPICState *s = container_of(d, IOAPICState, busdev.qdev); > > > > DO_UPCAST()? I hate it, but it's what the other devices do... > > Both are used: > grep container_of hw/*.[ch]|wc -l > 81 > grep DO_UPCAST hw/*.[ch]|wc -l > 246 Which is appropriate depends on the context. DO_UPCAST is appropriate when we're dealing with polymorphic types. In this case IOAPICState is derived from DeviceState (via SysBusDevice). There is an implicit assumption that these are all the same object, so DO_UPCAST is approprate. container_of is approriate when we're embedding one object in annother, but without any inheritance relationship between the two. Paul