[PATCH 00/11] kobject: Require explicit initialization of struct kobj_type::release
From: Ian Rogers
Date: Tue Oct 13 2026 - 18:46:30 EST
Clang supports the 'require_explicit_initialization' attribute on struct
fields to enforce that the field is explicitly initialized when an
aggregate object is constructed, emitting -Wuninitialized-explicit-init
(enabled by default) if the field is omitted.
Following discussion at the Linux Plumbers Conference [1], this series
introduces __require_explicit_initialization in
include/linux/compiler_attributes.h and applies it to
struct kobj_type::release.
As Documentation/core-api/kobject.rst notes:
"One important point cannot be overstated: every kobject must have a
release() method, and the kobject must persist (in a consistent state)
until that method is called. If these constraints are not met, the code
is flawed."
Annotating struct kobj_type::release caught 30 struct kobj_type
definitions across the tree that omitted .release:
- Patches 2-10 fix 10 struct kobj_type definitions where dynamically
allocated kobjects, ksets, or enclosing structures were either leaked on
kobject_put() or freed prematurely before kobject release (risking a
use-after-free when CONFIG_DEBUG_KOBJECT_RELEASE=y).
- Patch 11 annotates struct kobj_type::release with
__require_explicit_initialization and explicitly sets .release = NULL
(with explanatory comments) on the remaining legacy struct kobj_type
definitions whose kobjects are static, per-CPU, or embedded in devm- or
parent-managed structures.
[1] https://lpc.events/event/20/contributions/2392/
Ian Rogers (11):
Compiler Attributes: Add __require_explicit_initialization macro
powerpc/secvar: Add missing kobject release callback to secvar_ktype
sh: sq: Add missing kobject release callback to ktype_percpu_entry
cpufreq: Initialize kobj_type release callback in ondemand and
conservative governors
ACPI: CPPC: Free cpc_desc in kobject release callback
dlm: Free dlm_ls in kobject release callback
xen/sys-hypervisor: Add release callback to hyp_sysfs_kobj_type
s390/sclp_mem: Allocate struct sclp_mem dynamically and add kobject
release
ubifs: sysfs: Use kset_create_and_add() for ubifs_kset
drm/amdkfd: Free queue in procfs_queue_type kobject release callback
kobject: Require explicit initialization of struct kobj_type::release
Documentation/conf.py | 1 +
arch/arm64/kernel/cpuinfo.c | 2 +
arch/powerpc/kernel/secvar-sysfs.c | 6 ++
arch/sh/kernel/cpu/sh4/sq.c | 6 ++
drivers/acpi/cppc_acpi.c | 39 +++++-----
drivers/acpi/sysfs.c | 2 +
drivers/cpufreq/cpufreq_conservative.c | 5 +-
drivers/cpufreq/cpufreq_governor.c | 3 +-
drivers/cpufreq/cpufreq_governor.h | 1 +
drivers/cpufreq/cpufreq_ondemand.c | 5 +-
drivers/dma/ioat/sysfs.c | 2 +
drivers/gpu/drm/amd/amdgpu/amdgpu_xcp.c | 4 +
drivers/gpu/drm/amd/amdkfd/kfd_process.c | 10 ++-
drivers/gpu/drm/amd/amdkfd/kfd_queue.c | 5 +-
drivers/infiniband/hw/hfi1/sysfs.c | 2 +
drivers/infiniband/hw/usnic/usnic_ib_sysfs.c | 2 +
drivers/parisc/pdc_stable.c | 2 +
drivers/power/supply/ab8500_fg.c | 2 +
drivers/s390/char/sclp_mem.c | 73 +++++++++----------
drivers/soc/hisilicon/kunpeng_hccs.c | 6 ++
.../fbdev/omap2/omapfb/dss/display-sysfs.c | 2 +
.../fbdev/omap2/omapfb/dss/manager-sysfs.c | 2 +
.../fbdev/omap2/omapfb/dss/overlay-sysfs.c | 2 +
drivers/xen/sys-hypervisor.c | 6 ++
fs/dlm/lockspace.c | 19 +++--
fs/erofs/sysfs.c | 4 +
fs/f2fs/sysfs.c | 6 ++
fs/ocfs2/cluster/masklog.c | 2 +
fs/ubifs/sysfs.c | 24 ++----
include/linux/compiler_attributes.h | 11 +++
include/linux/kobject.h | 2 +-
scripts/checkpatch.pl | 1 +
tools/lib/python/kdoc/xforms_lists.py | 1 +
33 files changed, 170 insertions(+), 90 deletions(-)
--
2.56.0.385.gd3acb90ef8-goog