@@ -237,9 +237,7 @@ void tpm_buf_append_name(struct tpm_chip *chip, struct tpm_buf *buf,
237237#endif
238238
239239 if (!tpm2_chip_auth (chip )) {
240- tpm_buf_append_u32 (buf , handle );
241- /* count the number of handles in the upper bits of flags */
242- buf -> handles ++ ;
240+ tpm_buf_append_handle (chip , buf , handle );
243241 return ;
244242 }
245243
@@ -272,6 +270,31 @@ void tpm_buf_append_name(struct tpm_chip *chip, struct tpm_buf *buf,
272270}
273271EXPORT_SYMBOL_GPL (tpm_buf_append_name );
274272
273+ void tpm_buf_append_auth (struct tpm_chip * chip , struct tpm_buf * buf ,
274+ u8 attributes , u8 * passphrase , int passphrase_len )
275+ {
276+ /* offset tells us where the sessions area begins */
277+ int offset = buf -> handles * 4 + TPM_HEADER_SIZE ;
278+ u32 len = 9 + passphrase_len ;
279+
280+ if (tpm_buf_length (buf ) != offset ) {
281+ /* not the first session so update the existing length */
282+ len += get_unaligned_be32 (& buf -> data [offset ]);
283+ put_unaligned_be32 (len , & buf -> data [offset ]);
284+ } else {
285+ tpm_buf_append_u32 (buf , len );
286+ }
287+ /* auth handle */
288+ tpm_buf_append_u32 (buf , TPM2_RS_PW );
289+ /* nonce */
290+ tpm_buf_append_u16 (buf , 0 );
291+ /* attributes */
292+ tpm_buf_append_u8 (buf , 0 );
293+ /* passphrase */
294+ tpm_buf_append_u16 (buf , passphrase_len );
295+ tpm_buf_append (buf , passphrase , passphrase_len );
296+ }
297+
275298/**
276299 * tpm_buf_append_hmac_session() - Append a TPM session element
277300 * @chip: the TPM chip structure
@@ -309,26 +332,8 @@ void tpm_buf_append_hmac_session(struct tpm_chip *chip, struct tpm_buf *buf,
309332#endif
310333
311334 if (!tpm2_chip_auth (chip )) {
312- /* offset tells us where the sessions area begins */
313- int offset = buf -> handles * 4 + TPM_HEADER_SIZE ;
314- u32 len = 9 + passphrase_len ;
315-
316- if (tpm_buf_length (buf ) != offset ) {
317- /* not the first session so update the existing length */
318- len += get_unaligned_be32 (& buf -> data [offset ]);
319- put_unaligned_be32 (len , & buf -> data [offset ]);
320- } else {
321- tpm_buf_append_u32 (buf , len );
322- }
323- /* auth handle */
324- tpm_buf_append_u32 (buf , TPM2_RS_PW );
325- /* nonce */
326- tpm_buf_append_u16 (buf , 0 );
327- /* attributes */
328- tpm_buf_append_u8 (buf , 0 );
329- /* passphrase */
330- tpm_buf_append_u16 (buf , passphrase_len );
331- tpm_buf_append (buf , passphrase , passphrase_len );
335+ tpm_buf_append_auth (chip , buf , attributes , passphrase ,
336+ passphrase_len );
332337 return ;
333338 }
334339
@@ -948,10 +953,13 @@ static int tpm2_load_null(struct tpm_chip *chip, u32 *null_key)
948953 /* Deduce from the name change TPM interference: */
949954 dev_err (& chip -> dev , "null key integrity check failed\n" );
950955 tpm2_flush_context (chip , tmp_null_key );
951- chip -> flags |= TPM_CHIP_FLAG_DISABLE ;
952956
953957err :
954- return rc ? - ENODEV : 0 ;
958+ if (rc ) {
959+ chip -> flags |= TPM_CHIP_FLAG_DISABLE ;
960+ rc = - ENODEV ;
961+ }
962+ return rc ;
955963}
956964
957965/**
0 commit comments