diff mbox series

tpm/tpm_ftpm_tee: Fix error handling in ftpm_mod_init()

Message ID 20221124031926.16963-1-yuancan@huawei.com (mailing list archive)
State New
Headers show
Series tpm/tpm_ftpm_tee: Fix error handling in ftpm_mod_init() | expand

Commit Message

Yuan Can Nov. 24, 2022, 3:19 a.m. UTC
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")
Signed-off-by: Yuan Can <yuancan@huawei.com>
---
 drivers/char/tpm/tpm_ftpm_tee.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

Comments

Jarkko Sakkinen Nov. 28, 2022, 1:23 a.m. UTC | #1
On Thu, Nov 24, 2022 at 03:19:26AM +0000, Yuan Can wrote:
> 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")
> Signed-off-by: Yuan Can <yuancan@huawei.com>
> ---
>  drivers/char/tpm/tpm_ftpm_tee.c | 8 +++++++-
>  1 file changed, 7 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/char/tpm/tpm_ftpm_tee.c b/drivers/char/tpm/tpm_ftpm_tee.c
> index 5c233423c56f..deff23bb54bf 100644
> --- a/drivers/char/tpm/tpm_ftpm_tee.c
> +++ b/drivers/char/tpm/tpm_ftpm_tee.c
> @@ -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)
> -- 
> 2.17.1
> 

Acked-by: Jarkko Sakkinen <jarkko@kernel.org>

BR, Jarkko
Maxim Uvarov Nov. 28, 2022, 6:42 a.m. UTC | #2
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.

Reviewed-by: Maxim Uvarov <maxim.uvarov@linaro.org>

Best regards,
Maxim.

On Mon, 28 Nov 2022 at 04:23, Jarkko Sakkinen <jarkko@kernel.org> wrote:
>
> On Thu, Nov 24, 2022 at 03:19:26AM +0000, Yuan Can wrote:
> > 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")
> > Signed-off-by: Yuan Can <yuancan@huawei.com>
> > ---
> >  drivers/char/tpm/tpm_ftpm_tee.c | 8 +++++++-
> >  1 file changed, 7 insertions(+), 1 deletion(-)
> >
> > diff --git a/drivers/char/tpm/tpm_ftpm_tee.c b/drivers/char/tpm/tpm_ftpm_tee.c
> > index 5c233423c56f..deff23bb54bf 100644
> > --- a/drivers/char/tpm/tpm_ftpm_tee.c
> > +++ b/drivers/char/tpm/tpm_ftpm_tee.c
> > @@ -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)
> > --
> > 2.17.1
> >
>
> Acked-by: Jarkko Sakkinen <jarkko@kernel.org>
>
> BR, Jarkko
Jarkko Sakkinen Dec. 4, 2022, 4:59 p.m. UTC | #3
On Mon, Nov 28, 2022 at 09:42:15AM +0300, Maxim Uvarov wrote:
> 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.
> 
> Reviewed-by: Maxim Uvarov <maxim.uvarov@linaro.org>

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

> Best regards,
> Maxim.

BR, Jarkko
diff mbox series

Patch

diff --git a/drivers/char/tpm/tpm_ftpm_tee.c b/drivers/char/tpm/tpm_ftpm_tee.c
index 5c233423c56f..deff23bb54bf 100644
--- a/drivers/char/tpm/tpm_ftpm_tee.c
+++ b/drivers/char/tpm/tpm_ftpm_tee.c
@@ -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)