[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20200220151914.GW23930@mellanox.com>
Date: Thu, 20 Feb 2020 15:19:18 +0000
From: Jason Gunthorpe <jgg@...lanox.com>
To: Jason Wang <jasowang@...hat.com>
CC: "mst@...hat.com" <mst@...hat.com>,
"linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>,
"kvm@...r.kernel.org" <kvm@...r.kernel.org>,
"virtualization@...ts.linux-foundation.org"
<virtualization@...ts.linux-foundation.org>,
"netdev@...r.kernel.org" <netdev@...r.kernel.org>,
"tiwei.bie@...el.com" <tiwei.bie@...el.com>,
"maxime.coquelin@...hat.com" <maxime.coquelin@...hat.com>,
"cunming.liang@...el.com" <cunming.liang@...el.com>,
"zhihong.wang@...el.com" <zhihong.wang@...el.com>,
"rob.miller@...adcom.com" <rob.miller@...adcom.com>,
"xiao.w.wang@...el.com" <xiao.w.wang@...el.com>,
"haotian.wang@...ive.com" <haotian.wang@...ive.com>,
"lingshan.zhu@...el.com" <lingshan.zhu@...el.com>,
"eperezma@...hat.com" <eperezma@...hat.com>,
"lulu@...hat.com" <lulu@...hat.com>,
Parav Pandit <parav@...lanox.com>,
"kevin.tian@...el.com" <kevin.tian@...el.com>,
"stefanha@...hat.com" <stefanha@...hat.com>,
"rdunlap@...radead.org" <rdunlap@...radead.org>,
"hch@...radead.org" <hch@...radead.org>,
"aadam@...hat.com" <aadam@...hat.com>,
Jiri Pirko <jiri@...lanox.com>,
Shahaf Shuler <shahafs@...lanox.com>,
"hanand@...inx.com" <hanand@...inx.com>,
"mhabets@...arflare.com" <mhabets@...arflare.com>
Subject: Re: [PATCH V4 4/5] virtio: introduce a vDPA based transport
On Thu, Feb 20, 2020 at 02:11:40PM +0800, Jason Wang wrote:
> +static int virtio_vdpa_probe(struct vdpa_device *vdpa)
> +{
> + const struct vdpa_config_ops *ops = vdpa->config;
> + struct virtio_vdpa_device *vd_dev;
> + int ret = -EINVAL;
> +
> + vd_dev = kzalloc(sizeof(*vd_dev), GFP_KERNEL);
> + if (!vd_dev)
> + return -ENOMEM;
> +
> + vd_dev->vdev.dev.parent = vdpa_get_dma_dev(vdpa);
> + vd_dev->vdev.dev.release = virtio_vdpa_release_dev;
> + vd_dev->vdev.config = &virtio_vdpa_config_ops;
> + vd_dev->vdpa = vdpa;
> + INIT_LIST_HEAD(&vd_dev->virtqueues);
> + spin_lock_init(&vd_dev->lock);
> +
> + vd_dev->vdev.id.device = ops->get_device_id(vdpa);
> + if (vd_dev->vdev.id.device == 0)
> + goto err;
> +
> + vd_dev->vdev.id.vendor = ops->get_vendor_id(vdpa);
> + ret = register_virtio_device(&vd_dev->vdev);
> + if (ret)
> + goto err;
This error unwind is wrong. register_virtio_device() does
device_initialize() as it's first action. After that point error
unwind must be done with put_device() - particularly calling
kfree(vd_dev) after doing dev_set_name() leaks memory.
Looks like about half of the register_virtio_device() users did this
right, the others not. Perhaps you should fix them too...
Jason
Powered by blists - more mailing lists