* [PATCH] w1: Use container_of_const() when all types are const
@ 2025-11-26 17:18 Krzysztof Kozlowski
2025-11-26 19:27 ` david laight
0 siblings, 1 reply; 3+ messages in thread
From: Krzysztof Kozlowski @ 2025-11-26 17:18 UTC (permalink / raw)
To: Krzysztof Kozlowski, linux-kernel; +Cc: Krzysztof Kozlowski
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.
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 {
--
2.48.1
^ permalink raw reply related [flat|nested] 3+ messages in thread* Re: [PATCH] w1: Use container_of_const() when all types are const
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
2025-11-27 6:58 ` Krzysztof Kozlowski
0 siblings, 1 reply; 3+ messages in thread
From: david laight @ 2025-11-26 19:27 UTC (permalink / raw)
To: Krzysztof Kozlowski; +Cc: Krzysztof Kozlowski, linux-kernel
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 {
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCH] w1: Use container_of_const() when all types are const
2025-11-26 19:27 ` david laight
@ 2025-11-27 6:58 ` Krzysztof Kozlowski
0 siblings, 0 replies; 3+ messages in thread
From: Krzysztof Kozlowski @ 2025-11-27 6:58 UTC (permalink / raw)
To: david laight, Krzysztof Kozlowski; +Cc: linux-kernel
On 26/11/2025 20:27, david laight wrote:
> 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.
>
You mean to use _Generic for container_of, basically exactly how
container_of_const is created? Do you have any indications that this is
happening, because current code does not suggest that.
Best regards,
Krzysztof
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2025-11-27 6:58 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
2025-11-27 6:58 ` Krzysztof Kozlowski
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox