* [PATCH] linux/container_of.h: Remove redundant type cast in container_of_const()
@ 2024-08-02 15:15 Zijun Hu
2024-08-09 11:27 ` Andy Shevchenko
0 siblings, 1 reply; 5+ messages in thread
From: Zijun Hu @ 2024-08-02 15:15 UTC (permalink / raw)
To: Greg Kroah-Hartman
Cc: Jason Gunthorpe, Sakari Ailus, Matthew Wilcox (Oracle),
Andy Shevchenko, Rafael J. Wysocki, Zijun Hu, linux-kernel,
Zijun Hu
From: Zijun Hu <quic_zijuhu@quicinc.com>
Remove redundant (type *) cast for default branch in container_of_const()
since the cast has been done by container_of().
Signed-off-by: Zijun Hu <quic_zijuhu@quicinc.com>
---
include/linux/container_of.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/include/linux/container_of.h b/include/linux/container_of.h
index 713890c867be..c36435e7c7f2 100644
--- a/include/linux/container_of.h
+++ b/include/linux/container_of.h
@@ -32,7 +32,7 @@
#define container_of_const(ptr, type, member) \
_Generic(ptr, \
const typeof(*(ptr)) *: ((const type *)container_of(ptr, type, member)),\
- default: ((type *)container_of(ptr, type, member)) \
+ default: container_of(ptr, type, member) \
)
#endif /* _LINUX_CONTAINER_OF_H */
---
base-commit: 8400291e289ee6b2bf9779ff1c83a291501f017b
change-id: 20240802-container_of_const_fix-87ecdb71ba90
Best regards,
--
Zijun Hu <quic_zijuhu@quicinc.com>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] linux/container_of.h: Remove redundant type cast in container_of_const()
2024-08-02 15:15 [PATCH] linux/container_of.h: Remove redundant type cast in container_of_const() Zijun Hu
@ 2024-08-09 11:27 ` Andy Shevchenko
2024-08-09 12:04 ` Zijun Hu
` (2 more replies)
0 siblings, 3 replies; 5+ messages in thread
From: Andy Shevchenko @ 2024-08-09 11:27 UTC (permalink / raw)
To: Zijun Hu
Cc: Greg Kroah-Hartman, Jason Gunthorpe, Sakari Ailus,
Matthew Wilcox (Oracle),
Rafael J. Wysocki, linux-kernel, Zijun Hu
On Fri, Aug 02, 2024 at 11:15:15PM +0800, Zijun Hu wrote:
> From: Zijun Hu <quic_zijuhu@quicinc.com>
>
> 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.
...
> #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) \
> )
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] linux/container_of.h: Remove redundant type cast in container_of_const()
2024-08-09 11:27 ` Andy Shevchenko
@ 2024-08-09 12:04 ` Zijun Hu
2024-08-12 14:17 ` Sakari Ailus
2024-08-13 9:17 ` Greg Kroah-Hartman
2 siblings, 0 replies; 5+ messages in thread
From: Zijun Hu @ 2024-08-09 12:04 UTC (permalink / raw)
To: Andy Shevchenko
Cc: Greg Kroah-Hartman, Jason Gunthorpe, Sakari Ailus,
Matthew Wilcox (Oracle),
Rafael J. Wysocki, linux-kernel, Zijun Hu
On 2024/8/9 19:27, Andy Shevchenko wrote:
> On Fri, Aug 02, 2024 at 11:15:15PM +0800, Zijun Hu wrote:
>> From: Zijun Hu <quic_zijuhu@quicinc.com>
>>
>> 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.
>
my change is more obvious to say that container_of_const() is same as
container_of() for none const pointer parameter @ptr. it is simpler and
easier to understand.
> ...
>
>> #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)
>
yes, for above case, (const type *) is suitable and required.
>> - default: ((type *)container_of(ptr, type, member)) \
>> + default: container_of(ptr, type, member) \
>> )
>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] linux/container_of.h: Remove redundant type cast in container_of_const()
2024-08-09 11:27 ` Andy Shevchenko
2024-08-09 12:04 ` Zijun Hu
@ 2024-08-12 14:17 ` Sakari Ailus
2024-08-13 9:17 ` Greg Kroah-Hartman
2 siblings, 0 replies; 5+ messages in thread
From: Sakari Ailus @ 2024-08-12 14:17 UTC (permalink / raw)
To: Andy Shevchenko
Cc: Zijun Hu, Greg Kroah-Hartman, Jason Gunthorpe,
Matthew Wilcox (Oracle),
Rafael J. Wysocki, linux-kernel, Zijun Hu
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@quicinc.com>
> >
> > 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
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] linux/container_of.h: Remove redundant type cast in container_of_const()
2024-08-09 11:27 ` Andy Shevchenko
2024-08-09 12:04 ` Zijun Hu
2024-08-12 14:17 ` Sakari Ailus
@ 2024-08-13 9:17 ` Greg Kroah-Hartman
2 siblings, 0 replies; 5+ messages in thread
From: Greg Kroah-Hartman @ 2024-08-13 9:17 UTC (permalink / raw)
To: Andy Shevchenko
Cc: Zijun Hu, Jason Gunthorpe, Sakari Ailus, Matthew Wilcox (Oracle),
Rafael J. Wysocki, linux-kernel, Zijun Hu
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@quicinc.com>
> >
> > 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.
Which is why I did it this way. It's safe to keep as-is, so let's do so
please.
Remember, we write code for people first, compilers second. There's
nothing wrong with the code as-is and it makes it more obvious what is
happening when someone reads it.
thanks,
greg k-h
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2024-08-13 9:17 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-08-02 15:15 [PATCH] linux/container_of.h: Remove redundant type cast in container_of_const() Zijun Hu
2024-08-09 11:27 ` Andy Shevchenko
2024-08-09 12:04 ` Zijun Hu
2024-08-12 14:17 ` Sakari Ailus
2024-08-13 9:17 ` Greg Kroah-Hartman
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®