virtio-mmio: fix missing put_device() when vm_cmdline_parent registration failed
authorchengkaitao <pilgrimtao@gmail.com>
Thu, 2 Jun 2022 00:55:42 +0000 (08:55 +0800)
committerMichael S. Tsirkin <mst@redhat.com>
Wed, 8 Jun 2022 12:56:03 +0000 (08:56 -0400)
The reference must be released when device_register(&vm_cmdline_parent)
failed. Add the corresponding 'put_device()' in the error handling path.

Signed-off-by: chengkaitao <pilgrimtao@gmail.com>
Message-Id: <20220602005542.16489-1-chengkaitao@didiglobal.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
Acked-by: Jason Wang <jasowang@redhat.com>
drivers/virtio/virtio_mmio.c

index f9a36bc7ac27e1f32d6192b3cb68da31c36c315b..5ce79bf9f92b7fa5b339502a9c788f4c2b135dd4 100644 (file)
@@ -701,6 +701,7 @@ static int vm_cmdline_set(const char *device,
        if (!vm_cmdline_parent_registered) {
                err = device_register(&vm_cmdline_parent);
                if (err) {
+                       put_device(&vm_cmdline_parent);
                        pr_err("Failed to register parent device!\n");
                        return err;
                }