The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: Sakari Ailus <sakari.ailus@linux.intel.com>
Cc: linux-kernel@vger.kernel.org, Andy Whitcroft <apw@canonical.com>,
	Joe Perches <joe@perches.com>,
	Dwaipayan Ray <dwaipayanray1@gmail.com>,
	Lukas Bulwahn <lukas.bulwahn@gmail.com>
Subject: Re: [PATCH 1/1] checkpatch: Deprecate container_of() in favour of container_of_const()
Date: Mon, 11 Aug 2025 11:05:49 +0200	[thread overview]
Message-ID: <2025081142-setup-underuse-5611@gregkh> (raw)
In-Reply-To: <20250811085731.2117377-1-sakari.ailus@linux.intel.com>

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>

  reply	other threads:[~2025-08-11  9:05 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=2025081142-setup-underuse-5611@gregkh \
    --to=gregkh@linuxfoundation.org \
    --cc=apw@canonical.com \
    --cc=dwaipayanray1@gmail.com \
    --cc=joe@perches.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lukas.bulwahn@gmail.com \
    --cc=sakari.ailus@linux.intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox