Skip to content

Commit a98ce02

Browse files
author
Al Viro
committed
efi_secret: clean securityfs use up
securityfs_remove() does take care of entire subtree now; no need to mess with them individually. NB: ->i_op replacement in there is still buggy. One shouldn't ever modify ->i_op of live accessible inode. Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
1 parent 29d673b commit a98ce02

1 file changed

Lines changed: 8 additions & 29 deletions

File tree

drivers/virt/coco/efi_secret/efi_secret.c

Lines changed: 8 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,6 @@
3131

3232
struct efi_secret {
3333
struct dentry *secrets_dir;
34-
struct dentry *fs_dir;
35-
struct dentry *fs_files[EFI_SECRET_NUM_FILES];
3634
void __iomem *secret_data;
3735
u64 secret_data_len;
3836
};
@@ -119,10 +117,8 @@ static void wipe_memory(void *addr, size_t size)
119117

120118
static int efi_secret_unlink(struct inode *dir, struct dentry *dentry)
121119
{
122-
struct efi_secret *s = efi_secret_get();
123120
struct inode *inode = d_inode(dentry);
124121
struct secret_entry *e = (struct secret_entry *)inode->i_private;
125-
int i;
126122

127123
if (e) {
128124
/* Zero out the secret data */
@@ -132,10 +128,6 @@ static int efi_secret_unlink(struct inode *dir, struct dentry *dentry)
132128

133129
inode->i_private = NULL;
134130

135-
for (i = 0; i < EFI_SECRET_NUM_FILES; i++)
136-
if (s->fs_files[i] == dentry)
137-
s->fs_files[i] = NULL;
138-
139131
return simple_unlink(inode, dentry);
140132
}
141133

@@ -186,15 +178,6 @@ static int efi_secret_map_area(struct platform_device *dev)
186178
static void efi_secret_securityfs_teardown(struct platform_device *dev)
187179
{
188180
struct efi_secret *s = efi_secret_get();
189-
int i;
190-
191-
for (i = (EFI_SECRET_NUM_FILES - 1); i >= 0; i--) {
192-
securityfs_remove(s->fs_files[i]);
193-
s->fs_files[i] = NULL;
194-
}
195-
196-
securityfs_remove(s->fs_dir);
197-
s->fs_dir = NULL;
198181

199182
securityfs_remove(s->secrets_dir);
200183
s->secrets_dir = NULL;
@@ -209,7 +192,7 @@ static int efi_secret_securityfs_setup(struct platform_device *dev)
209192
unsigned char *ptr;
210193
struct secret_header *h;
211194
struct secret_entry *e;
212-
struct dentry *dent;
195+
struct dentry *dent, *dir;
213196
char guid_str[EFI_VARIABLE_GUID_LEN + 1];
214197

215198
ptr = (void __force *)s->secret_data;
@@ -232,8 +215,6 @@ static int efi_secret_securityfs_setup(struct platform_device *dev)
232215
}
233216

234217
s->secrets_dir = NULL;
235-
s->fs_dir = NULL;
236-
memset(s->fs_files, 0, sizeof(s->fs_files));
237218

238219
dent = securityfs_create_dir("secrets", NULL);
239220
if (IS_ERR(dent)) {
@@ -243,14 +224,13 @@ static int efi_secret_securityfs_setup(struct platform_device *dev)
243224
}
244225
s->secrets_dir = dent;
245226

246-
dent = securityfs_create_dir("coco", s->secrets_dir);
247-
if (IS_ERR(dent)) {
227+
dir = securityfs_create_dir("coco", s->secrets_dir);
228+
if (IS_ERR(dir)) {
248229
dev_err(&dev->dev, "Error creating coco securityfs directory entry err=%ld\n",
249-
PTR_ERR(dent));
250-
return PTR_ERR(dent);
230+
PTR_ERR(dir));
231+
return PTR_ERR(dir);
251232
}
252-
d_inode(dent)->i_op = &efi_secret_dir_inode_operations;
253-
s->fs_dir = dent;
233+
d_inode(dir)->i_op = &efi_secret_dir_inode_operations;
254234

255235
bytes_left = h->len - sizeof(*h);
256236
ptr += sizeof(*h);
@@ -266,15 +246,14 @@ static int efi_secret_securityfs_setup(struct platform_device *dev)
266246
if (efi_guidcmp(e->guid, NULL_GUID)) {
267247
efi_guid_to_str(&e->guid, guid_str);
268248

269-
dent = securityfs_create_file(guid_str, 0440, s->fs_dir, (void *)e,
249+
dent = securityfs_create_file(guid_str, 0440, dir, (void *)e,
270250
&efi_secret_bin_file_fops);
271251
if (IS_ERR(dent)) {
272252
dev_err(&dev->dev, "Error creating efi_secret securityfs entry\n");
273253
ret = PTR_ERR(dent);
274254
goto err_cleanup;
275255
}
276-
277-
s->fs_files[i++] = dent;
256+
i++;
278257
}
279258
ptr += e->len;
280259
bytes_left -= e->len;

0 commit comments

Comments
 (0)