Skip to content

Commit 9d68320

Browse files
Claudio Carvalhostewartsmith
authored andcommitted
tpm_i2c_nuvoton: cleanup variables in tpm_read_fifo()
The tpm_read_fifo() has unnecessary and not so intuitive variables. This cleans up these variables. Signed-off-by: Claudio Carvalho <cclaudio@linux.vnet.ibm.com> Signed-off-by: Stewart Smith <stewart@linux.vnet.ibm.com>
1 parent 0eb2fc7 commit 9d68320

File tree

1 file changed

+11
-17
lines changed

1 file changed

+11
-17
lines changed

libstb/drivers/tpm_i2c_nuvoton.c

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -357,44 +357,38 @@ static int tpm_write_fifo(uint8_t* buf, size_t buflen)
357357
static int tpm_read_fifo(uint8_t* buf, size_t* buflen)
358358
{
359359
int rc, burst_count;
360-
size_t curByte = 0;
361-
uint8_t* bytePtr = (uint8_t*)buf;
362-
uint8_t* curBytePtr = NULL;
360+
size_t count;
363361

364362
rc = tpm_wait_for_data_avail();
365363
if (rc < 0)
366364
goto error;
367365

366+
count = 0;
368367
do {
369368
burst_count = tpm_read_burst_count();
370369
if (burst_count < 0) {
371370
rc = burst_count;
372371
goto error;
373372
}
374-
/* Buffer overflow check */
375-
if (curByte + burst_count > *buflen)
376-
{
373+
if (count + burst_count > *buflen) {
377374
/**
378-
* @fwts-label TPMReadFifoOverflow1
375+
* @fwts-label TPMReadFifoOverflow
379376
* @fwts-advice The read from TPM FIFO overflowed. It is
380377
* expecting more data even though we think we are done.
381378
* This indicates a bug in the TPM device driver.
382379
*/
383-
prlog(PR_ERR, "TPM: read FIFO overflow1\n");
380+
prlog(PR_ERR, "NUVOTON: overflow on fifo read, c=%zd, "
381+
"bc=%d, bl=%zd\n", count, burst_count, *buflen);
384382
rc = STB_TPM_OVERFLOW;
385383
}
386-
/*
387-
* Read some data
388-
*/
389-
curBytePtr = &(bytePtr[curByte]);
390384
rc = tpm_i2c_request_send(tpm_device->bus_id,
391385
tpm_device->xscom_base,
392386
SMBUS_READ,
393387
TPM_DATA_FIFO_R, 1,
394-
curBytePtr, burst_count);
395-
curByte += burst_count;
396-
DBG("%s read FIFO. received %zd bytes, rc=%d\n",
397-
(rc) ? "!!!!" : "----", curByte, rc);
388+
&buf[count], burst_count);
389+
count += burst_count;
390+
DBG("%s FIFO: %d bytes read, count=%zd, rc=%d\n",
391+
(rc) ? "!!!!" : "----", burst_count, count, rc);
398392
if (rc < 0)
399393
goto error;
400394
rc = tpm_wait_for_fifo_status(
@@ -404,7 +398,7 @@ static int tpm_read_fifo(uint8_t* buf, size_t* buflen)
404398
goto error;
405399
} while (rc == 0);
406400

407-
*buflen = curByte;
401+
*buflen = count;
408402
return 0;
409403

410404
error:

0 commit comments

Comments
 (0)