[prev in list] [next in list] [prev in thread] [next in thread] 

List:       linux-kernel
Subject:    Re: ABI violations eventually caused by short sighted coding style
From:       "H. Peter Anvin" <hpa () zytor ! com>
Date:       2013-01-31 23:21:14
Message-ID: 510AFC6A.5030703 () zytor ! com
[Download RAW message or body]

On 01/31/2013 02:20 PM, Jon Pry wrote:
> 
> I believe changes should be made to the coding style forcing developers to take
> action. There are a couple of solutions I can think of:
> 
> 1. 	Put the unions at the beginning of structures if possible, or at least put
> 	them in a position that would ensure 8 byte offset from the beginning of
> 	the struct. Such as after a u64. Multiple unions should ensure the data[]
> 	of the preceding unions to be a multiple of 8 bytes.
> 2.  Require the data element to be declared as u64[size/8].
> 3.  Pack the ioctl structures
> 
> My preference is for the former since it does not cause any
> unnecessary padding.
> 

"The former" doesn't work when you are talking about a choice of three
elements.

packed structures are *very* expensive to use on some architectures, so
that is not a good solution.

In many, if not most cases, this is actually better handled by having
different ioctl numbers for each version/interface, but if you have to
make it self-contained, it makes most sense to make the common portion a
u64 or explicitly align the union to u64.

Another thing to keep in mind is that it often makes a lot more sense to
have a length member, and skip the problematic union.  That way a future
version of the kernel can simply memset() the part of the structure that
isn't initialized, and doesn't need a huge apparatus to keep track of
each individual version.

	-hpa



--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic