* [PATCH 1/1] checkpatch: Deprecate container_of() in favour of container_of_const()
@ 2025-08-11 8:57 Sakari Ailus
2025-08-11 9:05 ` Greg Kroah-Hartman
2025-11-05 8:08 ` Sakari Ailus
0 siblings, 2 replies; 6+ messages in thread
From: Sakari Ailus @ 2025-08-11 8:57 UTC (permalink / raw)
To: linux-kernel
Cc: Andy Whitcroft, Joe Perches, Dwaipayan Ray, Lukas Bulwahn,
Greg Kroah-Hartman
container_of() discards constness of its first argument and thus its use
may result in inadvertly unconstifying an object that is const. While
container_of_const() addresses this problem, the vast majority of new uses
of the two use the container_of() variant lacking the check.
Stem the flow of new container_of() use by adding it to the list of
deprecated functions in scripts/checkpatch.pl. Once all existing
container_of() users have been fixed to respect the constness attribute,
the check can be added to container_of() and we can switch back to
container_of() again.
Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
---
scripts/checkpatch.pl | 1 +
1 file changed, 1 insertion(+)
diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index 664f7b7a622c..32edebfc1935 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -859,6 +859,7 @@ our %deprecated_apis = (
"kunmap_atomic" => "kunmap_local",
"srcu_read_lock_lite" => "srcu_read_lock_fast",
"srcu_read_unlock_lite" => "srcu_read_unlock_fast",
+ "container_of" => "container_of_const",
);
#Create a search pattern for all these strings to speed up a loop below
--
2.39.5
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH 1/1] checkpatch: Deprecate container_of() in favour of container_of_const()
2025-08-11 8:57 [PATCH 1/1] checkpatch: Deprecate container_of() in favour of container_of_const() Sakari Ailus
@ 2025-08-11 9:05 ` Greg Kroah-Hartman
2025-11-05 8:08 ` Sakari Ailus
1 sibling, 0 replies; 6+ messages in thread
From: Greg Kroah-Hartman @ 2025-08-11 9:05 UTC (permalink / raw)
To: Sakari Ailus
Cc: linux-kernel, Andy Whitcroft, Joe Perches, Dwaipayan Ray,
Lukas Bulwahn
On Mon, Aug 11, 2025 at 11:57:31AM +0300, Sakari Ailus wrote:
> container_of() discards constness of its first argument and thus its use
> may result in inadvertly unconstifying an object that is const. While
> container_of_const() addresses this problem, the vast majority of new uses
> of the two use the container_of() variant lacking the check.
>
> Stem the flow of new container_of() use by adding it to the list of
> deprecated functions in scripts/checkpatch.pl. Once all existing
> container_of() users have been fixed to respect the constness attribute,
> the check can be added to container_of() and we can switch back to
> container_of() again.
>
> Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
> ---
> scripts/checkpatch.pl | 1 +
> 1 file changed, 1 insertion(+)
>
> diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
> index 664f7b7a622c..32edebfc1935 100755
> --- a/scripts/checkpatch.pl
> +++ b/scripts/checkpatch.pl
> @@ -859,6 +859,7 @@ our %deprecated_apis = (
> "kunmap_atomic" => "kunmap_local",
> "srcu_read_lock_lite" => "srcu_read_lock_fast",
> "srcu_read_unlock_lite" => "srcu_read_unlock_fast",
> + "container_of" => "container_of_const",
> );
>
> #Create a search pattern for all these strings to speed up a loop below
> --
> 2.39.5
>
Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 1/1] checkpatch: Deprecate container_of() in favour of container_of_const()
2025-08-11 8:57 [PATCH 1/1] checkpatch: Deprecate container_of() in favour of container_of_const() Sakari Ailus
2025-08-11 9:05 ` Greg Kroah-Hartman
@ 2025-11-05 8:08 ` Sakari Ailus
2025-11-05 9:22 ` Joe Perches
2025-11-05 13:01 ` Christoph Hellwig
1 sibling, 2 replies; 6+ messages in thread
From: Sakari Ailus @ 2025-11-05 8:08 UTC (permalink / raw)
To: Joe Perches, Sakari Ailus, Andy Whitcroft
Cc: linux-kernel, Dwaipayan Ray, Lukas Bulwahn, Greg Kroah-Hartman
Ping.
On Mon, Aug 11, 2025 at 11:57:31AM +0300, Sakari Ailus wrote:
> container_of() discards constness of its first argument and thus its use
> may result in inadvertly unconstifying an object that is const. While
> container_of_const() addresses this problem, the vast majority of new uses
> of the two use the container_of() variant lacking the check.
>
> Stem the flow of new container_of() use by adding it to the list of
> deprecated functions in scripts/checkpatch.pl. Once all existing
> container_of() users have been fixed to respect the constness attribute,
> the check can be added to container_of() and we can switch back to
> container_of() again.
>
> Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
> ---
> scripts/checkpatch.pl | 1 +
> 1 file changed, 1 insertion(+)
>
> diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
> index 664f7b7a622c..32edebfc1935 100755
> --- a/scripts/checkpatch.pl
> +++ b/scripts/checkpatch.pl
> @@ -859,6 +859,7 @@ our %deprecated_apis = (
> "kunmap_atomic" => "kunmap_local",
> "srcu_read_lock_lite" => "srcu_read_lock_fast",
> "srcu_read_unlock_lite" => "srcu_read_unlock_fast",
> + "container_of" => "container_of_const",
> );
>
> #Create a search pattern for all these strings to speed up a loop below
> --
> 2.39.5
>
>
--
Sakari Ailus
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 1/1] checkpatch: Deprecate container_of() in favour of container_of_const()
2025-11-05 8:08 ` Sakari Ailus
@ 2025-11-05 9:22 ` Joe Perches
2025-11-05 13:01 ` Christoph Hellwig
1 sibling, 0 replies; 6+ messages in thread
From: Joe Perches @ 2025-11-05 9:22 UTC (permalink / raw)
To: Sakari Ailus, Sakari Ailus, Andy Whitcroft
Cc: linux-kernel, Dwaipayan Ray, Lukas Bulwahn, Greg Kroah-Hartman
On Wed, 2025-11-05 at 10:08 +0200, Sakari Ailus wrote:
> Ping.
>
> On Mon, Aug 11, 2025 at 11:57:31AM +0300, Sakari Ailus wrote:
> > container_of() discards constness of its first argument and thus its use
> > may result in inadvertly unconstifying an object that is const. While
> > container_of_const() addresses this problem, the vast majority of new uses
> > of the two use the container_of() variant lacking the check.
> >
> > Stem the flow of new container_of() use by adding it to the list of
> > deprecated functions in scripts/checkpatch.pl. Once all existing
> > container_of() users have been fixed to respect the constness attribute,
> > the check can be added to container_of() and we can switch back to
> > container_of() again.
> >
> > Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
> > ---
> > scripts/checkpatch.pl | 1 +
> > 1 file changed, 1 insertion(+)
> >
> > diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
> > index 664f7b7a622c..32edebfc1935 100755
> > --- a/scripts/checkpatch.pl
> > +++ b/scripts/checkpatch.pl
> > @@ -859,6 +859,7 @@ our %deprecated_apis = (
> > "kunmap_atomic" => "kunmap_local",
> > "srcu_read_lock_lite" => "srcu_read_lock_fast",
> > "srcu_read_unlock_lite" => "srcu_read_unlock_fast",
> > + "container_of" => "container_of_const",
> > );
> >
> > #Create a search pattern for all these strings to speed up a loop below
> > --
> > 2.39.5
> >
> >
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 1/1] checkpatch: Deprecate container_of() in favour of container_of_const()
2025-11-05 8:08 ` Sakari Ailus
2025-11-05 9:22 ` Joe Perches
@ 2025-11-05 13:01 ` Christoph Hellwig
2025-11-05 16:25 ` Sakari Ailus
1 sibling, 1 reply; 6+ messages in thread
From: Christoph Hellwig @ 2025-11-05 13:01 UTC (permalink / raw)
To: Sakari Ailus
Cc: Joe Perches, Sakari Ailus, Andy Whitcroft, linux-kernel,
Dwaipayan Ray, Lukas Bulwahn, Greg Kroah-Hartman
Well, if container_of_const is a drop-in replacement for all uses of
container_of, just fix the implementation? If it is an almost but not
complete replacement, find a different name for the few uses. And if
it's not anywhere near drop in, just using container_of make a lot more
sense.
Just in case it wasn't clear: We really should keep the shorter nice
name as the default if at all possible. Both because it reads better
and because it avoids churn.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 1/1] checkpatch: Deprecate container_of() in favour of container_of_const()
2025-11-05 13:01 ` Christoph Hellwig
@ 2025-11-05 16:25 ` Sakari Ailus
0 siblings, 0 replies; 6+ messages in thread
From: Sakari Ailus @ 2025-11-05 16:25 UTC (permalink / raw)
To: Christoph Hellwig
Cc: Joe Perches, Sakari Ailus, Andy Whitcroft, linux-kernel,
Dwaipayan Ray, Lukas Bulwahn, Greg Kroah-Hartman
Hi Christoph,
On Wed, Nov 05, 2025 at 05:01:46AM -0800, Christoph Hellwig wrote:
> Well, if container_of_const is a drop-in replacement for all uses of
> container_of, just fix the implementation? If it is an almost but not
> complete replacement, find a different name for the few uses. And if
> it's not anywhere near drop in, just using container_of make a lot more
> sense.
>
> Just in case it wasn't clear: We really should keep the shorter nice
> name as the default if at all possible. Both because it reads better
> and because it avoids churn.
I'm in favour of the container_of() name instead of container_of_const(),
but there are a vast number of uses of container_of() in the kernel and
fixing these to respect const qualifier is going to take time. The intent
here is to prevent adding new uses of container_of() that do not respect
constness.
I tested this again on v6.18-rc2 and with my .config (far from
allyesconfig) there were 840 warnings from discarding const qualifier.
Presumably a lot of these are duplicates, but then again it'll be a
thankless (and possibly endless?) task to fix these if we don't make effort
to avoid new ones from being added at the same time.
--
Kind regards,
Sakari Ailus
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2025-11-05 16:25 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-08-11 8:57 [PATCH 1/1] checkpatch: Deprecate container_of() in favour of container_of_const() Sakari Ailus
2025-08-11 9:05 ` Greg Kroah-Hartman
2025-11-05 8:08 ` Sakari Ailus
2025-11-05 9:22 ` Joe Perches
2025-11-05 13:01 ` Christoph Hellwig
2025-11-05 16:25 ` Sakari Ailus
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.