[lkml]   [2018]   [May]   [16]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
Messages in this thread
SubjectRe: [PATCH v3] device property: Get rid of union aliasing
On Tue, May 15, 2018 at 08:32:02PM +0300, Andy Shevchenko wrote:
> The commit
> 318a19718261 ("device property: refactor built-in properties support")
> went way too far and brought a union aliasing. Partially revert it here
> to get rid of union aliasing.
> Note, all Apple properties are considered as u8 arrays. To get a value
> of any of them the caller must use device_property_read_u8_array().
> What union aliasing is?
> ~~~~~~~~~~~~~~~~~~~~~~~
> The C99 standard in section 6.2.5 paragraph 20 defines union type as
> "an overlapping nonempty set of member objects". It also states in
> section paragraph 14 that "the value of at most one of the
> members can be stored in a union object at any time'.
> Union aliasing is a type punning mechanism using union members to store
> as one type and read back as another.
> Why it's not good?
> ~~~~~~~~~~~~~~~~~~
> Section paragraph 6 says that a union object may not be a trap
> representation, although its member objects may be.
> Meanwhile annex J.1 says that "the value of a union member other than
> the last one stored into" is unspecified [removed in C11].
> In TC3, a footnote is added which specifies that accessing a member of a
> union other than the last one stored causes "the object representation"
> to be re-interpreted in the new type and specifically refers to this as
> "type punning". This conflicts to some degree with Annex J.1.
> While it's working in Linux with GCC, the use of union members to do
> type punning is not clear area in the C standard and might lead to
> unspecified behaviour.
> More information is available in this [1] blog post.
> [1]:
> Acked-by: Ard Biesheuvel <>
> Signed-off-by: Andy Shevchenko <>

Reviewed-by: Mika Westerberg <>

 \ /
  Last update: 2018-05-16 11:42    [W:0.066 / U:4.048 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site