Re: [PATCH] Use a zero-size array in the struct devres

From: Tejun Heo
Date: Tue Mar 06 2007 - 07:44:45 EST


Hello, Catalin.

Catalin Marinas wrote:
> Commit 9ac7849e35f705830f7b016ff272b0ff1f7ff759 adds the devres
> structure containing a flexible unsigned long long array, with a
> comment about the guaranteed alignment. According to the gcc manual,
> flexible arrays are considered incomplete types and it is an error to
> ask for their alignment. This patch makes data[] a zero-size array.

The gcc manual says nothing about alignment. What it says is sizeof()
doesn't work. If flexible array doesn't honor the alignment of the
declared type, it would be useless for its designed purpose of
supporting *array* of dynamically-determined length.

> I came across this when trying to build kmemleak as the modified
> container_of macro tries to get the size of the devres.data member and
> sizeof cannot be applied to incomplete types.

If kmemleak's container_of cannot deal with the current struct devres,
it means it can't deal with flexible arrays at all. Flexible array
being the standard as opposed to 0 size array gcc extension, I guess a
lot of people would prefer flexible array.

It would be best if kmemleak's container_of can be modified to work with
flexible arrays. If that's not possible, I guess it needs wider
discussion to determine whether to ditch flexible array for kmemleak.

Thanks.

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