Skip to content

Commit 020a0d8

Browse files
u1f35cjarkkojs
authored andcommitted
tpm: Remove tpm_find_get_ops
tpm_find_get_ops() looks for the first valid TPM if the caller passes in NULL. All internal users have been converted to either associate themselves with a TPM directly, or call tpm_default_chip() as part of their setup. Remove the no longer necessary tpm_find_get_ops(). Reviewed-by: Jarkko Sakkinen <jarkko@kernel.org> Signed-off-by: Jonathan McDowell <noodles@meta.com> Signed-off-by: Jarkko Sakkinen <jarkko@kernel.org>
1 parent e68407b commit 020a0d8

4 files changed

Lines changed: 17 additions & 43 deletions

File tree

drivers/char/tpm/tpm-chip.c

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -230,42 +230,6 @@ struct tpm_chip *tpm_default_chip(void)
230230
}
231231
EXPORT_SYMBOL_GPL(tpm_default_chip);
232232

233-
/**
234-
* tpm_find_get_ops() - find and reserve a TPM chip
235-
* @chip: a &struct tpm_chip instance, %NULL for the default chip
236-
*
237-
* Finds a TPM chip and reserves its class device and operations. The chip must
238-
* be released with tpm_put_ops() after use.
239-
* This function is for internal use only. It supports existing TPM callers
240-
* by accepting NULL, but those callers should be converted to pass in a chip
241-
* directly.
242-
*
243-
* Return:
244-
* A reserved &struct tpm_chip instance.
245-
* %NULL if a chip is not found.
246-
* %NULL if the chip is not available.
247-
*/
248-
struct tpm_chip *tpm_find_get_ops(struct tpm_chip *chip)
249-
{
250-
int rc;
251-
252-
if (chip) {
253-
if (!tpm_try_get_ops(chip))
254-
return chip;
255-
return NULL;
256-
}
257-
258-
chip = tpm_default_chip();
259-
if (!chip)
260-
return NULL;
261-
rc = tpm_try_get_ops(chip);
262-
/* release additional reference we got from tpm_default_chip() */
263-
put_device(&chip->dev);
264-
if (rc)
265-
return NULL;
266-
return chip;
267-
}
268-
269233
/**
270234
* tpm_dev_release() - free chip memory and the device number
271235
* @dev: the character device for the TPM chip

drivers/char/tpm/tpm-interface.c

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -313,10 +313,13 @@ int tpm_is_tpm2(struct tpm_chip *chip)
313313
{
314314
int rc;
315315

316-
chip = tpm_find_get_ops(chip);
317316
if (!chip)
318317
return -ENODEV;
319318

319+
rc = tpm_try_get_ops(chip);
320+
if (rc)
321+
return rc;
322+
320323
rc = (chip->flags & TPM_CHIP_FLAG_TPM2) != 0;
321324

322325
tpm_put_ops(chip);
@@ -338,10 +341,13 @@ int tpm_pcr_read(struct tpm_chip *chip, u32 pcr_idx,
338341
{
339342
int rc;
340343

341-
chip = tpm_find_get_ops(chip);
342344
if (!chip)
343345
return -ENODEV;
344346

347+
rc = tpm_try_get_ops(chip);
348+
if (rc)
349+
return rc;
350+
345351
if (chip->flags & TPM_CHIP_FLAG_TPM2)
346352
rc = tpm2_pcr_read(chip, pcr_idx, digest, NULL);
347353
else
@@ -369,10 +375,13 @@ int tpm_pcr_extend(struct tpm_chip *chip, u32 pcr_idx,
369375
int rc;
370376
int i;
371377

372-
chip = tpm_find_get_ops(chip);
373378
if (!chip)
374379
return -ENODEV;
375380

381+
rc = tpm_try_get_ops(chip);
382+
if (rc)
383+
return rc;
384+
376385
for (i = 0; i < chip->nr_allocated_banks; i++) {
377386
if (digests[i].alg_id != chip->allocated_banks[i].alg_id) {
378387
rc = -EINVAL;
@@ -492,10 +501,13 @@ int tpm_get_random(struct tpm_chip *chip, u8 *out, size_t max)
492501
if (!out || max > TPM_MAX_RNG_DATA)
493502
return -EINVAL;
494503

495-
chip = tpm_find_get_ops(chip);
496504
if (!chip)
497505
return -ENODEV;
498506

507+
rc = tpm_try_get_ops(chip);
508+
if (rc)
509+
return rc;
510+
499511
if (chip->flags & TPM_CHIP_FLAG_TPM2)
500512
rc = tpm2_get_random(chip, out, max);
501513
else

drivers/char/tpm/tpm.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,6 @@ static inline void tpm_msleep(unsigned int delay_msec)
267267
int tpm_chip_bootstrap(struct tpm_chip *chip);
268268
int tpm_chip_start(struct tpm_chip *chip);
269269
void tpm_chip_stop(struct tpm_chip *chip);
270-
struct tpm_chip *tpm_find_get_ops(struct tpm_chip *chip);
271270

272271
struct tpm_chip *tpm_chip_alloc(struct device *dev,
273272
const struct tpm_class_ops *ops);

drivers/char/tpm/tpm_tis_core.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -265,8 +265,7 @@ static u8 tpm_tis_status(struct tpm_chip *chip)
265265

266266
/*
267267
* Dump stack for forensics, as invalid TPM_STS.x could be
268-
* potentially triggered by impaired tpm_try_get_ops() or
269-
* tpm_find_get_ops().
268+
* potentially triggered by impaired tpm_try_get_ops().
270269
*/
271270
dump_stack();
272271
}

0 commit comments

Comments
 (0)