Skip to contentSkip to conversation

ARM: pxa: Fix error handling in viper_tpm_init

PATCH In review Miaoqian Lin 2 participants 2 messages Dec 27, 2021

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ARM: pxa: Fix error handling in viper_tpm_init

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.")
---
 arch/arm/mach-pxa/viper.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)
arch/arm/mach-pxa/viper.c +4 -5
index 3aa34e9a15d3..9a0f184dbecb 100644
@@ -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);
 }
Signature · 1 line
2.17.1
maintainer
#1 lore raw

Hi,

Quoted 3 lines · Miaoqian Lin

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

Quoted 27 lines
Fixes 352699a ("Basic support for the Arcom/Eurotech Viper SBC.")
---
  arch/arm/mach-pxa/viper.c | 9 ++++-----
  1 file changed, 4 insertions(+), 5 deletions(-)
arch/arm/mach-pxa/viper.c +2 -2
index 3aa34e9a15d3..9a0f184dbecb 100644
@@ -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)
  	}

arch/arm/mach-pxa/viper.c static void __init viper_tpm_init(void) · line 834

Quoted 10 lines
arch/arm/mach-pxa/viper.c +2 -3
 
  	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);
  }

_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel