Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 33635bd9 authored by weiping zhang's avatar weiping zhang Committed by Michael S. Tsirkin
Browse files

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: default avatarweiping zhang <zhangweiping@didichuxing.com>
Reviewed-by: default avatarCornelia Huck <cohuck@redhat.com>
Signed-off-by: default avatarMichael S. Tsirkin <mst@redhat.com>
parent f2b44cde
Loading
Loading
Loading
Loading
+6 −2
Original line number Original line Diff line number Diff line
@@ -513,7 +513,7 @@ static void virtio_pci_release_dev(struct device *_d)
static int virtio_pci_probe(struct pci_dev *pci_dev,
static int virtio_pci_probe(struct pci_dev *pci_dev,
			    const struct pci_device_id *id)
			    const struct pci_device_id *id)
{
{
	struct virtio_pci_device *vp_dev;
	struct virtio_pci_device *vp_dev, *reg_dev = NULL;
	int rc;
	int rc;


	/* allocate our structure and fill it out */
	/* allocate our structure and fill it out */
@@ -551,6 +551,7 @@ static int virtio_pci_probe(struct pci_dev *pci_dev,
	pci_set_master(pci_dev);
	pci_set_master(pci_dev);


	rc = register_virtio_device(&vp_dev->vdev);
	rc = register_virtio_device(&vp_dev->vdev);
	reg_dev = vp_dev;
	if (rc)
	if (rc)
		goto err_register;
		goto err_register;


@@ -564,6 +565,9 @@ static int virtio_pci_probe(struct pci_dev *pci_dev,
err_probe:
err_probe:
	pci_disable_device(pci_dev);
	pci_disable_device(pci_dev);
err_enable_device:
err_enable_device:
	if (reg_dev)
		put_device(&vp_dev->vdev.dev);
	else
		kfree(vp_dev);
		kfree(vp_dev);
	return rc;
	return rc;
}
}