mirror of
https://github.com/AuxXxilium/linux_dsm_epyc7002.git
synced 2024-11-24 14:41:02 +07:00
tpm: Simplify the measurements loop
The responsibility of tpm1_bios_measurements_start() is to walk over the first *pos measurements, ensuring the skipped and to-be-read measurements are not out-of-boundary. This commit simplifies the loop by employing a do-while loop with the necessary sanity check. Signed-off-by: Jia Zhang <zhang.jia@linux.alibaba.com> Reviewd-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com> Signed-off-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
This commit is contained in:
parent
442601e87a
commit
bb3b6b0fc5
@ -74,7 +74,7 @@ static const char* tcpa_pc_event_id_strings[] = {
|
||||
/* returns pointer to start of pos. entry of tcg log */
|
||||
static void *tpm1_bios_measurements_start(struct seq_file *m, loff_t *pos)
|
||||
{
|
||||
loff_t i;
|
||||
loff_t i = 0;
|
||||
struct tpm_chip *chip = m->private;
|
||||
struct tpm_bios_log *log = &chip->log;
|
||||
void *addr = log->bios_event_log;
|
||||
@ -83,38 +83,29 @@ static void *tpm1_bios_measurements_start(struct seq_file *m, loff_t *pos)
|
||||
u32 converted_event_size;
|
||||
u32 converted_event_type;
|
||||
|
||||
|
||||
/* read over *pos measurements */
|
||||
for (i = 0; i < *pos; i++) {
|
||||
do {
|
||||
event = addr;
|
||||
|
||||
/* check if current entry is valid */
|
||||
if (addr + sizeof(struct tcpa_event) >= limit)
|
||||
return NULL;
|
||||
|
||||
converted_event_size =
|
||||
do_endian_conversion(event->event_size);
|
||||
converted_event_type =
|
||||
do_endian_conversion(event->event_type);
|
||||
|
||||
if ((addr + sizeof(struct tcpa_event)) < limit) {
|
||||
if ((converted_event_type == 0) &&
|
||||
(converted_event_size == 0))
|
||||
return NULL;
|
||||
addr += (sizeof(struct tcpa_event) +
|
||||
converted_event_size);
|
||||
}
|
||||
}
|
||||
if (((converted_event_type == 0) && (converted_event_size == 0))
|
||||
|| ((addr + sizeof(struct tcpa_event) + converted_event_size)
|
||||
>= limit))
|
||||
return NULL;
|
||||
|
||||
/* now check if current entry is valid */
|
||||
if ((addr + sizeof(struct tcpa_event)) >= limit)
|
||||
return NULL;
|
||||
if (i++ == *pos)
|
||||
break;
|
||||
|
||||
event = addr;
|
||||
|
||||
converted_event_size = do_endian_conversion(event->event_size);
|
||||
converted_event_type = do_endian_conversion(event->event_type);
|
||||
|
||||
if (((converted_event_type == 0) && (converted_event_size == 0))
|
||||
|| ((addr + sizeof(struct tcpa_event) + converted_event_size)
|
||||
>= limit))
|
||||
return NULL;
|
||||
addr += (sizeof(struct tcpa_event) + converted_event_size);
|
||||
} while (1);
|
||||
|
||||
return addr;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user