Re: [PATCH] thermal/core: Fix double device initialization

From: Rafael J. Wysocki

Date: Mon May 25 2026 - 11:33:20 EST


On Mon, May 25, 2026 at 5:29 PM Rafael J. Wysocki <rafael@xxxxxxxxxx> wrote:
>
> On Mon, May 25, 2026 at 5:16 PM Daniel Lezcano
> <daniel.lezcano@xxxxxxxxxx> wrote:
> >
> > In the previous change splitting the cooling device register function,
> > the device initialization was mistakenly added in the move.
> >
> > This change is wrong because the device is registered with the
> > function device_register() which does device_initialize() and then
> > device_add(). That results in a double initialization and a message in
> > logs:
> >
> > [ 1.531290] kobject: kobject (0000000053ba73b2): tried to init an initialized object, something is seriously wrong.
> > [ 1.531293] CPU: 9 UID: 0 PID: 420 Comm: kworker/u50:3 Not tainted 7.1.0-rc1+ #48 PREEMPT(lazy)
> > [ 1.531294] Hardware name: LENOVO 21N10007UK/21N10007UK, BIOS N42ET38W (1.12 ) 05/29/2024
> > [ 1.531295] Workqueue: events_unbound deferred_probe_work_func
> > [ 1.531298] Call trace:
> > [ 1.531298] show_stack+0x24/0x50 (C)
> > [ 1.531301] dump_stack_lvl+0x80/0xc0
> > [ 1.531303] kobject_init+0xc0/0xd8
> > [ 1.531305] device_initialize+0x3c/0x140
> > [ 1.531308] device_register+0x20/0x48
> > [ 1.531310] thermal_cooling_device_add+0xe0/0x208
> > [ 1.531311] thermal_of_cooling_device_register+0x54/0xa0
> > [ 1.531313] __cpufreq_cooling_register+0x1e0/0x368
> > [ 1.531315] of_cpufreq_cooling_register+0x64/0xe0
> > [ 1.531316] cpufreq_online+0xa6c/0xef0
> > [ 1.531317] cpufreq_add_dev+0x108/0x180
> > [ 1.531318] subsys_interface_register+0x138/0x168
> > [ 1.531320] cpufreq_register_driver+0x1b8/0x390
> >
> > Fix by just removing the added line.
> >
> > Fixes: 13f4e660a126 ("thermal/core: Split __thermal_cooling_device_register() into two functions")
>
> In this commit, the device_register() has been replaced with
> device_add(), so the problem above should not trigger.
>
> Which kernel have you tested?

Moreover, note that removing device_initialize() would break the
cleanup path which relies on the device's kobject to be initialized
AFAICS.

> > Signed-off-by: Daniel Lezcano <daniel.lezcano@xxxxxxxxxx>
> > ---
> > drivers/thermal/thermal_core.c | 1 -
> > 1 file changed, 1 deletion(-)
> >
> > diff --git a/drivers/thermal/thermal_core.c b/drivers/thermal/thermal_core.c
> > index 9b9fa51067bd..3cf305ceaf41 100644
> > --- a/drivers/thermal/thermal_core.c
> > +++ b/drivers/thermal/thermal_core.c
> > @@ -1012,7 +1012,6 @@ static int thermal_cooling_device_add(struct thermal_cooling_device *cdev, void
> > cdev->updated = false;
> > cdev->device.class = thermal_class;
> > cdev->device.release = thermal_cdev_release;
> > - device_initialize(&cdev->device);
> > cdev->devdata = devdata;
> >
> > ret = dev_set_name(&cdev->device, "cooling_device%d", cdev->id);
> > --