Skip to content

Commit 71b8822

Browse files
Claudio Carvalhostewartsmith
authored andcommitted
tpm_i2c_nuvoton: return burst_count in tpm_read_burst_count()
This returns burst_count as opposed to pass it as a parameter. Signed-off-by: Claudio Carvalho <cclaudio@linux.vnet.ibm.com> Signed-off-by: Stewart Smith <stewart@linux.vnet.ibm.com>
1 parent cd5953d commit 71b8822

File tree

1 file changed

+19
-21
lines changed

1 file changed

+19
-21
lines changed

libstb/drivers/tpm_i2c_nuvoton.c

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -215,22 +215,20 @@ static int tpm_poll_for_data_avail(void)
215215
return STB_TPM_TIMEOUT;
216216
}
217217

218-
static int tpm_read_burst_count(uint8_t* burst_count)
218+
static int tpm_read_burst_count(void)
219219
{
220220
int rc, delay;
221-
uint8_t bc;
221+
uint8_t burst_count;
222222

223+
burst_count = 0;
223224
delay = 0;
224-
*burst_count = 0;
225-
226225
do {
227226
/* In i2C, burstCount is 1 byte */
228-
rc = tpm_status_read_byte(TPM_BURST_COUNT, &bc);
229-
if (rc == 0 && bc > 0) {
230-
DBG("---- burst_count=%d, delay=%d/%d\n",
227+
rc = tpm_status_read_byte(TPM_BURST_COUNT, &burst_count);
228+
if (rc == 0 && burst_count > 0) {
229+
DBG("---- burst_count=%d, delay=%d/%d\n", burst_count,
231230
delay, TPM_TIMEOUT_D);
232-
*burst_count = bc;
233-
return 0;
231+
return (int) burst_count;
234232
}
235233
if (rc < 0) {
236234
/**
@@ -261,8 +259,7 @@ static int tpm_read_burst_count(uint8_t* burst_count)
261259

262260
static int tpm_write_fifo(uint8_t* buf, size_t buflen)
263261
{
264-
uint8_t burst_count = 0;
265-
int rc;
262+
int rc, burst_count;
266263
size_t curByte = 0;
267264
uint8_t* bytePtr = buf;
268265
uint8_t* curBytePtr = NULL;
@@ -275,9 +272,9 @@ static int tpm_write_fifo(uint8_t* buf, size_t buflen)
275272
size_t tx_len = 0;
276273

277274
do {
278-
rc = tpm_read_burst_count(&burst_count);
279-
if (rc < 0)
280-
return rc;
275+
burst_count = tpm_read_burst_count();
276+
if (burst_count < 0)
277+
return burst_count;
281278
/*
282279
* Send in some data
283280
*/
@@ -309,9 +306,9 @@ static int tpm_write_fifo(uint8_t* buf, size_t buflen)
309306
/*
310307
* Send the final byte
311308
*/
312-
rc = tpm_read_burst_count(&burst_count);
313-
if (rc < 0)
314-
return rc;
309+
burst_count = tpm_read_burst_count();
310+
if (burst_count < 0)
311+
return burst_count;
315312
curBytePtr = &(bytePtr[curByte]);
316313
rc = tpm_i2c_request_send(tpm_device->bus_id,
317314
tpm_device->xscom_base,
@@ -339,8 +336,7 @@ static int tpm_write_fifo(uint8_t* buf, size_t buflen)
339336

340337
static int tpm_read_fifo(uint8_t* buf, size_t* buflen)
341338
{
342-
int rc;
343-
uint8_t burst_count;
339+
int rc, burst_count;
344340
size_t curByte = 0;
345341
uint8_t* bytePtr = (uint8_t*)buf;
346342
uint8_t* curBytePtr = NULL;
@@ -350,9 +346,11 @@ static int tpm_read_fifo(uint8_t* buf, size_t* buflen)
350346
goto error;
351347

352348
do {
353-
rc = tpm_read_burst_count(&burst_count);
354-
if (rc < 0)
349+
burst_count = tpm_read_burst_count();
350+
if (burst_count < 0) {
351+
rc = burst_count;
355352
goto error;
353+
}
356354
/* Buffer overflow check */
357355
if (curByte + burst_count > *buflen)
358356
{

0 commit comments

Comments
 (0)