qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-devel] Re: [PATCH 06/41] virtio: Use DO_UPCAST instead of a cast


From: Juan Quintela
Subject: [Qemu-devel] Re: [PATCH 06/41] virtio: Use DO_UPCAST instead of a cast
Date: Thu, 03 Dec 2009 12:56:57 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux)

"Michael S. Tsirkin" <address@hidden> wrote:
> On Wed, Dec 02, 2009 at 08:03:22PM +0100, Juan Quintela wrote:
>> "Michael S. Tsirkin" <address@hidden> wrote:
>> 
>> > I don't understand.
>> > container_of is just more generic than DO_UPCAST.
>> > So why *ever* use DO_UPCAST? Let's get rid of it.

....

>> See how you create a device of size struct_size, but then you access it
>> with vdev.  If vdev is _not_ the 1st element of the struct, you have got
>> corruption.
>
> A cleaner solution IMO would be to have callers allocate the memory
> and pass VirtIODevice * to virtio_common_init.

Been there, asked for that.  Basically qdev + passing initialized memory
= nono

>>  DO_UPCAST() prevent you for having that error.
>
>
> If we want to assert specific structure layout, this
> should be a compile-time check. There's no
> reason to do this check every time at a random place where
> DO_UPCAST is called.

See DO_UPCAST() definition :)


It is a compile time check.  It just do cpp magic to be sure that things
are right.  DO_UPCAST() == (cast *) with some typechecking.

>> container_of() would have leave you go around, and have a memory
>> corruption not easy to fix.
>> 
>> DO_UPCAST() macro was created just to avoid this kind of errors.
>> 
>> Later, Juan.





reply via email to

[Prev in Thread] Current Thread [Next in Thread]