virtualization.lists.linux-foundation.org archive mirror
 help / color / mirror / Atom feed
From: Cornelia Huck <cohuck@redhat.com>
To: weiping zhang <zwp10758@gmail.com>
Cc: virtualization@lists.linux-foundation.org, mst@redhat.com
Subject: Re: [PATCH] virtio: release virtio index when fail to device_register
Date: Mon, 4 Dec 2017 10:38:42 +0100	[thread overview]
Message-ID: <20171204103842.3d8709a8.cohuck@redhat.com> (raw)
In-Reply-To: <20171201165539.GA11865@localhost.didichuxing.com>

On Sat, 2 Dec 2017 00:55:39 +0800
weiping zhang <zwp10758@gmail.com> wrote:

> On Wed, Nov 29, 2017 at 10:50:44AM +0100, Cornelia Huck wrote:

> > We hold an extra reference to the struct device, even after a failed
> > register, and it is the responsibility of the caller to give up that
> > reference once no longer needed. As callers toregister_virtio_device()
> > embed the struct virtio_device, it needs to be their responsibility.
> > Looking at the existing callers,
> > 
> > - ccw does a put_device
> > - pci, mmio and remoteproc do nothing, causing a leak
> > - vop does a free on the embedding structure, which is a big no-no
> > 
> > Thoughts?  
> Sorry to relay late and thanks for your review.
> Do you mean the "extra reference to the struct device" caused by the
> following code?
>  
> err = device_register(&dev->dev);
> 	device_add(dev)
> 		get_device(dev)
> If I'm understand right, I think there is no extra reference if we fail
> virtio_register_device, because if device_register we don't get a
> reference.

The device_initialize() already gives you a reference. If device_add()
fails, it has cleaned up any additional reference it might have
obtained, but the initial reference is still there and needs to be
released by the caller.

  parent reply	other threads:[~2017-12-04  9:38 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-11-29  1:23 [PATCH] virtio: release virtio index when fail to device_register weiping zhang
2017-11-29  9:50 ` Cornelia Huck
2017-12-01 16:55   ` weiping zhang
2017-12-01 17:30     ` weiping zhang
2017-12-04  9:38     ` Cornelia Huck [this message]
2017-12-05  1:30       ` weiping zhang
2017-11-29 13:55 ` Michael S. Tsirkin
  -- strict thread matches above, loose matches on Subject: below --
2017-11-28 15:43 weiping zhang

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=20171204103842.3d8709a8.cohuck@redhat.com \
    --to=cohuck@redhat.com \
    --cc=mst@redhat.com \
    --cc=virtualization@lists.linux-foundation.org \
    --cc=zwp10758@gmail.com \
    /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).