diff mbox series

[v5,06/29] tpm: Don't cleanup unless an error happens

Message ID 20200408165737.v5.6.Ic7e63c1f960c3adab3a1c03a61a56c4199fc7074@changeid
State Superseded
Headers show
Series dm: Add programmatic generation of ACPI tables (part A) | expand

Commit Message

Simon Glass April 8, 2020, 10:57 p.m. UTC
At present the cleanup() method is called on every transfer. It should
only be called on failing transfers. Fix this and tidy up the error
handling a little.

Signed-off-by: Simon Glass <sjg at chromium.org>
Reviewed-by: Bin Meng <bmeng.cn at gmail.com>
---

Changes in v5: None
Changes in v4: None
Changes in v3: None
Changes in v2: None

 drivers/tpm/tpm-uclass.c | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)

Comments

Bin Meng April 16, 2020, 5:33 a.m. UTC | #1
On Thu, Apr 9, 2020 at 6:58 AM Simon Glass <sjg at chromium.org> wrote:
>
> At present the cleanup() method is called on every transfer. It should
> only be called on failing transfers. Fix this and tidy up the error
> handling a little.
>
> Signed-off-by: Simon Glass <sjg at chromium.org>
> Reviewed-by: Bin Meng <bmeng.cn at gmail.com>
> ---
>
> Changes in v5: None
> Changes in v4: None
> Changes in v3: None
> Changes in v2: None
>
>  drivers/tpm/tpm-uclass.c | 13 ++++++++++---
>  1 file changed, 10 insertions(+), 3 deletions(-)
>

applied to u-boot-x86, thanks!
diff mbox series

Patch

diff --git a/drivers/tpm/tpm-uclass.c b/drivers/tpm/tpm-uclass.c
index 1b11c93194d..71d58070062 100644
--- a/drivers/tpm/tpm-uclass.c
+++ b/drivers/tpm/tpm-uclass.c
@@ -72,7 +72,7 @@  int tpm_xfer(struct udevice *dev, const uint8_t *sendbuf, size_t send_size,
 	struct tpm_ops *ops = tpm_get_ops(dev);
 	ulong start, stop;
 	uint count, ordinal;
-	int ret, ret2;
+	int ret, ret2 = 0;
 
 	if (ops->xfer)
 		return ops->xfer(dev, sendbuf, send_size, recvbuf, recv_size);
@@ -120,9 +120,16 @@  int tpm_xfer(struct udevice *dev, const uint8_t *sendbuf, size_t send_size,
 		}
 	} while (ret);
 
-	ret2 = ops->cleanup ? ops->cleanup(dev) : 0;
+	if (ret) {
+		if (ops->cleanup) {
+			ret2 = ops->cleanup(dev);
+			if (ret2)
+				return log_msg_ret("cleanup", ret2);
+		}
+		return log_msg_ret("xfer", ret);
+	}
 
-	return ret2 ? ret2 : ret;
+	return 0;
 }
 
 UCLASS_DRIVER(tpm) = {