mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] simplify container_of_const()
@ 2024-07-19 19:19 Alexey Dobriyan
  2024-07-19 19:29 ` Alexey Dobriyan
  0 siblings, 1 reply; 2+ messages in thread
From: Alexey Dobriyan @ 2024-07-19 19:19 UTC (permalink / raw)
  To: akpm; +Cc: linux-kernel, andriy.shevchenko

* add necessary parenthesis so that

	container_of_const((expr1, expr2), T, member)

  compiles without warnings,

* delete unnecessary parenthesis,

* delete unnecessary cast:

	container_of(ptr, T, member)

  has type "T*" and doesn't need any more casts.

Signed-off-by: Alexey Dobriyan <adobriyan@gmail.com>
---

 include/linux/container_of.h |    6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

--- a/include/linux/container_of.h
+++ b/include/linux/container_of.h
@@ -30,9 +30,9 @@
  * @member:		the name of the member within the struct.
  */
 #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))	\
+	_Generic((ptr),							\
+		const typeof(*(ptr)) *: (const type *)container_of(ptr, type, member),\
+		default: container_of(ptr, type, member)		\
 	)
 
 #endif	/* _LINUX_CONTAINER_OF_H */

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] simplify container_of_const()
  2024-07-19 19:19 [PATCH] simplify container_of_const() Alexey Dobriyan
@ 2024-07-19 19:29 ` Alexey Dobriyan
  0 siblings, 0 replies; 2+ messages in thread
From: Alexey Dobriyan @ 2024-07-19 19:29 UTC (permalink / raw)
  To: akpm; +Cc: linux-kernel, andriy.shevchenko

On Fri, Jul 19, 2024 at 10:19:37PM +0300, Alexey Dobriyan wrote:
> * add necessary parenthesis so that
> 
> 	container_of_const((expr1, expr2), T, member)
> 
>   compiles without warnings,

This part is bogus, I'm not sure why I wrote this.

> --- a/include/linux/container_of.h
> +++ b/include/linux/container_of.h
> @@ -30,9 +30,9 @@
>   * @member:		the name of the member within the struct.
>   */
>  #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))	\
> +	_Generic((ptr),							\

someone could sneak in additional clause...

> +		const typeof(*(ptr)) *: (const type *)container_of(ptr, type, member),\
> +		default: container_of(ptr, type, member)		\

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2024-07-19 19:29 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-07-19 19:19 [PATCH] simplify container_of_const() Alexey Dobriyan
2024-07-19 19:29 ` Alexey Dobriyan

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®