Skip to content

Commit cda3712

Browse files
ebiggersAl Viro
authored andcommitted
fs: constify tree_descr arrays passed to simple_fill_super()
simple_fill_super() is passed an array of tree_descr structures which describe the files to create in the filesystem's root directory. Since these arrays are never modified intentionally, they should be 'const' so that they are placed in .rodata and benefit from memory protection. This patch updates the function signature and all users, and also constifies tree_descr.name. Signed-off-by: Eric Biggers <ebiggers@google.com> Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
1 parent a0c111b commit cda3712

13 files changed

Lines changed: 17 additions & 16 deletions

File tree

‎drivers/infiniband/hw/qib/qib_fs.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -512,7 +512,7 @@ static int qibfs_fill_super(struct super_block *sb, void *data, int silent)
512512
unsigned long flags;
513513
int ret;
514514

515-
static struct tree_descr files[] = {
515+
static const struct tree_descr files[] = {
516516
[2] = {"driver_stats", &driver_ops[0], S_IRUGO},
517517
[3] = {"driver_stats_names", &driver_ops[1], S_IRUGO},
518518
{""},

‎drivers/xen/xenfs/super.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,14 @@ static const struct file_operations capabilities_file_ops = {
4444

4545
static int xenfs_fill_super(struct super_block *sb, void *data, int silent)
4646
{
47-
static struct tree_descr xenfs_files[] = {
47+
static const struct tree_descr xenfs_files[] = {
4848
[2] = { "xenbus", &xen_xenbus_fops, S_IRUSR|S_IWUSR },
4949
{ "capabilities", &capabilities_file_ops, S_IRUGO },
5050
{ "privcmd", &xen_privcmd_fops, S_IRUSR|S_IWUSR },
5151
{""},
5252
};
5353

54-
static struct tree_descr xenfs_init_files[] = {
54+
static const struct tree_descr xenfs_init_files[] = {
5555
[2] = { "xenbus", &xen_xenbus_fops, S_IRUSR|S_IWUSR },
5656
{ "capabilities", &capabilities_file_ops, S_IRUGO },
5757
{ "privcmd", &xen_privcmd_fops, S_IRUSR|S_IWUSR },

‎fs/binfmt_misc.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -818,7 +818,7 @@ static const struct super_operations s_ops = {
818818
static int bm_fill_super(struct super_block *sb, void *data, int silent)
819819
{
820820
int err;
821-
static struct tree_descr bm_files[] = {
821+
static const struct tree_descr bm_files[] = {
822822
[2] = {"status", &bm_status_operations, S_IWUSR|S_IRUGO},
823823
[3] = {"register", &bm_register_operations, S_IWUSR},
824824
/* last one */ {""}

‎fs/debugfs/inode.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ static const struct dentry_operations debugfs_dops = {
199199

200200
static int debug_fill_super(struct super_block *sb, void *data, int silent)
201201
{
202-
static struct tree_descr debug_files[] = {{""}};
202+
static const struct tree_descr debug_files[] = {{""}};
203203
struct debugfs_fs_info *fsi;
204204
int err;
205205

‎fs/fuse/control.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ void fuse_ctl_remove_conn(struct fuse_conn *fc)
292292

293293
static int fuse_ctl_fill_super(struct super_block *sb, void *data, int silent)
294294
{
295-
struct tree_descr empty_descr = {""};
295+
static const struct tree_descr empty_descr = {""};
296296
struct fuse_conn *fc;
297297
int err;
298298

‎fs/libfs.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -507,7 +507,7 @@ EXPORT_SYMBOL(simple_write_end);
507507
* to pass it an appropriate max_reserved value to avoid collisions.
508508
*/
509509
int simple_fill_super(struct super_block *s, unsigned long magic,
510-
struct tree_descr *files)
510+
const struct tree_descr *files)
511511
{
512512
struct inode *inode;
513513
struct dentry *root;

‎fs/nfsd/nfsctl.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1146,7 +1146,7 @@ static ssize_t write_v4_end_grace(struct file *file, char *buf, size_t size)
11461146

11471147
static int nfsd_fill_super(struct super_block * sb, void * data, int silent)
11481148
{
1149-
static struct tree_descr nfsd_files[] = {
1149+
static const struct tree_descr nfsd_files[] = {
11501150
[NFSD_List] = {"exports", &exports_nfsd_operations, S_IRUGO},
11511151
[NFSD_Export_features] = {"export_features",
11521152
&export_features_operations, S_IRUGO},

‎fs/tracefs/inode.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ static const struct super_operations tracefs_super_operations = {
266266

267267
static int trace_fill_super(struct super_block *sb, void *data, int silent)
268268
{
269-
static struct tree_descr trace_files[] = {{""}};
269+
static const struct tree_descr trace_files[] = {{""}};
270270
struct tracefs_fs_info *fsi;
271271
int err;
272272

‎include/linux/fs.h‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2995,9 +2995,10 @@ extern const struct file_operations simple_dir_operations;
29952995
extern const struct inode_operations simple_dir_inode_operations;
29962996
extern void make_empty_dir_inode(struct inode *inode);
29972997
extern bool is_empty_dir_inode(struct inode *inode);
2998-
struct tree_descr { char *name; const struct file_operations *ops; int mode; };
2998+
struct tree_descr { const char *name; const struct file_operations *ops; int mode; };
29992999
struct dentry *d_alloc_name(struct dentry *, const char *);
3000-
extern int simple_fill_super(struct super_block *, unsigned long, struct tree_descr *);
3000+
extern int simple_fill_super(struct super_block *, unsigned long,
3001+
const struct tree_descr *);
30013002
extern int simple_pin_fs(struct file_system_type *, struct vfsmount **mount, int *count);
30023003
extern void simple_release_fs(struct vfsmount **mount, int *count);
30033004

‎kernel/bpf/inode.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -429,7 +429,7 @@ static int bpf_parse_options(char *data, struct bpf_mount_opts *opts)
429429

430430
static int bpf_fill_super(struct super_block *sb, void *data, int silent)
431431
{
432-
static struct tree_descr bpf_rfiles[] = { { "" } };
432+
static const struct tree_descr bpf_rfiles[] = { { "" } };
433433
struct bpf_mount_opts opts;
434434
struct inode *inode;
435435
int ret;

0 commit comments

Comments
 (0)