@@ -32,7 +32,7 @@ static int tpm_bios_measurements_open(struct inode *inode,
3232 struct tpm_chip * chip ;
3333
3434 inode_lock (inode );
35- if (!inode -> i_private ) {
35+ if (!inode -> i_nlink ) {
3636 inode_unlock (inode );
3737 return - ENODEV ;
3838 }
@@ -105,7 +105,7 @@ static int tpm_read_log(struct tpm_chip *chip)
105105void tpm_bios_log_setup (struct tpm_chip * chip )
106106{
107107 const char * name = dev_name (& chip -> dev );
108- unsigned int cnt ;
108+ struct dentry * dentry ;
109109 int log_version ;
110110 int rc = 0 ;
111111
@@ -117,14 +117,12 @@ void tpm_bios_log_setup(struct tpm_chip *chip)
117117 return ;
118118 log_version = rc ;
119119
120- cnt = 0 ;
121- chip -> bios_dir [cnt ] = securityfs_create_dir (name , NULL );
120+ chip -> bios_dir = securityfs_create_dir (name , NULL );
122121 /* NOTE: securityfs_create_dir can return ENODEV if securityfs is
123122 * compiled out. The caller should ignore the ENODEV return code.
124123 */
125- if (IS_ERR (chip -> bios_dir [cnt ]))
126- goto err ;
127- cnt ++ ;
124+ if (IS_ERR (chip -> bios_dir ))
125+ return ;
128126
129127 chip -> bin_log_seqops .chip = chip ;
130128 if (log_version == EFI_TCG2_EVENT_LOG_FORMAT_TCG_2 )
@@ -135,57 +133,37 @@ void tpm_bios_log_setup(struct tpm_chip *chip)
135133 & tpm1_binary_b_measurements_seqops ;
136134
137135
138- chip -> bios_dir [ cnt ] =
136+ dentry =
139137 securityfs_create_file ("binary_bios_measurements" ,
140- 0440 , chip -> bios_dir [ 0 ] ,
138+ 0440 , chip -> bios_dir ,
141139 (void * )& chip -> bin_log_seqops ,
142140 & tpm_bios_measurements_ops );
143- if (IS_ERR (chip -> bios_dir [ cnt ] ))
141+ if (IS_ERR (dentry ))
144142 goto err ;
145- cnt ++ ;
146143
147144 if (!(chip -> flags & TPM_CHIP_FLAG_TPM2 )) {
148145
149146 chip -> ascii_log_seqops .chip = chip ;
150147 chip -> ascii_log_seqops .seqops =
151148 & tpm1_ascii_b_measurements_seqops ;
152149
153- chip -> bios_dir [ cnt ] =
150+ dentry =
154151 securityfs_create_file ("ascii_bios_measurements" ,
155- 0440 , chip -> bios_dir [ 0 ] ,
152+ 0440 , chip -> bios_dir ,
156153 (void * )& chip -> ascii_log_seqops ,
157154 & tpm_bios_measurements_ops );
158- if (IS_ERR (chip -> bios_dir [ cnt ] ))
155+ if (IS_ERR (dentry ))
159156 goto err ;
160- cnt ++ ;
161157 }
162158
163159 return ;
164160
165161err :
166- chip -> bios_dir [cnt ] = NULL ;
167162 tpm_bios_log_teardown (chip );
168163 return ;
169164}
170165
171166void tpm_bios_log_teardown (struct tpm_chip * chip )
172167{
173- int i ;
174- struct inode * inode ;
175-
176- /* securityfs_remove currently doesn't take care of handling sync
177- * between removal and opening of pseudo files. To handle this, a
178- * workaround is added by making i_private = NULL here during removal
179- * and to check it during open(), both within inode_lock()/unlock().
180- * This design ensures that open() either safely gets kref or fails.
181- */
182- for (i = (TPM_NUM_EVENT_LOG_FILES - 1 ); i >= 0 ; i -- ) {
183- if (chip -> bios_dir [i ]) {
184- inode = d_inode (chip -> bios_dir [i ]);
185- inode_lock (inode );
186- inode -> i_private = NULL ;
187- inode_unlock (inode );
188- securityfs_remove (chip -> bios_dir [i ]);
189- }
190- }
168+ securityfs_remove (chip -> bios_dir );
191169}
0 commit comments