Hi Aidan,

On 2026-05-13T00:26:04, Aidan Garske <[email protected]> wrote:
> tpm: export tpm_show_device, tpm_set_device, and get_tpm
>
> Remove static scope from tpm_show_device(), tpm_set_device(), and
> get_tpm() in cmd/tpm-common.c so they can be called from other
> translation units. Add corresponding declarations to
> include/tpm-common.h.
>
> wolfTPM's command backend needs these functions for device enumeration
> and selection when operating through U-Boot's driver model.
>
> Signed-off-by: Aidan Garske <[email protected]>
>
> cmd/tpm-common.c     |  4 ++--
>  include/tpm-common.h | 22 ++++++++++++++++++++++
>  2 files changed, 24 insertions(+), 2 deletions(-)

> diff --git a/cmd/tpm-common.c b/cmd/tpm-common.c
> @@ -234,7 +234,7 @@ int type_string_write_vars(const char *type_str, u8 *data,
>       return 0;
>  }
>
> -static int tpm_show_device(void)
> +int tpm_show_device(void)

These three helpers live in cmd/ and operate on a static tpm_dev
private to the command layer. Promoting them so a backend in lib/ or
drivers/ can call into cmd/ is the wrong direction. If the wolfTPM
backend genuinely needs shared 'currently selected TPM' state, please
move that state and these helpers into the TPM uclass and have
cmd/tpm-common.c call into them, not the other way round.

> diff --git a/include/tpm-common.h b/include/tpm-common.h
> @@ -337,4 +337,26 @@ enum tpm_version tpm_get_version(struct udevice *dev);
> +/**
> + * tpm_show_device() - Show all TPM devices
> + *
> + * Return: 0 on success, -ve on failure
> + */
> +int tpm_show_device(void);
> +
> +/**
> + * tpm_set_device() - Set the TPM device to use
> + *
> + * @num: The number of the TPM device to use
> + * Return: 0 on success, -ve on failure
> + */
> +int tpm_set_device(unsigned long num);
> +
> +/**
> + * get_tpm() - Get the TPM device
> + *
> + * Return: 0 on success, -ve on failure
> + */
> +int get_tpm(struct udevice **devp);

The kerneldoc is wrong. tpm_set_device() and get_tpm() return
CMD_RET_FAILURE (1, positive), not -ve. tpm_show_device() ignores
per-device errors and unconditionally returns 0. Either document
accurately, or make tpm_show_device() propagate the failure from
tpm_get_desc().

If these become public API, please also fix the return convention to
use proper negative errnos (CMD_RET_* is a command-layer thing) and
rename get_tpm() - tpm_get_device() or similar. get_tpm() is too
generic for a global symbol.

Also, @devp is undocumented. Please add an entry for it, and note that
the function selects device 0 the first time it is called.

Regards,
Simon

Reply via email to