Page MenuHomeFreeBSD

linuxkpi: Define `DEFINE_CLASS()` and `CLASS()`
ClosedPublic

Authored by dumbbell on Jun 14 2026, 9:22 AM.
Referenced Files
Unknown Object (File)
Tue, Sep 15, 12:44 AM
Unknown Object (File)
Wed, Sep 9, 3:58 PM
Unknown Object (File)
Wed, Sep 9, 9:45 AM
Unknown Object (File)
Mon, Sep 7, 12:40 PM
Unknown Object (File)
Thu, Sep 3, 9:04 PM
Unknown Object (File)
Thu, Sep 3, 9:03 PM
Unknown Object (File)
Thu, Sep 3, 8:46 AM
Unknown Object (File)
Tue, Sep 1, 8:30 AM
Subscribers

Details

Summary

DEFINE_CLASS() is in fact named LINUXKPI_DEFINE_CLASS() because it conflicts with DEFINE_CLASS() defined in <sys/kobj.h>.

This macro defines a type and a pair of constructor/destructor functions.

They are to be used by CLASS(): this one declares a variable, initialise it with the constructor and set the __cleanup() attribute to call the destructor once the variable goes out of scope.

The DRM drivers generic code started to use CLASS() in Linux 6.13. It requires the fd class to be defined in <linux/file.h>.

This is part of the update of DRM drivers to Linux 6.13.

Sponsored by: The FreeBSD Foundation

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

bz added inline comments.
sys/compat/linuxkpi/common/include/linux/cleanup.h
48

If we adjust the current implementation to use a class_name and not a claneup_name (or at least use the same names) then we can implement DEFINE_GUARD as DEFINE_CLASS I believe.
I had tried not to use possibly conflicting names like "constructor" and "destructor" (probably because I am used too much used to perl reserved keywords).

Let me think about this during the day and get back here.

I think the right way to do things is to let you commit the CLASS code and then I will adjust the CLEANUP/GUARD code to match/use the CLASS code.

This revision is now accepted and ready to land.Mon, Sep 7, 10:41 PM