firmware: vpd: Destroy vpd sections in remove function
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.
--- drivers/firmware/google/vpd.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-)
drivers/firmware/google/vpd.c +9 -2
@@ -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
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.
--- drivers/firmware/google/vpd.c | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-)
drivers/firmware/google/vpd.c +13 -6
@@ -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
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/vpdif the device is not instantiated, so tie its lifetime to the device.Fixes 049a59db34eb ("firmware: Google VPD sysfs driver")Signed-off-by Guenter Roeck <[email protected]>
Quoted 58 lines
--- drivers/firmware/google/vpd.c | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-)drivers/firmware/google/vpd.c +13
-6@@ -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
PATCH 3/3 firmware: vpd: Fix platform driver and device registration/unregistration
In reply to Guenter RoeckThe driver exit function needs to unregister both platform device and driver. Also, during registration, register driver first and perform error checks.
--- drivers/firmware/google/vpd.c | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-)
drivers/firmware/google/vpd.c +13 -5
@@ -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
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")Signed-off-by Guenter Roeck <[email protected]>
Quoted 46 lines
--- drivers/firmware/google/vpd.c | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-)drivers/firmware/google/vpd.c +13
-5@@ -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
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")Signed-off-by Guenter Roeck <[email protected]>
Quoted 38 lines
--- drivers/firmware/google/vpd.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-)drivers/firmware/google/vpd.c +9
-2@@ -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
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")Signed-off-by Guenter Roeck <[email protected]>--- drivers/firmware/google/vpd.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-)
For all 3 patches:
Thanks.
Signature · 1 line
~Randy