From: david laight <david.laight@runbox.com>
To: Krzysztof Kozlowski <krzysztof.kozlowski@oss.qualcomm.com>
Cc: Krzysztof Kozlowski <krzk@kernel.org>, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] w1: Use container_of_const() when all types are const
Date: Wed, 26 Nov 2025 19:27:05 +0000 [thread overview]
Message-ID: <20251126192705.36321d87@pumpkin> (raw)
In-Reply-To: <20251126171841.72379-2-krzysztof.kozlowski@oss.qualcomm.com>
On Wed, 26 Nov 2025 18:18:42 +0100
Krzysztof Kozlowski <krzysztof.kozlowski@oss.qualcomm.com> wrote:
> Use container_of_const(), which is preferred over container_of(), when
> the argument 'ptr' and returned pointer are already const, for better
> code safety and readability.
I thought there was a plan to make container_of() return a const pointer
when the input is const?
Can't be done yet because a few things need some 'const' sprinkles
to compile.
David
>
> Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@oss.qualcomm.com>
> ---
> drivers/w1/w1.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/w1/w1.c b/drivers/w1/w1.c
> index 002d2639aa12..3b48d15390be 100644
> --- a/drivers/w1/w1.c
> +++ b/drivers/w1/w1.c
> @@ -575,11 +575,11 @@ static int w1_uevent(const struct device *dev, struct kobj_uevent_env *env)
> int err = 0;
>
> if (dev->driver == &w1_master_driver) {
> - md = container_of(dev, struct w1_master, dev);
> + md = container_of_const(dev, struct w1_master, dev);
> event_owner = "master";
> name = md->name;
> } else if (dev->driver == &w1_slave_driver) {
> - sl = container_of(dev, struct w1_slave, dev);
> + sl = container_of_const(dev, struct w1_slave, dev);
> event_owner = "slave";
> name = sl->name;
> } else {
next prev parent reply other threads:[~2025-11-26 19:27 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-11-26 17:18 [PATCH] w1: Use container_of_const() when all types are const Krzysztof Kozlowski
2025-11-26 19:27 ` david laight [this message]
2025-11-27 6:58 ` Krzysztof Kozlowski
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=20251126192705.36321d87@pumpkin \
--to=david.laight@runbox.com \
--cc=krzk@kernel.org \
--cc=krzysztof.kozlowski@oss.qualcomm.com \
--cc=linux-kernel@vger.kernel.org \
/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 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.