Skip to contentSkip to conversation

firmware: vpd: Destroy vpd sections in remove function

PATCH In review Guenter Roeck 3 participants 7 messages Nov 15, 2017 – Nov 16, 2017

lore
Share & tools
lore
#0 lore raw

PATCH 1/3 firmware: vpd: Destroy vpd sections in remove function

vpd sections are initialized during probe and thus should be destroyed in the remove function.

Fixes 049a59db34eb ("firmware: Google VPD sysfs driver")
---
 drivers/firmware/google/vpd.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)
drivers/firmware/google/vpd.c +9 -2
index 35e553b3b190..84217172297b 100644
@@ -298,8 +298,17 @@ static int vpd_probe(struct platform_device *pdev)
 	return vpd_sections_init(entry.cbmem_addr);
 }
 
+static int vpd_remove(struct platform_device *pdev)
+{
+	vpd_section_destroy(&ro_vpd);
+	vpd_section_destroy(&rw_vpd);
+
+	return 0;
+}
+
 static struct platform_driver vpd_driver = {
 	.probe = vpd_probe,
+	.remove = vpd_remove,
 	.driver = {
 		.name = "vpd",
 	},
@@ -324,8 +333,6 @@ static int __init vpd_platform_init(void)
 
 static void __exit vpd_platform_exit(void)
 {
-	vpd_section_destroy(&ro_vpd);
-	vpd_section_destroy(&rw_vpd);
 	kobject_put(vpd_kobj);
 }
 
Signature · 1 line
2.7.4
#1 lore raw

PATCH 2/3 firmware: vpd: Tie firmware kobject to device lifetime

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")
---
 drivers/firmware/google/vpd.c | 19 +++++++++++++------
 1 file changed, 13 insertions(+), 6 deletions(-)
drivers/firmware/google/vpd.c +13 -6
index 84217172297b..942e358efa60 100644
@@ -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);
Signature · 1 line
2.7.4
Reviewed-by on v1 2/3
#2 lore raw

Re: [PATCH 2/3] firmware: vpd: Tie firmware kobject to device lifetime

Quoted 5 lines · Guenter Roeck

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")
Quoted 58 lines
---
 drivers/firmware/google/vpd.c | 19 +++++++++++++------
 1 file changed, 13 insertions(+), 6 deletions(-)
drivers/firmware/google/vpd.c +13 -6
index 84217172297b..942e358efa60 100644
@@ -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);
Signature · 1 line
2.7.4
Signature · 1 line
Dmitry
#3 lore raw

PATCH 3/3 firmware: vpd: Fix platform driver and device registration/unregistration

In reply to Guenter Roeck

The driver exit function needs to unregister both platform device and driver. Also, during registration, register driver first and perform error checks.

Fixes 049a59db34eb ("firmware: Google VPD sysfs driver")
---
 drivers/firmware/google/vpd.c | 18 +++++++++++++-----
 1 file changed, 13 insertions(+), 5 deletions(-)
drivers/firmware/google/vpd.c +13 -5
index 942e358efa60..e4b40f2b4627 100644
@@ -326,21 +326,29 @@ static struct platform_driver vpd_driver = {
 	},
 };
 
+static struct platform_device *vpd_pdev;
+
 static int __init vpd_platform_init(void)
 {
-	struct platform_device *pdev;
+	int ret;
 
-	pdev = platform_device_register_simple("vpd", -1, NULL, 0);
-	if (IS_ERR(pdev))
-		return PTR_ERR(pdev);
+	ret = platform_driver_register(&vpd_driver);
+	if (ret)
+		return ret;
 
-	platform_driver_register(&vpd_driver);
+	vpd_pdev = platform_device_register_simple("vpd", -1, NULL, 0);
+	if (IS_ERR(vpd_pdev)) {
+		platform_driver_unregister(&vpd_driver);
+		return PTR_ERR(vpd_pdev);
+	}
 
 	return 0;
 }
 
 static void __exit vpd_platform_exit(void)
 {
+	platform_device_unregister(vpd_pdev);
+	platform_driver_unregister(&vpd_driver);
 }
 
 module_init(vpd_platform_init);
Signature · 1 line
2.7.4
Reviewed-by on v1 3/3
#4 lore raw

Re: [PATCH 3/3] firmware: vpd: Fix platform driver and device registration/unregistration

Quoted 6 lines · Guenter Roeck

The driver exit function needs to unregister both platform device and driver. Also, during registration, register driver first and perform error checks.

Fixes 049a59db34eb ("firmware: Google VPD sysfs driver")
Quoted 46 lines
---
 drivers/firmware/google/vpd.c | 18 +++++++++++++-----
 1 file changed, 13 insertions(+), 5 deletions(-)
drivers/firmware/google/vpd.c +13 -5
index 942e358efa60..e4b40f2b4627 100644
@@ -326,21 +326,29 @@ static struct platform_driver vpd_driver = {
 	},
 };
 
+static struct platform_device *vpd_pdev;
+
 static int __init vpd_platform_init(void)
 {
-	struct platform_device *pdev;
+	int ret;
 
-	pdev = platform_device_register_simple("vpd", -1, NULL, 0);
-	if (IS_ERR(pdev))
-		return PTR_ERR(pdev);
+	ret = platform_driver_register(&vpd_driver);
+	if (ret)
+		return ret;
 
-	platform_driver_register(&vpd_driver);
+	vpd_pdev = platform_device_register_simple("vpd", -1, NULL, 0);
+	if (IS_ERR(vpd_pdev)) {
+		platform_driver_unregister(&vpd_driver);
+		return PTR_ERR(vpd_pdev);
+	}
 
 	return 0;
 }
 
 static void __exit vpd_platform_exit(void)
 {
+	platform_device_unregister(vpd_pdev);
+	platform_driver_unregister(&vpd_driver);
 }
 
 module_init(vpd_platform_init);
Signature · 1 line
2.7.4
Signature · 1 line
Dmitry
Reviewed-by on v1 1/3
#5 lore raw
In reply to Guenter Roeck
Quoted 5 lines · Guenter Roeck

vpd sections are initialized during probe and thus should be destroyed in the remove function.

Fixes 049a59db34eb ("firmware: Google VPD sysfs driver")
Quoted 38 lines
---
 drivers/firmware/google/vpd.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)
drivers/firmware/google/vpd.c +9 -2
index 35e553b3b190..84217172297b 100644
@@ -298,8 +298,17 @@ static int vpd_probe(struct platform_device *pdev)
 	return vpd_sections_init(entry.cbmem_addr);
 }
 
+static int vpd_remove(struct platform_device *pdev)
+{
+	vpd_section_destroy(&ro_vpd);
+	vpd_section_destroy(&rw_vpd);
+
+	return 0;
+}
+
 static struct platform_driver vpd_driver = {
 	.probe = vpd_probe,
+	.remove = vpd_remove,
 	.driver = {
 		.name = "vpd",
 	},
@@ -324,8 +333,6 @@ static int __init vpd_platform_init(void)
 
 static void __exit vpd_platform_exit(void)
 {
-	vpd_section_destroy(&ro_vpd);
-	vpd_section_destroy(&rw_vpd);
 	kobject_put(vpd_kobj);
 }
 
Signature · 1 line
2.7.4
Signature · 1 line
Dmitry
Tested-by on v1 1/3
#6 lore raw
In reply to Guenter Roeck
Quoted 8 lines · Guenter Roeck

vpd sections are initialized during probe and thus should be destroyed in the remove function.

Fixes 049a59db34eb ("firmware: Google VPD sysfs driver")
---
 drivers/firmware/google/vpd.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

For all 3 patches:

Thanks.

Signature · 1 line
~Randy