Skip to contentSkip to conversation

tpm/tpm_ftpm_tee: Fix error handling in ftpm_mod_init()

PATCH Applied Yuan Can 3 participants 4 messages Nov 24, 2022 – Dec 4, 2022

Subsystems (2)
lore
Share & tools
lore

Yuan Can

author
#0 lore raw

PATCH 1/1 tpm/tpm_ftpm_tee: Fix error handling in ftpm_mod_init()

The ftpm_mod_init() returns the driver_register() directly without checking its return value, if driver_register() failed, the ftpm_tee_plat_driver is not unregistered.

Fix by unregister ftpm_tee_plat_driver when driver_register() failed.

Fixes 9f1944c23c8c ("tpm_ftpm_tee: register driver on TEE bus")
---
 drivers/char/tpm/tpm_ftpm_tee.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
drivers/char/tpm/tpm_ftpm_tee.c +7 -1
index 5c233423c56f..deff23bb54bf 100644
@@ -397,7 +397,13 @@ static int __init ftpm_mod_init(void)
 	if (rc)
 		return rc;
 
-	return driver_register(&ftpm_tee_driver.driver);
+	rc = driver_register(&ftpm_tee_driver.driver);
+	if (rc) {
+		platform_driver_unregister(&ftpm_tee_plat_driver);
+		return rc;
+	}
+
+	return 0;
 }
 
 static void __exit ftpm_mod_exit(void)
Signature · 1 line
2.17.1
maintainer Acked-by on v1 1/1
#1 lore raw
Quoted 34 lines · Yuan Can

The ftpm_mod_init() returns the driver_register() directly without checking its return value, if driver_register() failed, the ftpm_tee_plat_driver is not unregistered.

Fix by unregister ftpm_tee_plat_driver when driver_register() failed.

Fixes 9f1944c23c8c ("tpm_ftpm_tee: register driver on TEE bus")
---
 drivers/char/tpm/tpm_ftpm_tee.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
drivers/char/tpm/tpm_ftpm_tee.c +7 -1
index 5c233423c56f..deff23bb54bf 100644
@@ -397,7 +397,13 @@ static int __init ftpm_mod_init(void)
 	if (rc)
 		return rc;
 
-	return driver_register(&ftpm_tee_driver.driver);
+	rc = driver_register(&ftpm_tee_driver.driver);
+	if (rc) {
+		platform_driver_unregister(&ftpm_tee_plat_driver);
+		return rc;
+	}
+
+	return 0;
 }
 
 static void __exit ftpm_mod_exit(void)
Signature · 1 line
2.17.1

BR, Jarkko

Reviewed-by
#2 lore raw

yea, for backward compatibility both platfrom_driver and driver_ were supported. Maybe it's time to reconsider this now... Thanks for the clean up fix.

Best regards,
Maxim.

Quoted 40 lines · Jarkko Sakkinen
Quoted 32 lines · Yuan Can

The ftpm_mod_init() returns the driver_register() directly without checking its return value, if driver_register() failed, the ftpm_tee_plat_driver is not unregistered.

Fix by unregister ftpm_tee_plat_driver when driver_register() failed.

Fixes 9f1944c23c8c ("tpm_ftpm_tee: register driver on TEE bus")
---
 drivers/char/tpm/tpm_ftpm_tee.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
drivers/char/tpm/tpm_ftpm_tee.c +7 -2
index 5c233423c56f..deff23bb54bf 100644
@@ -397,7 +397,13 @@ static int __init ftpm_mod_init(void)
      if (rc)
              return rc;
 
-     return driver_register(&ftpm_tee_driver.driver);
+     rc = driver_register(&ftpm_tee_driver.driver);
+     if (rc) {
+             platform_driver_unregister(&ftpm_tee_plat_driver);
+             return rc;
+     }
+
+     return 0;
 }
 
 static void __exit ftpm_mod_exit(void)
--
Quoted 2 lines

2.17.1

BR, Jarkko

maintainer Applied
#3 lore raw
Quoted 5 lines · Maxim Uvarov

yea, for backward compatibility both platfrom_driver and driver_ were supported. Maybe it's time to reconsider this now... Thanks for the clean up fix.

Applied to git://git.kernel.org/pub/scm/linux/kernel/git/jarkko/linux-tpmdd.git

Quoted 2 lines

Best regards,
Maxim.

BR, Jarkko