qemu_fw_cfg: don't leak kobj on init error
authorMichael S. Tsirkin <mst@redhat.com>
Sun, 3 Apr 2016 12:22:08 +0000 (15:22 +0300)
committerMichael S. Tsirkin <mst@redhat.com>
Thu, 7 Apr 2016 12:16:39 +0000 (15:16 +0300)
If platform_driver_register fails, we should
cleanup fw_cfg_top_ko before exiting.

Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
Acked-by: Gabriel Somlo <somlo@cmu.edu>
drivers/firmware/qemu_fw_cfg.c

index fedbff55a7f3848872b7d0196086bc0f56caa0c7..e4c471413d46e52edd752ae3a8152ee8289972ee 100644 (file)
@@ -727,12 +727,18 @@ device_param_cb(mmio, &fw_cfg_cmdline_param_ops, NULL, S_IRUSR);
 
 static int __init fw_cfg_sysfs_init(void)
 {
+       int ret;
+
        /* create /sys/firmware/qemu_fw_cfg/ top level directory */
        fw_cfg_top_ko = kobject_create_and_add("qemu_fw_cfg", firmware_kobj);
        if (!fw_cfg_top_ko)
                return -ENOMEM;
 
-       return platform_driver_register(&fw_cfg_sysfs_driver);
+       ret = platform_driver_register(&fw_cfg_sysfs_driver);
+       if (ret)
+               fw_cfg_kobj_cleanup(fw_cfg_top_ko);
+
+       return ret;
 }
 
 static void __exit fw_cfg_sysfs_exit(void)