@@ -95,27 +95,27 @@ static TPM_RC SwTpmTransmit(TPM2_CTX* ctx, const void* buffer, ssize_t bufSz)
9595{
9696 TPM_RC rc = TPM_RC_SUCCESS ;
9797 ssize_t wrc = 0 ;
98+ const char * ptr ;
99+ int remaining ;
98100
99101 if (ctx == NULL || ctx -> tcpCtx .fd < 0 || buffer == NULL ) {
100102 return BAD_FUNC_ARG ;
101103 }
102104
103- {
104- const char * ptr = (const char * )buffer ;
105- int remaining = bufSz ;
106- while (remaining > 0 ) {
107- wrc = write (ctx -> tcpCtx .fd , ptr , remaining );
108- if (wrc <= 0 ) {
109- #ifdef WOLFTPM_DEBUG_VERBOSE
110- printf ("Failed to send the TPM command to fd %d, got errno %d ="
111- "%s\n" , ctx -> tcpCtx .fd , errno , strerror (errno ));
112- #endif
113- rc = TPM_RC_FAILURE ;
114- break ;
115- }
116- remaining -= (int )wrc ;
117- ptr += wrc ;
105+ ptr = (const char * )buffer ;
106+ remaining = bufSz ;
107+ while (remaining > 0 ) {
108+ wrc = write (ctx -> tcpCtx .fd , ptr , remaining );
109+ if (wrc <= 0 ) {
110+ #ifdef WOLFTPM_DEBUG_VERBOSE
111+ printf ("Failed to send the TPM command to fd %d, got errno %d ="
112+ "%s\n" , ctx -> tcpCtx .fd , errno , strerror (errno ));
113+ #endif
114+ rc = TPM_RC_FAILURE ;
115+ break ;
118116 }
117+ remaining -= (int )wrc ;
118+ ptr += wrc ;
119119 }
120120
121121 return rc ;
@@ -170,6 +170,7 @@ static TPM_RC SwTpmConnect(TPM2_CTX* ctx, const char* host, const char* port)
170170 struct termios tty ;
171171 speed_t baud ;
172172 int baudInt ;
173+ struct stat devStat ;
173174
174175 if (ctx == NULL ) {
175176 return BAD_FUNC_ARG ;
@@ -185,12 +186,9 @@ static TPM_RC SwTpmConnect(TPM2_CTX* ctx, const char* host, const char* port)
185186 return TPM_RC_FAILURE ;
186187 }
187188 /* Verify the opened path is a character device */
188- {
189- struct stat st ;
190- if (fstat (fd , & st ) != 0 || !S_ISCHR (st .st_mode )) {
191- close (fd );
192- return TPM_RC_FAILURE ;
193- }
189+ if (fstat (fd , & devStat ) != 0 || !S_ISCHR (devStat .st_mode )) {
190+ close (fd );
191+ return TPM_RC_FAILURE ;
194192 }
195193
196194 /* Configure serial port: 8N1, raw mode, no flow control */
0 commit comments