tpm: Remove duplicate code from caps_show() in tpm-sysfs.c
Replace existing TPM 1.x version structs with new structs that consolidate the common parts into a single struct so that code duplication is no longer needed in caps_show(). Cc: Peter Huewe <peterhuewe@gmx.de> Cc: Jason Gunthorpe <jgg@ziepe.ca> Cc: Alexey Klimov <aklimov@redhat.com> Reviewed-by: Jerry Snitselaar <jsnitsel@redhat.com> Tested-by: Jerry Snitselaar <jsnitsel@redhat.com> Signed-off-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
This commit is contained in:
parent
eb094f0696
commit
f2f5820e3b
|
@ -217,6 +217,7 @@ static ssize_t caps_show(struct device *dev, struct device_attribute *attr,
|
||||||
char *buf)
|
char *buf)
|
||||||
{
|
{
|
||||||
struct tpm_chip *chip = to_tpm_chip(dev);
|
struct tpm_chip *chip = to_tpm_chip(dev);
|
||||||
|
struct tpm1_version *version;
|
||||||
ssize_t rc = 0;
|
ssize_t rc = 0;
|
||||||
char *str = buf;
|
char *str = buf;
|
||||||
cap_t cap;
|
cap_t cap;
|
||||||
|
@ -232,31 +233,31 @@ static ssize_t caps_show(struct device *dev, struct device_attribute *attr,
|
||||||
str += sprintf(str, "Manufacturer: 0x%x\n",
|
str += sprintf(str, "Manufacturer: 0x%x\n",
|
||||||
be32_to_cpu(cap.manufacturer_id));
|
be32_to_cpu(cap.manufacturer_id));
|
||||||
|
|
||||||
/* Try to get a TPM version 1.2 TPM_CAP_VERSION_INFO */
|
/* TPM 1.2 */
|
||||||
rc = tpm1_getcap(chip, TPM_CAP_VERSION_1_2, &cap,
|
if (!tpm1_getcap(chip, TPM_CAP_VERSION_1_2, &cap,
|
||||||
"attempting to determine the 1.2 version",
|
"attempting to determine the 1.2 version",
|
||||||
sizeof(cap.tpm_version_1_2));
|
sizeof(cap.version2))) {
|
||||||
if (!rc) {
|
version = &cap.version2.version;
|
||||||
str += sprintf(str,
|
goto out_print;
|
||||||
"TCG version: %d.%d\nFirmware version: %d.%d\n",
|
}
|
||||||
cap.tpm_version_1_2.Major,
|
|
||||||
cap.tpm_version_1_2.Minor,
|
/* TPM 1.1 */
|
||||||
cap.tpm_version_1_2.revMajor,
|
|
||||||
cap.tpm_version_1_2.revMinor);
|
|
||||||
} else {
|
|
||||||
/* Otherwise just use TPM_STRUCT_VER */
|
|
||||||
if (tpm1_getcap(chip, TPM_CAP_VERSION_1_1, &cap,
|
if (tpm1_getcap(chip, TPM_CAP_VERSION_1_1, &cap,
|
||||||
"attempting to determine the 1.1 version",
|
"attempting to determine the 1.1 version",
|
||||||
sizeof(cap.tpm_version)))
|
sizeof(cap.version1))) {
|
||||||
goto out_ops;
|
goto out_ops;
|
||||||
|
}
|
||||||
|
|
||||||
|
version = &cap.version1;
|
||||||
|
|
||||||
|
out_print:
|
||||||
str += sprintf(str,
|
str += sprintf(str,
|
||||||
"TCG version: %d.%d\nFirmware version: %d.%d\n",
|
"TCG version: %d.%d\nFirmware version: %d.%d\n",
|
||||||
cap.tpm_version.Major,
|
version->major, version->minor,
|
||||||
cap.tpm_version.Minor,
|
version->rev_major, version->rev_minor);
|
||||||
cap.tpm_version.revMajor,
|
|
||||||
cap.tpm_version.revMinor);
|
|
||||||
}
|
|
||||||
rc = str - buf;
|
rc = str - buf;
|
||||||
|
|
||||||
out_ops:
|
out_ops:
|
||||||
tpm_put_ops(chip);
|
tpm_put_ops(chip);
|
||||||
return rc;
|
return rc;
|
||||||
|
|
|
@ -186,19 +186,16 @@ struct stclear_flags_t {
|
||||||
u8 bGlobalLock;
|
u8 bGlobalLock;
|
||||||
} __packed;
|
} __packed;
|
||||||
|
|
||||||
struct tpm_version_t {
|
struct tpm1_version {
|
||||||
u8 Major;
|
u8 major;
|
||||||
u8 Minor;
|
u8 minor;
|
||||||
u8 revMajor;
|
u8 rev_major;
|
||||||
u8 revMinor;
|
u8 rev_minor;
|
||||||
} __packed;
|
} __packed;
|
||||||
|
|
||||||
struct tpm_version_1_2_t {
|
struct tpm1_version2 {
|
||||||
__be16 tag;
|
__be16 tag;
|
||||||
u8 Major;
|
struct tpm1_version version;
|
||||||
u8 Minor;
|
|
||||||
u8 revMajor;
|
|
||||||
u8 revMinor;
|
|
||||||
} __packed;
|
} __packed;
|
||||||
|
|
||||||
struct timeout_t {
|
struct timeout_t {
|
||||||
|
@ -243,8 +240,8 @@ typedef union {
|
||||||
struct stclear_flags_t stclear_flags;
|
struct stclear_flags_t stclear_flags;
|
||||||
__u8 owned;
|
__u8 owned;
|
||||||
__be32 num_pcrs;
|
__be32 num_pcrs;
|
||||||
struct tpm_version_t tpm_version;
|
struct tpm1_version version1;
|
||||||
struct tpm_version_1_2_t tpm_version_1_2;
|
struct tpm1_version2 version2;
|
||||||
__be32 manufacturer_id;
|
__be32 manufacturer_id;
|
||||||
struct timeout_t timeout;
|
struct timeout_t timeout;
|
||||||
struct duration_t duration;
|
struct duration_t duration;
|
||||||
|
|
Loading…
Reference in New Issue