A nine-patch series from Ian Rogers proposes a compile-time check for a missing kobject release callback: a new __must_init attribute on struct kobj_type::release, which would make Clang 20 or later warn when an initialiser leaves the field out. Version 4 was posted on 19 November 2026 and applied to the driver-core maintainers’ testing branch on 22 November. It is not in mainline or in linux-next, and no target release has been stated.
Status on 23 November 2026: v4, applied to the driver-core-testing branch of driver-core.git, not yet in driver-core-next or linux-next. Not merged.
A driver that embeds a struct kobject in its own structure, usually to publish a private sysfs directory, may free that memory only from the kobject release callback. Today nothing checks that the callback exists. The series would make the compiler check it, and preparing the tree for the check has already shown how many in-tree users get the rule wrong.
The problem today: a missing kobject release is silent
A kobject is reference counted. A driver calls kobject_put() when it has finished with the object, but an open sysfs file may still hold a reference, so the last reference can be dropped later than the driver expects. The only safe place to free the enclosing structure is the release() function named in the object’s struct kobj_type. Documentation/core-api/kobject.rst says that every kobject must have a release() method and that code which does not meet this is flawed.
In current kernels this rule is enforced only by a debug message. In lib/kobject.c at v7.4-rc3, kobject_cleanup() checks the pointer and reports its absence with pr_debug(), which prints nothing unless dynamic debug or DEBUG is enabled for that file:
if (t && !t->release)
pr_debug("'%s' (%p): does not have a release() function, it is broken and must be fixed. See Documentation/core-api/kobject.rst.\n",
kobject_name(kobj), kobj);Cleanup then continues and no release function is called. Either the driver never frees the object, which is a memory leak, or it frees the object by another route, such as kfree() straight after kobject_put() or a devm allocation released at unbind. The second case is a use-after-free whenever a reference outlives the driver’s own. A missing kobject release therefore surfaces, if at all, as a leak report or a crash far from its cause.
The existing runtime aid is CONFIG_DEBUG_KOBJECT_RELEASE. With it enabled, kobject_release() defers the cleanup through delayed work by one to four seconds, so that a driver which frees too early fails visibly. It only finds the paths that a test actually exercises.
What the series proposes
Patch 1 would add a macro to include/linux/compiler_attributes.h that wraps the Clang attribute require_explicit_initialization. A structure member marked with it must be named in every aggregate initialiser of that structure; if it is omitted, Clang emits -Wuninitialized-explicit-init, a warning that is enabled by default. The proposed definition is:
/*
* Optional: not supported by gcc
* Optional: only supported since clang >= 20.0
*/
#if __has_attribute(__require_explicit_initialization__)
# define __must_init __attribute__((__require_explicit_initialization__))
#else
# define __must_init
#endifPatch 9 would then apply the attribute to one field in include/linux/kobject.h:
struct kobj_type {
- void (*release)(struct kobject *kobj);
+ void (*release)(struct kobject *kobj) __must_init;
const struct sysfs_ops *sysfs_ops;Two limits follow from the patch text. With GCC, and with Clang older than 20, the macro expands to nothing, so those builds would behave as they do now; the kernel’s minimum LLVM version at v7.4-rc3 is 17.0.1 on most architectures. And the check is satisfied by writing .release = NULL: it requires the author to state a decision about the kobject release, and does not prove that the decision is correct.
What the annotation found in the tree
The cover letter of version 1 reported that annotating the field caught 30 struct kobj_type definitions without a release callback. In version 4, patches 2 to 8 would repair seven areas. Two of them matter directly to embedded products.
Patch 7 concerns UBIFS. fs/ubifs/sysfs.c currently declares a static struct kset whose type has no release function. The patch description states that, with CONFIG_DEBUG_KOBJECT_RELEASE=y, unloading the ubifs module while a delayed release is pending causes a use-after-free on that kset. The proposed fix would obtain the kset from kset_create_and_add(), which supplies its own release function. Patch 4 would change the cpufreq ondemand and conservative governors so that the callback is set in the static initialiser and no longer assigned at run time.
Patch 9 would not fix the remaining sites. It would write .release = NULL at each one and add a comment. By the author’s count in the v3 thread, 17 files are involved: three built-in sites where the storage is never freed (arm64 cpuinfo, ACPI hotplug profiles and s390 sclp_mem), and 14 files with what the patch calls broken kobject lifetime management. The second group includes the AB8500 fuel gauge driver, the three omapfb DSS sysfs files, and the sysfs code of F2FS and EROFS when those filesystems are built as modules. The comment proposed for drivers/power/supply/ab8500_fg.c describes a pattern that also appears in vendor drivers:
/*
* FIXME: Broken kobject lifetime (needs follow-up fix): fg_kobject is
* embedded in devm-allocated struct ab8500_fg; ab8500_fg_sysfs_exit()
* only calls kobject_del() (never kobject_put()) before devm frees the
* struct on unbind, and on ab8500_fg_sysfs_init() failure kobject_put()
* races with devm freeing the struct on probe failure.
*/
.release = NULL,A structure allocated with devm_kzalloc() is freed when the driver unbinds, whatever the reference count of a kobject inside it. Our article on how devres manages device resources explains when that memory is released. The patch states that it does not alter runtime behaviour at these sites.
The review
Version 1, eleven patches, was posted on 13 October 2026 after a session by the author at the Linux Plumbers Conference. Greg Kroah-Hartman welcomed the idea but asked for a different order: “let’s fix up the users before adding the attribute”. Kees Cook offered to take patch 1 earlier with a first user in seq_file, and Kroah-Hartman agreed provided it did not break the build. According to the v2 cover letter the attribute did not reach the v7.4 merge window, so the series carries it again, renamed from __require_explicit_initialization to __must_init at Kroah-Hartman’s suggestion.
Miguel Ojeda corrected the compiler requirement: the conference slides named Clang 14, but he found the attribute only from Clang 20, and asked for the comment that now appears in the macro.
Two reviewers questioned individual fixes. Sumanth Korikkar objected to the s390 patch in v1, which added a kobject release function for firmware memory entries that are permanent and never unregistered; the patch was dropped and the site received .release = NULL with a comment. Alexander Aring acked the DLM change but observed that it was a large change for the sake of a debug option.
Rafael Wysocki asked whether subsystem maintainers should pick up their patches separately. Rogers replied that the final patch would break Clang builds wherever a fix was missing. Danilo Krummrich then offered to route the whole series through the driver-core tree.
The last substantive review was Krummrich’s, on 18 November. In v3 every remaining site carried a comment beginning “Pre-existing:”. He objected that this did not separate sites whose storage really is permanent from sites with a lifetime bug, and asked for each comment to state either the guarantee or the defect. Version 4 is the answer: the three-and-fourteen split, the FIXME comments, and a statement from Rogers that he plans to send fixes to the subsystems concerned.
Where it stands
Krummrich applied all nine patches to the driver-core-testing branch on 22 November 2026 and wrote that he would keep them there for a few more days before moving them to driver-core-next, inviting concerns about the comments in patch 9. When checked on 23 November, include/linux/kobject.h carried the attribute on driver-core-testing only. It was unchanged in driver-core-next, in next-20261120, which was the latest linux-next tree, and in mainline at v7.4-rc4. No maintainer has named a release. The next steps are promotion to driver-core-next, exposure in linux-next, and a pull request in a later merge window.
What it would mean for a product team
If the series is merged, the effect depends on the compiler. A product kernel built with GCC would see no change. A kernel built with Clang 20 or later would report every struct kobj_type initialiser in vendor or out-of-tree code that omits .release, and where CONFIG_WERROR is enabled that warning stops the build. Drivers that only call kobject_create_and_add() or kset_create_and_add() do not define a kobj_type and would not be affected.
The audit does not have to wait for the merge. The affected definitions can be listed today, and the series can be applied to a v7.4-rc3 tree and built with Clang:
raghu@techveda.org:~$ git grep -n -A6 'struct kobj_type' -- drivers/ fs/ sound/
raghu@techveda.org:~$ clang --version
raghu@techveda.org:~$ git checkout -b kobj-release-test v7.4-rc3
raghu@techveda.org:~$ b4 shazam 20261119192520.1983406-1-irogers@google.com
raghu@techveda.org:~$ make LLVM=1 ARCH=arm64 defconfig
raghu@techveda.org:~$ make LLVM=1 ARCH=arm64 -j8For each definition without a release function, the question is the one Krummrich put to the author: what guarantees that the memory outlives the last reference? If the kobject sits inside a devm allocation, or inside static data of a loadable module, nothing does. A test kernel with CONFIG_DEBUG_KOBJECT_RELEASE=y makes the defect reproducible by unbinding the driver or unloading the module, and logs each delayed kobject release:
root@imx8mp-evk:~# dmesg | grep kobject_releaseThe proposal would not fix the 14 files marked FIXME; those remain as they are until follow-up patches are accepted. It would not detect a release function that exists but is empty, which the kernel documentation warns against. Patch 7 carries a Fixes: tag; whether it will be backported to stable kernels has not been stated in the thread.
What was checked and what could not be verified
We read the v4 cover letter and patches 1, 4, 7 and 9, the human replies on the v1, v2 and v3 threads, and Krummrich’s messages of 18 and 22 November. We read lib/kobject.c, fs/ubifs/sysfs.c, scripts/min-tool-version.sh and the kobject documentation at v7.4-rc3, and compared include/linux/kobject.h across mainline, linux-next and both driver-core branches. We did not build the series, so the text of the Clang diagnostic is not reproduced here. We did not read patches 2, 3, 5, 6 and 8 in full, the seq_file thread, or the conference recording, and we did not check the 14 FIXME descriptions against the driver sources.
Key takeaways
- The proposal would add
__must_initand apply it tostruct kobj_type::release; only Clang 20 or later would act on it. - Today a missing kobject release callback produces only a
pr_debug()message inkobject_cleanup(). - The series would fix a UBIFS module-unload defect and would document, without fixing, 14 files with lifetime problems.
- Version 4 is on
driver-core-testing; it is not in linux-next or mainline, and no release has been named.
Frequently asked questions
Would the proposed check affect a kernel built with GCC?
No. The proposed __must_init macro expands to nothing when the compiler does not support the attribute, and the patch comment states that GCC does not. Only Clang 20 or later would report a missing kobject release initialiser.
Is the series part of Linux 7.4?
No. On 23 November 2026 it was on the driver-core-testing branch only, and absent from linux-next and from mainline at v7.4-rc4. No maintainer has stated a target release.
How can a missing kobject release be found on a kernel without this series?
Search the driver sources for struct kobj_type definitions that do not set .release, and test unbind and module unload on a kernel built with CONFIG_DEBUG_KOBJECT_RELEASE=y, which delays the final cleanup so that an early free fails visibly.
References
- [PATCH v4 0/9] Add __must_init and require explicit kobj_type::release, Ian Rogers, 19 November 2026 (lore.kernel.org)
- [PATCH v4 9/9] kobject: Require explicit initialization of struct kobj_type::release
- Danilo Krummrich: applied to driver-core-testing, 22 November 2026
- Danilo Krummrich: review of v3 patch 9, 18 November 2026
- Version 3 thread, 8 November 2026
- Version 2 thread, 27 October 2026
- Version 1 thread, 13 October 2026
- driver-core.git, driver-core-testing branch
- lib/kobject.c at v7.4-rc3
- Documentation/core-api/kobject.rst at v7.4-rc3
- Linux Plumbers Conference 2026: Upgrading Runtime Leaks to Compile-Time Errors, Ian Rogers




