LKML Archive mirror
 help / color / mirror / Atom feed
* [PATCH] ARM: pxa: Fix error handling in viper_tpm_init
@ 2021-12-27 12:51 Miaoqian Lin
  2021-12-27 15:34 ` Daniel Mack
  0 siblings, 1 reply; 2+ messages in thread
From: Miaoqian Lin @ 2021-12-27 12:51 UTC (permalink / raw)
  Cc: linmq006, Daniel Mack, Haojian Zhuang, Robert Jarzmik,
	Russell King, Marc Zyngier, linux-arm-kernel, linux-kernel

tpm_device get by platform_device_alloc(), which calls device_initialize.
Call platform_device_put(tpm_device) instead of kfree(tmp_device) to
prevent memory leak.

Fixes: 352699a ("Basic support for the Arcom/Eurotech Viper SBC.")
Signed-off-by: Miaoqian Lin <linmq006@gmail.com>
---
 arch/arm/mach-pxa/viper.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/arch/arm/mach-pxa/viper.c b/arch/arm/mach-pxa/viper.c
index 3aa34e9a15d3..9a0f184dbecb 100644
--- a/arch/arm/mach-pxa/viper.c
+++ b/arch/arm/mach-pxa/viper.c
@@ -815,11 +815,11 @@ static void __init viper_tpm_init(void)
 					      sizeof(i2c_tpm_data))) {
 			if (platform_device_add(tpm_device)) {
 				errstr = "register TPM i2c bus";
-				goto error_free_tpm;
+				goto exit_put_device;
 			}
 		} else {
 			errstr = "allocate TPM i2c bus data";
-			goto error_free_tpm;
+			goto exit_put_device;
 		}
 	} else {
 		errstr = "allocate TPM i2c device";
@@ -827,9 +827,8 @@ static void __init viper_tpm_init(void)
 	}
 
 	return;
-
-error_free_tpm:
-	kfree(tpm_device);
+exit_put_device:
+	platform_device_put(tpm_device);
 error_tpm:
 	pr_err("viper: Couldn't %s, giving up\n", errstr);
 }
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] ARM: pxa: Fix error handling in viper_tpm_init
  2021-12-27 12:51 [PATCH] ARM: pxa: Fix error handling in viper_tpm_init Miaoqian Lin
@ 2021-12-27 15:34 ` Daniel Mack
  0 siblings, 0 replies; 2+ messages in thread
From: Daniel Mack @ 2021-12-27 15:34 UTC (permalink / raw)
  To: Miaoqian Lin
  Cc: Haojian Zhuang, Robert Jarzmik, Russell King, Marc Zyngier,
	linux-arm-kernel, linux-kernel

Hi,

On 27/12/2021 13:51, Miaoqian Lin wrote:
> tpm_device get by platform_device_alloc(), which calls device_initialize.
> Call platform_device_put(tpm_device) instead of kfree(tmp_device) to
> prevent memory leak.

While this seems correct, I don't think we should make any effort to 
maintain legacy board support files but rather move to DTS instead. 
Robert and I laid the foundation and ported a few machines a while ago, 
but I was reluctant to touch the board support code I can't test on real 
hardware.

As you seem to have access to a Viper board, could you have a look at 
the existing device-tree ported PXA machines and see if you can follow 
suit here please?


Thanks,
Daniel


> 
> Fixes: 352699a ("Basic support for the Arcom/Eurotech Viper SBC.")
> Signed-off-by: Miaoqian Lin <linmq006@gmail.com>
> ---
>   arch/arm/mach-pxa/viper.c | 9 ++++-----
>   1 file changed, 4 insertions(+), 5 deletions(-)
> 
> diff --git a/arch/arm/mach-pxa/viper.c b/arch/arm/mach-pxa/viper.c
> index 3aa34e9a15d3..9a0f184dbecb 100644
> --- a/arch/arm/mach-pxa/viper.c
> +++ b/arch/arm/mach-pxa/viper.c
> @@ -815,11 +815,11 @@ static void __init viper_tpm_init(void)
>   					      sizeof(i2c_tpm_data))) {
>   			if (platform_device_add(tpm_device)) {
>   				errstr = "register TPM i2c bus";
> -				goto error_free_tpm;
> +				goto exit_put_device;
>   			}
>   		} else {
>   			errstr = "allocate TPM i2c bus data";
> -			goto error_free_tpm;
> +			goto exit_put_device;
>   		}
>   	} else {
>   		errstr = "allocate TPM i2c device";
> @@ -827,9 +827,8 @@ static void __init viper_tpm_init(void)
>   	}
>   
>   	return;
> -
> -error_free_tpm:
> -	kfree(tpm_device);
> +exit_put_device:
> +	platform_device_put(tpm_device);
>   error_tpm:
>   	pr_err("viper: Couldn't %s, giving up\n", errstr);
>   }


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-12-27 15:46 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-12-27 12:51 [PATCH] ARM: pxa: Fix error handling in viper_tpm_init Miaoqian Lin
2021-12-27 15:34 ` Daniel Mack

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).