Skip to content

Commit f42b8d7

Browse files
author
Al Viro
committed
tpm: don't bother with removal of files in directory we'll be removing
FWIW, there is a reliable indication of removal - ->i_nlink going to 0 ;-) Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
1 parent 5be998a commit f42b8d7

2 files changed

Lines changed: 13 additions & 35 deletions

File tree

drivers/char/tpm/eventlog/common.c

Lines changed: 12 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -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)
105105
void 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

165161
err:
166-
chip->bios_dir[cnt] = NULL;
167162
tpm_bios_log_teardown(chip);
168163
return;
169164
}
170165

171166
void 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
}

include/linux/tpm.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ struct tpm_chip {
182182
unsigned long duration[TPM_NUM_DURATIONS]; /* jiffies */
183183
bool duration_adjusted;
184184

185-
struct dentry *bios_dir[TPM_NUM_EVENT_LOG_FILES];
185+
struct dentry *bios_dir;
186186

187187
const struct attribute_group *groups[3 + TPM_MAX_HASHES];
188188
unsigned int groups_cnt;

0 commit comments

Comments
 (0)