Skip to content

Commit d600618

Browse files
ebiggerstytso
authored andcommitted
ext4: constify static data that is never modified
Constify static data in ext4 that is never (intentionally) modified so that it is placed in .rodata and benefits from memory protection. Signed-off-by: Eric Biggers <ebiggers@google.com> Signed-off-by: Theodore Ts'o <tytso@mit.edu>
1 parent 1bc0af6 commit d600618

5 files changed

Lines changed: 11 additions & 10 deletions

File tree

‎fs/ext4/ext4.h‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2365,7 +2365,7 @@ static inline void ext4_update_dx_flag(struct inode *inode)
23652365
if (!ext4_has_feature_dir_index(inode->i_sb))
23662366
ext4_clear_inode_flag(inode, EXT4_INODE_INDEX);
23672367
}
2368-
static unsigned char ext4_filetype_table[] = {
2368+
static const unsigned char ext4_filetype_table[] = {
23692369
DT_UNKNOWN, DT_REG, DT_DIR, DT_CHR, DT_BLK, DT_FIFO, DT_SOCK, DT_LNK
23702370
};
23712371

@@ -3050,7 +3050,7 @@ extern int ext4_handle_dirty_dirent_node(handle_t *handle,
30503050
struct inode *inode,
30513051
struct buffer_head *bh);
30523052
#define S_SHIFT 12
3053-
static unsigned char ext4_type_by_mode[S_IFMT >> S_SHIFT] = {
3053+
static const unsigned char ext4_type_by_mode[S_IFMT >> S_SHIFT] = {
30543054
[S_IFREG >> S_SHIFT] = EXT4_FT_REG_FILE,
30553055
[S_IFDIR >> S_SHIFT] = EXT4_FT_DIR,
30563056
[S_IFCHR >> S_SHIFT] = EXT4_FT_CHRDEV,

‎fs/ext4/mballoc.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,7 @@ static struct kmem_cache *ext4_free_data_cachep;
357357
#define NR_GRPINFO_CACHES 8
358358
static struct kmem_cache *ext4_groupinfo_caches[NR_GRPINFO_CACHES];
359359

360-
static const char *ext4_groupinfo_slab_names[NR_GRPINFO_CACHES] = {
360+
static const char * const ext4_groupinfo_slab_names[NR_GRPINFO_CACHES] = {
361361
"ext4_groupinfo_1k", "ext4_groupinfo_2k", "ext4_groupinfo_4k",
362362
"ext4_groupinfo_8k", "ext4_groupinfo_16k", "ext4_groupinfo_32k",
363363
"ext4_groupinfo_64k", "ext4_groupinfo_128k"

‎fs/ext4/super.c‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1208,7 +1208,7 @@ static const struct fscrypt_operations ext4_cryptops = {
12081208
#endif
12091209

12101210
#ifdef CONFIG_QUOTA
1211-
static char *quotatypes[] = INITQFNAMES;
1211+
static const char * const quotatypes[] = INITQFNAMES;
12121212
#define QTYPE2NAME(t) (quotatypes[t])
12131213

12141214
static int ext4_write_dquot(struct dquot *dquot);
@@ -1422,7 +1422,8 @@ static ext4_fsblk_t get_sb_block(void **data)
14221422
}
14231423

14241424
#define DEFAULT_JOURNAL_IOPRIO (IOPRIO_PRIO_VALUE(IOPRIO_CLASS_BE, 3))
1425-
static char deprecated_msg[] = "Mount option \"%s\" will be removed by %s\n"
1425+
static const char deprecated_msg[] =
1426+
"Mount option \"%s\" will be removed by %s\n"
14261427
"Contact linux-ext4@vger.kernel.org if you think we should keep it.\n";
14271428

14281429
#ifdef CONFIG_QUOTA

‎fs/ext4/sysfs.c‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ typedef enum {
3434
ptr_ext4_super_block_offset,
3535
} attr_ptr_t;
3636

37-
static const char *proc_dirname = "fs/ext4";
37+
static const char proc_dirname[] = "fs/ext4";
3838
static struct proc_dir_entry *ext4_proc_root;
3939

4040
struct ext4_attr {
@@ -375,7 +375,7 @@ static const struct file_operations ext4_seq_##name##_fops = { \
375375
PROC_FILE_SHOW_DEFN(es_shrinker_info);
376376
PROC_FILE_SHOW_DEFN(options);
377377

378-
static struct ext4_proc_files {
378+
static const struct ext4_proc_files {
379379
const char *name;
380380
const struct file_operations *fops;
381381
} proc_files[] = {
@@ -388,7 +388,7 @@ static struct ext4_proc_files {
388388
int ext4_register_sysfs(struct super_block *sb)
389389
{
390390
struct ext4_sb_info *sbi = EXT4_SB(sb);
391-
struct ext4_proc_files *p;
391+
const struct ext4_proc_files *p;
392392
int err;
393393

394394
sbi->s_kobj.kset = &ext4_kset;
@@ -412,7 +412,7 @@ int ext4_register_sysfs(struct super_block *sb)
412412
void ext4_unregister_sysfs(struct super_block *sb)
413413
{
414414
struct ext4_sb_info *sbi = EXT4_SB(sb);
415-
struct ext4_proc_files *p;
415+
const struct ext4_proc_files *p;
416416

417417
if (sbi->s_proc) {
418418
for (p = proc_files; p->name; p++)

‎fs/ext4/xattr.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ static void ext4_xattr_rehash(struct ext4_xattr_header *,
8181
static int ext4_xattr_list(struct dentry *dentry, char *buffer,
8282
size_t buffer_size);
8383

84-
static const struct xattr_handler *ext4_xattr_handler_map[] = {
84+
static const struct xattr_handler * const ext4_xattr_handler_map[] = {
8585
[EXT4_XATTR_INDEX_USER] = &ext4_xattr_user_handler,
8686
#ifdef CONFIG_EXT4_FS_POSIX_ACL
8787
[EXT4_XATTR_INDEX_POSIX_ACL_ACCESS] = &posix_acl_access_xattr_handler,

0 commit comments

Comments
 (0)