Skip to content

Commit e153365

Browse files
amir73ilgregkh
authored andcommitted
fs: prepare for adding LSM blob to backing_file
[ Upstream commit 880bd49 ] In preparation to adding LSM blob to backing_file struct, factor out helpers init_backing_file() and backing_file_free(). Cc: stable@vger.kernel.org Cc: linux-fsdevel@vger.kernel.org Cc: linux-unionfs@vger.kernel.org Cc: linux-erofs@lists.ozlabs.org Signed-off-by: Amir Goldstein <amir73il@gmail.com> Reviewed-by: Serge Hallyn <serge@hallyn.com> [PM: use the term "LSM blob", fix comment style to match file] Signed-off-by: Paul Moore <paul@paul-moore.com> [ Used kfree() instead of kmem_cache_free(bfilp_cachep, ff) ] Signed-off-by: Sasha Levin <sashal@kernel.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 2b53d3a commit e153365

1 file changed

Lines changed: 20 additions & 2 deletions

File tree

fs/file_table.c

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,15 +60,20 @@ struct path *backing_file_user_path(struct file *f)
6060
}
6161
EXPORT_SYMBOL_GPL(backing_file_user_path);
6262

63+
static inline void backing_file_free(struct backing_file *ff)
64+
{
65+
path_put(&ff->user_path);
66+
kfree(ff);
67+
}
68+
6369
static inline void file_free(struct file *f)
6470
{
6571
security_file_free(f);
6672
if (likely(!(f->f_mode & FMODE_NOACCOUNT)))
6773
percpu_counter_dec(&nr_files);
6874
put_cred(f->f_cred);
6975
if (unlikely(f->f_mode & FMODE_BACKING)) {
70-
path_put(backing_file_user_path(f));
71-
kfree(backing_file(f));
76+
backing_file_free(backing_file(f));
7277
} else {
7378
kmem_cache_free(filp_cachep, f);
7479
}
@@ -255,6 +260,12 @@ struct file *alloc_empty_file_noaccount(int flags, const struct cred *cred)
255260
return f;
256261
}
257262

263+
static int init_backing_file(struct backing_file *ff)
264+
{
265+
memset(&ff->user_path, 0, sizeof(ff->user_path));
266+
return 0;
267+
}
268+
258269
/*
259270
* Variant of alloc_empty_file() that allocates a backing_file container
260271
* and doesn't check and modify nr_files.
@@ -277,7 +288,14 @@ struct file *alloc_empty_backing_file(int flags, const struct cred *cred)
277288
return ERR_PTR(error);
278289
}
279290

291+
/* The f_mode flags must be set before fput(). */
280292
ff->file.f_mode |= FMODE_BACKING | FMODE_NOACCOUNT;
293+
error = init_backing_file(ff);
294+
if (unlikely(error)) {
295+
fput(&ff->file);
296+
return ERR_PTR(error);
297+
}
298+
281299
return &ff->file;
282300
}
283301

0 commit comments

Comments
 (0)