From: Xianting Tian <xianting.tian@linux.alibaba.com>
To: Jason Wang <jasowang@redhat.com>
Cc: mst <mst@redhat.com>,
virtualization <virtualization@lists.linux-foundation.org>,
linux-kernel <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] virtio-pci: fix memory leak of vp_dev
Date: Fri, 7 Jan 2022 10:36:48 +0800 [thread overview]
Message-ID: <9589357f-8d23-5a48-c5f6-ba17eb79cf57@linux.alibaba.com> (raw)
In-Reply-To: <CACGkMEuW5po+v-fFPNH6wtVVXD84Bx0UWhe86sHFYXQM39OKRA@mail.gmail.com>
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
>>
prev parent reply other threads:[~2022-01-07 2:36 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
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 message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=9589357f-8d23-5a48-c5f6-ba17eb79cf57@linux.alibaba.com \
--to=xianting.tian@linux.alibaba.com \
--cc=jasowang@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mst@redhat.com \
--cc=virtualization@lists.linux-foundation.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).