* [PATCH] virtio-pci: fix memory leak of vp_dev
@ 2022-01-06 8:31 Xianting Tian
2022-01-07 2:34 ` Jason Wang
0 siblings, 1 reply; 3+ messages in thread
From: Xianting Tian @ 2022-01-06 8:31 UTC (permalink / raw)
To: mst, jasowang; +Cc: virtualization, linux-kernel, Xianting Tian
In virtio_pci_probe(), vp_dev will not be freed if it goes to
"err_register" branch. fix it
Signed-off-by: Xianting Tian <xianting.tian@linux.alibaba.com>
---
drivers/virtio/virtio_pci_common.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/drivers/virtio/virtio_pci_common.c b/drivers/virtio/virtio_pci_common.c
index fdbde1db5..48b5ac15e 100644
--- a/drivers/virtio/virtio_pci_common.c
+++ b/drivers/virtio/virtio_pci_common.c
@@ -602,8 +602,7 @@ static int virtio_pci_probe(struct pci_dev *pci_dev,
err_enable_device:
if (reg_dev)
put_device(&vp_dev->vdev.dev);
- else
- kfree(vp_dev);
+ kfree(vp_dev);
return rc;
}
--
2.17.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] virtio-pci: fix memory leak of vp_dev
2022-01-06 8:31 [PATCH] virtio-pci: fix memory leak of vp_dev Xianting Tian
@ 2022-01-07 2:34 ` Jason Wang
2022-01-07 2:36 ` Xianting Tian
0 siblings, 1 reply; 3+ messages in thread
From: Jason Wang @ 2022-01-07 2:34 UTC (permalink / raw)
To: Xianting Tian; +Cc: mst, virtualization, linux-kernel
On Thu, Jan 6, 2022 at 4:31 PM Xianting Tian
<xianting.tian@linux.alibaba.com> wrote:
>
> In virtio_pci_probe(), vp_dev will not be freed if it goes to
> "err_register" branch. fix it
>
> Signed-off-by: Xianting Tian <xianting.tian@linux.alibaba.com>
So we had this:
commit 33635bd976fb4c3ccf0cfbb81a8d29bb87760607
Author: weiping zhang <zhangweiping@didichuxing.com>
Date: Thu Dec 21 20:40:24 2017 +0800
virtio_pci: don't kfree device on register failure
As mentioned at drivers/base/core.c:
/*
* NOTE: _Never_ directly free @dev after calling this function, even
* if it returned an error! Always use put_device() to give up the
* reference initialized in this function instead.
*/
so we don't free vp_dev until vp_dev->vdev.dev.release be called.
Signed-off-by: weiping zhang <zhangweiping@didichuxing.com>
Reviewed-by: Cornelia Huck <cohuck@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
Any reason that the above fix is wrong?
Thanks
> ---
> drivers/virtio/virtio_pci_common.c | 3 +--
> 1 file changed, 1 insertion(+), 2 deletions(-)
>
> diff --git a/drivers/virtio/virtio_pci_common.c b/drivers/virtio/virtio_pci_common.c
> index fdbde1db5..48b5ac15e 100644
> --- a/drivers/virtio/virtio_pci_common.c
> +++ b/drivers/virtio/virtio_pci_common.c
> @@ -602,8 +602,7 @@ static int virtio_pci_probe(struct pci_dev *pci_dev,
> err_enable_device:
> if (reg_dev)
> put_device(&vp_dev->vdev.dev);
> - else
> - kfree(vp_dev);
> + kfree(vp_dev);
> return rc;
> }
>
> --
> 2.17.1
>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] virtio-pci: fix memory leak of vp_dev
2022-01-07 2:34 ` Jason Wang
@ 2022-01-07 2:36 ` Xianting Tian
0 siblings, 0 replies; 3+ messages in thread
From: Xianting Tian @ 2022-01-07 2:36 UTC (permalink / raw)
To: Jason Wang; +Cc: mst, virtualization, linux-kernel
Thanks, I checked this before your reply, it is not a bug,
Sorry for the inconvenience caused.
在 2022/1/7 上午10:34, Jason Wang 写道:
> On Thu, Jan 6, 2022 at 4:31 PM Xianting Tian
> <xianting.tian@linux.alibaba.com> wrote:
>> In virtio_pci_probe(), vp_dev will not be freed if it goes to
>> "err_register" branch. fix it
>>
>> Signed-off-by: Xianting Tian <xianting.tian@linux.alibaba.com>
> So we had this:
>
> commit 33635bd976fb4c3ccf0cfbb81a8d29bb87760607
> Author: weiping zhang <zhangweiping@didichuxing.com>
> Date: Thu Dec 21 20:40:24 2017 +0800
>
> virtio_pci: don't kfree device on register failure
>
> As mentioned at drivers/base/core.c:
> /*
> * NOTE: _Never_ directly free @dev after calling this function, even
> * if it returned an error! Always use put_device() to give up the
> * reference initialized in this function instead.
> */
> so we don't free vp_dev until vp_dev->vdev.dev.release be called.
>
> Signed-off-by: weiping zhang <zhangweiping@didichuxing.com>
> Reviewed-by: Cornelia Huck <cohuck@redhat.com>
> Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
>
> Any reason that the above fix is wrong?
>
> Thanks
>
>> ---
>> drivers/virtio/virtio_pci_common.c | 3 +--
>> 1 file changed, 1 insertion(+), 2 deletions(-)
>>
>> diff --git a/drivers/virtio/virtio_pci_common.c b/drivers/virtio/virtio_pci_common.c
>> index fdbde1db5..48b5ac15e 100644
>> --- a/drivers/virtio/virtio_pci_common.c
>> +++ b/drivers/virtio/virtio_pci_common.c
>> @@ -602,8 +602,7 @@ static int virtio_pci_probe(struct pci_dev *pci_dev,
>> err_enable_device:
>> if (reg_dev)
>> put_device(&vp_dev->vdev.dev);
>> - else
>> - kfree(vp_dev);
>> + kfree(vp_dev);
>> return rc;
>> }
>>
>> --
>> 2.17.1
>>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2022-01-07 2:36 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-01-06 8:31 [PATCH] virtio-pci: fix memory leak of vp_dev Xianting Tian
2022-01-07 2:34 ` Jason Wang
2022-01-07 2:36 ` Xianting Tian
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).