Re: [PATCH] linux/container_of.h: Remove redundant type cast in container_of_const()
From: Sakari Ailus
Date: Mon Aug 12 2024 - 10:17:45 EST
Hi Andy, Zijun,
On Fri, Aug 09, 2024 at 02:27:23PM +0300, Andy Shevchenko wrote:
> On Fri, Aug 02, 2024 at 11:15:15PM +0800, Zijun Hu wrote:
> > From: Zijun Hu <quic_zijuhu@xxxxxxxxxxx>
> >
> > Remove redundant (type *) cast for default branch in container_of_const()
> > since the cast has been done by container_of().
>
> While it might have same effect, the below is explicitly clear about both
> cases. With your patch it will become inconsistent.
In the const case it's actually required whereas container_of() already
does exactly the same cast, rendering the cast done below redundant.
There's nothing inconsistent in removing a needless cast.
Removing it is my preference as well.
>
> ...
>
> > #define container_of_const(ptr, type, member) \
> > _Generic(ptr, \
> > const typeof(*(ptr)) *: ((const type *)container_of(ptr, type, member)),\
>
> (see, in the above line the cast is still present / required)
>
> > - default: ((type *)container_of(ptr, type, member)) \
> > + default: container_of(ptr, type, member) \
> > )
>
--
Kind regards,
Sakari Ailus