--- a/sys/dev/drm/linux_kobject.c +++ b/sys/dev/drm/linux_kobject.c @@ -27,6 +27,8 @@ #include #include +MALLOC_DECLARE(M_DRM); + int kobject_init_and_add(struct kobject *kobj, struct kobj_type *ktype, struct kobject *parent, const char *fmt, ...) { @@ -45,7 +47,16 @@ void kobject_release(struct kref *kref) { struct kobject *kobj = container_of(kref, struct kobject, kref); + char *name = __DECONST(char *, kobj->name); if (kobj->ktype && kobj->ktype->release) kobj->ktype->release(kobj); + + /* + * The release callback typically frees the structure embedding + * this kobject, so the name pointer must be saved before the + * release call (mirrors upstream kobject_cleanup()). + */ + if (name != NULL) + kfree(name, M_DRM); }