]> git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/commitdiff
xen/pcpu: fix possible memory leak in register_pcpu()
authorYang Yingliang <yangyingliang@huawei.com>
Thu, 10 Nov 2022 15:24:41 +0000 (23:24 +0800)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Wed, 14 Dec 2022 12:59:29 +0000 (13:59 +0100)
[ Upstream commit da36a2a76b01b210ffaa55cdc2c99bc8783697c5 ]

In device_add(), dev_set_name() is called to allocate name, if it returns
error, the name need be freed. As comment of device_register() says, it
should use put_device() to give up the reference in the error path. So fix
this by calling put_device(), then the name can be freed in kobject_cleanup().

Fixes: f65c9bb3fb72 ("xen/pcpu: Xen physical cpus online/offline sys interface")
Signed-off-by: Yang Yingliang <yangyingliang@huawei.com>
Reviewed-by: Juergen Gross <jgross@suse.com>
Link: https://lore.kernel.org/r/20221110152441.401630-1-yangyingliang@huawei.com
Signed-off-by: Juergen Gross <jgross@suse.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
(cherry picked from commit c08c13cb13fa3866dd0700db3b246fcd2043ab81)
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
drivers/xen/pcpu.c

index 47aa3a1ccaf5746a9a7eae7f1f8ab82d2065e33c..fd3a644b0855992944671897efcf8dba241d2985 100644 (file)
@@ -228,7 +228,7 @@ static int register_pcpu(struct pcpu *pcpu)
 
        err = device_register(dev);
        if (err) {
-               pcpu_release(dev);
+               put_device(dev);
                return err;
        }