Skip to contentSkip to conversation

xen/pcpu: fix possible memory leak in register_pcpu()

PATCH In review Yang Yingliang 2 participants 2 messages Nov 10, 2022 Xen hypervisor interface

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 xen/pcpu: fix possible memory leak in register_pcpu()

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")
---
 drivers/xen/pcpu.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/xen/pcpu.c +1 -1
index 47aa3a1ccaf5..fd3a644b0855 100644
@@ -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;
 	}
 
Signature · 1 line
2.25.1
maintainer Reviewed-by on v1 1/1
#1 lore raw
Quoted 7 lines · Yang Yingliang

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")

Juergen