Re: [PATCH] linux/kernel.h: add container_from()

From: Rasmus Villemoes
Date: Thu Aug 27 2020 - 14:08:09 EST


On 27/08/2020 03.36, Allen Pais wrote:
> Introduce container_from() as a generic helper instead of
> sub-systems defining a private from_* API
> (Eg: from_tasklets recently introduced in
> 12cc923f1ccc: Tasklet: Introduce new initialization API)
>
> The helper is similar to container_of() in argument order
> with the difference of naming the containing structure instead
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

> of having to specify its type.
>

> +/**
> + * container_from - cast a member of a structure out to the containing structure
> + * @ptr: the pointer to the member.
> + * @container: the type of the container struct.
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
This seems to have been copy-pasted from container_of? Shouldn't
@container be the (local) value we're storing into? As in foo =
container_from(..., foo, ...)? Or am I misunderstanding the purpose of this?

[And I think it would read nicer if the bikeshed was called
to_container(), but don't care deeply.]

Rasmus