|
|
Log in / Subscribe / Register

Losing the magic

Losing the magic

Posted Dec 6, 2022 14:15 UTC (Tue) by sima (subscriber, #160698)
In reply to: Losing the magic by marcH
Parent article: Losing the magic

Tons of places have moved to container_of and struct embedded, and away from void*. It's not really more typesafe when you try to get things intentionally wrong, but it does help a lot with silly mistakes and "oops wrong offset" screwups.

But yeah relative amount of void* might be an interesting metric to see whether the conjecture that the kernel moved towards more type safety actually holds.


to post comments

Losing the magic

Posted Dec 7, 2022 17:41 UTC (Wed) by abatters (✭ supporter ✭, #6932) [Link] (1 responses)

As an example of the kernel moving in the unsafe direction, the kernel has lots of special printk format specifiers for specific pointer types that are not typechecked by the compiler.

https://docs.kernel.org/core-api/printk-formats.html

Losing the magic

Posted Dec 8, 2022 10:53 UTC (Thu) by geert (subscriber, #98403) [Link]

Sounds like a good task for sparse?

Losing the magic

Posted Jan 2, 2023 18:31 UTC (Mon) by tabberson (guest, #162965) [Link] (1 responses)

Can you please explain what you mean by "struct embedded"?

Losing the magic

Posted Jan 3, 2023 9:56 UTC (Tue) by geert (subscriber, #98403) [Link]

struct foo {
        ...
        struct bar embedded;
        ...
};
If you have a pointer to the "embedded" member of type "struct bar", you can convert it to a pointer to the containing "struct foo" using the container_of() macro.


Copyright © 2026, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds