Skip to content

Commit ea94c08

Browse files
tpm: Make chip->{status,cancel,req_canceled} opt
JIRA: https://issues.redhat.com/browse/RHEL-87276 Upstream Status: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git Conflicts: Downstream is missing 80b8a39 ("tpm/tpm_ftpm_tee: Return true/false (not 1/0) from bool functions") commit 980a573 Author: Jarkko Sakkinen <jarkko@kernel.org> Date: Wed Mar 26 17:55:49 2025 +0200 tpm: Make chip->{status,cancel,req_canceled} opt tpm_ftpm_tee does not require chip->status, chip->cancel and chip->req_canceled. Make them optional. Reviewed-by: Stefano Garzarella <sgarzare@redhat.com> Signed-off-by: Jarkko Sakkinen <jarkko.sakkinen@opinsys.com> Signed-off-by: Jarkko Sakkinen <jarkko@kernel.org> Signed-off-by: Stefano Garzarella <sgarzare@redhat.com>
1 parent 638423b commit ea94c08

File tree

2 files changed

+27
-23
lines changed

2 files changed

+27
-23
lines changed

drivers/char/tpm/tpm-interface.c

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,30 @@ unsigned long tpm_calc_ordinal_duration(struct tpm_chip *chip, u32 ordinal)
5858
}
5959
EXPORT_SYMBOL_GPL(tpm_calc_ordinal_duration);
6060

61+
static void tpm_chip_cancel(struct tpm_chip *chip)
62+
{
63+
if (!chip->ops->cancel)
64+
return;
65+
66+
chip->ops->cancel(chip);
67+
}
68+
69+
static u8 tpm_chip_status(struct tpm_chip *chip)
70+
{
71+
if (!chip->ops->status)
72+
return 0;
73+
74+
return chip->ops->status(chip);
75+
}
76+
77+
static bool tpm_chip_req_canceled(struct tpm_chip *chip, u8 status)
78+
{
79+
if (!chip->ops->req_canceled)
80+
return false;
81+
82+
return chip->ops->req_canceled(chip, status);
83+
}
84+
6185
static ssize_t tpm_try_transmit(struct tpm_chip *chip, void *buf, size_t bufsiz)
6286
{
6387
struct tpm_header *header = buf;
@@ -104,12 +128,12 @@ static ssize_t tpm_try_transmit(struct tpm_chip *chip, void *buf, size_t bufsiz)
104128

105129
stop = jiffies + tpm_calc_ordinal_duration(chip, ordinal);
106130
do {
107-
u8 status = chip->ops->status(chip);
131+
u8 status = tpm_chip_status(chip);
108132
if ((status & chip->ops->req_complete_mask) ==
109133
chip->ops->req_complete_val)
110134
goto out_recv;
111135

112-
if (chip->ops->req_canceled(chip, status)) {
136+
if (tpm_chip_req_canceled(chip, status)) {
113137
dev_err(&chip->dev, "Operation Canceled\n");
114138
return -ECANCELED;
115139
}
@@ -118,7 +142,7 @@ static ssize_t tpm_try_transmit(struct tpm_chip *chip, void *buf, size_t bufsiz)
118142
rmb();
119143
} while (time_before(jiffies, stop));
120144

121-
chip->ops->cancel(chip);
145+
tpm_chip_cancel(chip);
122146
dev_err(&chip->dev, "Operation Timed out\n");
123147
return -ETIME;
124148

drivers/char/tpm/tpm_ftpm_tee.c

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -165,30 +165,10 @@ static int ftpm_tee_tpm_op_send(struct tpm_chip *chip, u8 *buf, size_t len)
165165
return 0;
166166
}
167167

168-
static void ftpm_tee_tpm_op_cancel(struct tpm_chip *chip)
169-
{
170-
/* not supported */
171-
}
172-
173-
static u8 ftpm_tee_tpm_op_status(struct tpm_chip *chip)
174-
{
175-
return 0;
176-
}
177-
178-
static bool ftpm_tee_tpm_req_canceled(struct tpm_chip *chip, u8 status)
179-
{
180-
return 0;
181-
}
182-
183168
static const struct tpm_class_ops ftpm_tee_tpm_ops = {
184169
.flags = TPM_OPS_AUTO_STARTUP,
185170
.recv = ftpm_tee_tpm_op_recv,
186171
.send = ftpm_tee_tpm_op_send,
187-
.cancel = ftpm_tee_tpm_op_cancel,
188-
.status = ftpm_tee_tpm_op_status,
189-
.req_complete_mask = 0,
190-
.req_complete_val = 0,
191-
.req_canceled = ftpm_tee_tpm_req_canceled,
192172
};
193173

194174
/*

0 commit comments

Comments
 (0)