firmware: vpd: Tie firmware kobject to device lifetime
authorGuenter Roeck <linux@roeck-us.net>
Wed, 15 Nov 2017 21:00:44 +0000 (13:00 -0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Tue, 28 Nov 2017 15:57:18 +0000 (16:57 +0100)
It doesn't make sense to have /sys/firmware/vpd if the device is not
instantiated, so tie its lifetime to the device.

Fixes: 049a59db34eb ("firmware: Google VPD sysfs driver")
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Cc: stable <stable@vger.kernel.org>
Reviewed-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
Tested-by: Randy Dunlap <rdunlap@infradead.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/firmware/google/vpd.c

index 84217172297b6786bce1dea1449136fb2075dceb..942e358efa602611f8e09eaa162e2e06e8d2885b 100644 (file)
@@ -295,7 +295,17 @@ static int vpd_probe(struct platform_device *pdev)
        if (ret)
                return ret;
 
-       return vpd_sections_init(entry.cbmem_addr);
+       vpd_kobj = kobject_create_and_add("vpd", firmware_kobj);
+       if (!vpd_kobj)
+               return -ENOMEM;
+
+       ret = vpd_sections_init(entry.cbmem_addr);
+       if (ret) {
+               kobject_put(vpd_kobj);
+               return ret;
+       }
+
+       return 0;
 }
 
 static int vpd_remove(struct platform_device *pdev)
@@ -303,6 +313,8 @@ static int vpd_remove(struct platform_device *pdev)
        vpd_section_destroy(&ro_vpd);
        vpd_section_destroy(&rw_vpd);
 
+       kobject_put(vpd_kobj);
+
        return 0;
 }
 
@@ -322,10 +334,6 @@ static int __init vpd_platform_init(void)
        if (IS_ERR(pdev))
                return PTR_ERR(pdev);
 
-       vpd_kobj = kobject_create_and_add("vpd", firmware_kobj);
-       if (!vpd_kobj)
-               return -ENOMEM;
-
        platform_driver_register(&vpd_driver);
 
        return 0;
@@ -333,7 +341,6 @@ static int __init vpd_platform_init(void)
 
 static void __exit vpd_platform_exit(void)
 {
-       kobject_put(vpd_kobj);
 }
 
 module_init(vpd_platform_init);