Message ID | 20221110152441.401630-1-yangyingliang@huawei.com (mailing list archive) |
---|---|
State | Accepted |
Commit | da36a2a76b01b210ffaa55cdc2c99bc8783697c5 |
Headers | show |
Series | xen/pcpu: fix possible memory leak in register_pcpu() | expand |
On 10.11.22 16:24, Yang Yingliang wrote: > 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> Juergen
diff --git a/drivers/xen/pcpu.c b/drivers/xen/pcpu.c index 47aa3a1ccaf5..fd3a644b0855 100644 --- a/drivers/xen/pcpu.c +++ b/drivers/xen/pcpu.c @@ -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; }
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> --- drivers/xen/pcpu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)