summaryrefslogtreecommitdiff
path: root/drivers/tpm
diff options
context:
space:
mode:
authorSimon Glass <sjg@chromium.org>2020-04-08 16:57:25 -0600
committerBin Meng <bmeng.cn@gmail.com>2020-04-16 14:36:28 +0800
commit88307654af35fd550324fc1d8504db0da7225950 (patch)
tree1727529c41ef6c56a05a81bce48104277756e95d /drivers/tpm
parent32e8ee004a3dad1a9cc06bd3ac44d8ba562afc3e (diff)
downloadu-boot-88307654af35fd550324fc1d8504db0da7225950.tar.gz
tpm: Don't cleanup unless an error happens
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@chromium.org> Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Diffstat (limited to 'drivers/tpm')
-rw-r--r--drivers/tpm/tpm-uclass.c13
1 files changed, 10 insertions, 3 deletions
diff --git a/drivers/tpm/tpm-uclass.c b/drivers/tpm/tpm-uclass.c
index 1b11c93194..71d5807006 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) = {