LoongArch: KVM: Fix kvm_device leak in kvm_{pch_pic|ipi|eiointc}_destroy
Subsystems (3)
cover LoongArch: KVM: Fix kvm_device leak in kvm_{pch_pic|ipi|eiointc}_destroy
In kvm_ioctl_create_device(), kvm_device has allocated memory, kvm_device->destroy() seems to be supposed to free its kvm_device struct, but kvm_pch_pic_destroy() is not currently doing this, that would lead to a memory leak.
So, fix it.
Qiang Ma (3):
LoongArch: KVM: Fix kvm_device leak in kvm_pch_pic_destroy
LoongArch: KVM: Fix kvm_device leak in kvm_ipi_destroy
LoongArch: KVM: Fix kvm_device leak in kvm_eiointc_destroy
arch/loongarch/kvm/intc/eiointc.c | 2 ++ arch/loongarch/kvm/intc/ipi.c | 2 ++ arch/loongarch/kvm/intc/pch_pic.c | 2 ++ 3 files changed, 6 insertions(+)
Signature · 1 line
2.20.1
PATCH 1/3 LoongArch: KVM: Fix kvm_device leak in kvm_pch_pic_destroy
In kvm_ioctl_create_device(), kvm_device has allocated memory, kvm_device->destroy() seems to be supposed to free its kvm_device struct, but kvm_pch_pic_destroy() is not currently doing this, that would lead to a memory leak.
So, fix it.
--- arch/loongarch/kvm/intc/pch_pic.c | 2 ++ 1 file changed, 2 insertions(+)
arch/loongarch/kvm/intc/pch_pic.c +2 -0
@@ -475,6 +475,8 @@ static void kvm_pch_pic_destroy(struct kvm_device *dev)/* unregister pch pic device and free it's memory */ kvm_io_bus_unregister_dev (kvm,KVM_MMIO_BUS , &s->device);kfree (s); +/* alloc by kvm_ioctl_create_device, free by .destroy */ +kfree (dev); }static struct kvm_device_ops kvm_pch_pic_dev_ops = {
Signature · 1 line
2.20.1
PATCH 2/3 LoongArch: KVM: Fix kvm_device leak in kvm_ipi_destroy
In reply to Qiang MaIn kvm_ioctl_create_device(), kvm_device has allocated memory, kvm_device->destroy() seems to be supposed to free its kvm_device struct, but kvm_ipi_destroy() is not currently doing this, that would lead to a memory leak.
So, fix it.
--- arch/loongarch/kvm/intc/ipi.c | 2 ++ 1 file changed, 2 insertions(+)
arch/loongarch/kvm/intc/ipi.c +2 -0
@@ -459,6 +459,8 @@ static void kvm_ipi_destroy(struct kvm_device *dev) ipi = kvm->arch.ipi;kvm_io_bus_unregister_dev (kvm,KVM_IOCSR_BUS , &ipi->device);kfree (ipi); +/* alloc by kvm_ioctl_create_device, free by .destroy */ +kfree (dev); }static struct kvm_device_ops kvm_ipi_dev_ops = {
Signature · 1 line
2.20.1
PATCH 3/3 LoongArch: KVM: Fix kvm_device leak in kvm_eiointc_destroy
In reply to Qiang MaIn kvm_ioctl_create_device(), kvm_device has allocated memory, kvm_device->destroy() seems to be supposed to free its kvm_device struct, but kvm_eiointc_destroy() is not currently doing this, that would lead to a memory leak.
So, fix it.
--- arch/loongarch/kvm/intc/eiointc.c | 2 ++ 1 file changed, 2 insertions(+)
arch/loongarch/kvm/intc/eiointc.c +2 -0
@@ -679,6 +679,8 @@ static void kvm_eiointc_destroy(struct kvm_device *dev)kvm_io_bus_unregister_dev (kvm,KVM_IOCSR_BUS , &eiointc->device);kvm_io_bus_unregister_dev (kvm,KVM_IOCSR_BUS , &eiointc->device_vext);kfree (eiointc); +/* alloc by kvm_ioctl_create_device, free by .destroy */ +kfree (dev); }static struct kvm_device_ops kvm_eiointc_dev_ops = {
Signature · 1 line
2.20.1
Hi qiang,
Thanks for the patch, it looks good to me.
For the whole series.
Regards
Bibo Mao
Quoted 17 lines · Qiang Ma
In
kvm_ioctl_create_device(),kvm_devicehas allocated memory,kvm_device->destroy()seems to be supposed to free itskvm_devicestruct, butkvm_pch_pic_destroy()is not currently doing this, that would lead to a memory leak.So, fix it.
Qiang Ma (3):
LoongArch: KVM: Fixkvm_deviceleak inkvm_pch_pic_destroy
LoongArch: KVM: Fixkvm_deviceleak inkvm_ipi_destroy
LoongArch: KVM: Fixkvm_deviceleak inkvm_eiointc_destroyarch/loongarch/kvm/intc/eiointc.c | 2 ++ arch/loongarch/kvm/intc/ipi.c | 2 ++ arch/loongarch/kvm/intc/pch_pic.c | 2 ++ 3 files changed, 6 insertions(+)