Cosmetic
Subsystems (2)
cover Cosmetic
Hello Alexander,
I passed chackpatch.pl to these files,
and found many things to fix.
I splitted the changes into a few different patches, to make it easier for review.
Cheers,
Alex
Alejandro Colomar (4):
fs/anon_inodes.c: Use "%s" + __func__ instead of hardcoding function
name
fs/anon_inodes.c, fs/attr.c, fs/bad_inode.c, fs/binfmt_aout.c,
fs/binfmt_elf.c: Cosmetic
fs/attr.c, fs/bad_inode.c, fs/binfmt_aout.c, fs/binfmt_elf.c: Cosmetic fs/binfmt_elf.c: Cosmetic
fs/anon_inodes.c | 5 +- fs/attr.c | 12 +-- fs/bad_inode.c | 55 +++++----- fs/binfmt_aout.c | 95 +++++++++-------- fs/binfmt_elf.c | 268 ++++++++++++++++++++++++----------------------- 5 files changed, 225 insertions(+), 210 deletions(-)
Signature · 1 line
2.28.0
PATCH 1/4 fs/anon_inodes.c: Use "%s" + __func__ instead of hardcoding function name
--- fs/anon_inodes.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
fs/anon_inodes.c +2 -2
@@ -152,11 +152,11 @@ static int __init anon_inode_init(void) { anon_inode_mnt =kern_mount (&anon_inode_fs_type);if (IS_ERR (anon_inode_mnt)) -panic ("anon_inode_init() kernel mount failed (%ld)\n" ,PTR_ERR (anon_inode_mnt)); +panic ("%s() kernel mount failed (%ld)\n" , __func__,PTR_ERR (anon_inode_mnt)); anon_inode_inode =alloc_anon_inode (anon_inode_mnt->mnt_sb);if (IS_ERR (anon_inode_inode)) -panic ("anon_inode_init() inode allocation failed (%ld)\n" ,PTR_ERR (anon_inode_inode)); +panic ("%s() inode allocation failed (%ld)\n" , __func__,PTR_ERR (anon_inode_inode));return 0 ; }
Signature · 1 line
2.28.0
PATCH 2/4 fs/anon_inodes.c, fs/attr.c, fs/bad_inode.c, fs/binfmt_aout.c, fs/binfmt_elf.c: Cosmetic
In reply to Alejandro ColomarThis patch contains only trivial changes:
Some of them found with checkpatch.pl in strict mode.
- Remove trailing whitespace.
- Remove spaces coming before tabs.
- Fix typos in comments.
- Convert spaces into tabs.
- Add a space around operators that should have them, and remove them when they shouldn't have them sround, according to coding_style.rst.
- Use braces accordint to coding_style.rst.
- Align multi-line function prototypes, and other similar cases.
- Remove or add blank lines:
* Add blank lines after declarations, and before code.
* Remove blank lines after function definitions and before EXPORT_SYMBOL().
- Remove redundant parentheses, when the don't improve readability.
- Fix comments' style according to coding_style.rst.
- Simplify comparisons against NULL, using '!' (or nothing at all).
- Use C89 comments (/* */), instead of C99 (//).
--- fs/anon_inodes.c | 1 + fs/attr.c | 7 +-- fs/bad_inode.c | 50 +++++++++--------- fs/binfmt_aout.c | 94 +++++++++++++++++----------------- fs/binfmt_elf.c | 129 ++++++++++++++++++++++++----------------------- 5 files changed, 143 insertions(+), 138 deletions(-)
fs/anon_inodes.c +1 -0
@@ -43,6 +43,7 @@ static const struct dentry_operations anon_inodefs_dentry_operations = {static int anon_inodefs_init_fs_context (struct fs_context *fc) {struct pseudo_fs_context *ctx =init_pseudo (fc,ANON_INODE_FS_MAGIC ); +if (!ctx)return -ENOMEM ; ctx->dops = &anon_inodefs_dentry_operations;
fs/attr.c +4 -3
@@ -64,7 +64,7 @@ int setattr_prepare(struct dentry *dentry, struct iattr *attr)unsigned int ia_valid = attr->ia_valid;/* -* First check size constraints. These can't be overriden using +* First check size constraints. These can't be overridden using * ATTR_FORCE. */ if (ia_valid &ATTR_SIZE ) {
@@ -220,7 +220,8 @@ EXPORT_SYMBOL(setattr_copy);* the file open for write, as there can be no conflicting delegation in * that case. */ -int notify_change (struct dentry * dentry,struct iattr * attr,struct inode **delegated_inode) +int notify_change (struct dentry *dentry,struct iattr *attr, +struct inode **delegated_inode) {struct inode *inode = dentry->d_inode;umode_t mode = inode->i_mode;
@@ -284,7 +285,7 @@ int notify_change(struct dentry * dentry, struct iattr * attr, struct inode **de* no function will ever call notify_change with both ATTR_MODE and * ATTR_KILL_S*ID set. */ -if ((ia_valid & (ATTR_KILL_SUID |ATTR_KILL_SGID )) && +if ((ia_valid & (ATTR_KILL_SUID |ATTR_KILL_SGID )) && (ia_valid &ATTR_MODE ))BUG ();
fs/bad_inode.c +24 -26
143 lines not on this page · raw message
fs/binfmt_aout.c +49 -45
209 lines not on this page · raw message
fs/binfmt_elf.c +65 -64
330 lines not on this page · raw message
Signature · 1 line
2.28.0
PATCH 3/4 fs/attr.c, fs/bad_inode.c, fs/binfmt_aout.c, fs/binfmt_elf.c: Cosmetic
In reply to Alejandro ColomarSlightly non-trivial changes:
- Move declarations to the top of function definitions.
- Split multiple assignments in a single line to multiple lines with a signle assignment each.
--- fs/attr.c | 5 ++--- fs/bad_inode.c | 5 +++-- fs/binfmt_aout.c | 3 ++- fs/binfmt_elf.c | 26 ++++++++++++++++---------- 4 files changed, 23 insertions(+), 16 deletions(-)
fs/attr.c +2 -3
@@ -62,13 +62,14 @@ int setattr_prepare(struct dentry *dentry, struct iattr *attr) {struct inode *inode =d_inode (dentry);unsigned int ia_valid = attr->ia_valid; +int error;/* * First check size constraints. These can't be overridden using * ATTR_FORCE. */ if (ia_valid &ATTR_SIZE ) { -int error =inode_newsize_ok (inode, attr->ia_size); + error =inode_newsize_ok (inode, attr->ia_size);if (error)return error; }
@@ -105,8 +106,6 @@ int setattr_prepare(struct dentry *dentry, struct iattr *attr) kill_priv:/* User has permission for the change */ if (ia_valid &ATTR_KILL_PRIV ) { -int error; - error =security_inode_killpriv (dentry);if (error)return error;
fs/bad_inode.c +3 -2
@@ -200,8 +200,9 @@ void make_bad_inode(struct inode *inode)remove_inode_hash (inode); inode->i_mode =S_IFREG ; - inode->i_atime = inode->i_mtime = inode->i_ctime = -current_time (inode); + inode->i_ctime =current_time (inode); + inode->i_mtime = inode->i_ctime; + inode->i_atime = inode->i_ctime; inode->i_op = &bad_inode_ops; inode->i_opflags &= ~IOP_XATTR ; inode->i_fop = &bad_file_ops;
fs/binfmt_aout.c +2 -1
@@ -97,7 +97,8 @@ static unsigned long __user *create_aout_tables(char __user *p, struct linux_bin }while (c); }put_user (NULL , argv); - current->mm->arg_end = current->mm->env_start = (unsigned long )p; + current->mm->env_start = (unsigned long )p; + current->mm->arg_end = (unsigned long )p;while (envc-- >0 ) {char c;
fs/binfmt_elf.c +16 -10
@@ -1035,13 +1035,12 @@ static int load_elf_binary(struct linux_binprm *bprm)unsigned long k, vaddr;unsigned long total_size =0 ;unsigned long alignment; +unsigned long nbyte;if (elf_ppnt->p_type !=PT_LOAD )continue ;if (unlikely (elf_brk > elf_bss)) { -unsigned long nbyte; -/* * There was a PT_LOAD segment with p_memsz > p_filesz * before this one. Map anonymous pages, if needed,
@@ -1277,10 +1276,12 @@ static int load_elf_binary(struct linux_binprm *bprm)*/ if (IS_ENABLED (CONFIG_ARCH_HAS_ELF_RANDOMIZE ) && elf_ex->e_type ==ET_DYN && !interpreter) { - mm->brk = mm->start_brk =ELF_ET_DYN_BASE ; + mm->start_brk =ELF_ET_DYN_BASE ; + mm->brk =ELF_ET_DYN_BASE ; } - mm->brk = mm->start_brk =arch_randomize_brk (mm); + mm->start_brk =arch_randomize_brk (mm); + mm->brk = mm->start_brk;#ifdef compat_brk_randomized current->brk_randomized =1 ;#endif
@@ -1506,7 +1507,8 @@ static void fill_note(struct memelfnote *note, const char *name, int type,static void fill_prstatus (struct elf_prstatus *prstatus,struct task_struct *p,long signr) { - prstatus->pr_info.si_signo = prstatus->pr_cursig = signr; + prstatus->pr_cursig = signr; + prstatus->pr_info.si_signo = signr; prstatus->pr_sigpend = p->pending.signal.sig[0 ]; prstatus->pr_sighold = p->blocked.sig[0 ];rcu_read_lock ();
@@ -1618,6 +1620,7 @@ static int fill_files_note(struct memelfnote *note)user_long_t *data;user_long_t *start_end_ofs;char *name_base, *name_curpos; +unsigned int shift_bytes;/* *Estimated* file count and total data size needed */ count = mm->map_count;
@@ -1639,7 +1642,8 @@ static int fill_files_note(struct memelfnote *note)return -ENOMEM ; start_end_ofs = data +2 ; - name_base = name_curpos = ((char *)data) + names_ofs; + name_curpos = ((char *)data) + names_ofs; + name_base = name_curpos; remaining = size - names_ofs; count =0 ;for (vma = mm->mmap; vma; vma = vma->vm_next) {
@@ -1681,7 +1685,7 @@ static int fill_files_note(struct memelfnote *note)*/ n = mm->map_count - count;if (n !=0 ) { -unsigned shift_bytes = n *3 *sizeof (data[0 ]); + shift_bytes = n *3 *sizeof (data[0 ]);memmove (name_base - shift_bytes, name_base, name_curpos - name_base); name_curpos -= shift_bytes;
@@ -1922,11 +1926,12 @@ static int write_note_info(struct elf_note_info *info,static void free_note_info (struct elf_note_info *info) { +struct elf_thread_core_info *t;struct elf_thread_core_info *threads = info->thread; +unsigned int i;while (threads) { -unsigned int i; -struct elf_thread_core_info *t = threads; + t = threads; threads = t->next;WARN_ON (t->notes[0 ].data && t->notes[0 ].data != &t->prstatus);for (i =1 ; i < info->thread_notes; ++i)
@@ -2209,7 +2214,8 @@ static int elf_core_dump(struct coredump_params *cprm) offset += sz; } - dataoff = offset =roundup (offset,ELF_EXEC_PAGESIZE ); + offset =roundup (offset,ELF_EXEC_PAGESIZE ); + dataoff = offset; offset += vma_data_size; offset +=elf_core_extra_data_size ();
Signature · 1 line
2.28.0
PATCH 4/4 fs/binfmt_elf.c: Cosmetic
In reply to Alejandro ColomarNon-trivial changes:
Invert 'if's to simplify logic.
Use 'goto' in conjunction with the above, when appropriate.
--- fs/binfmt_elf.c | 115 +++++++++++++++++++++++++----------------------- 1 file changed, 59 insertions(+), 56 deletions(-)
fs/binfmt_elf.c +59 -56
@@ -1079,65 +1079,68 @@ static int load_elf_binary(struct linux_binprm *bprm)*/ if (elf_ex->e_type ==ET_EXEC || load_addr_set) { elf_flags |=MAP_FIXED ; - }else if (elf_ex->e_type ==ET_DYN ) { -/* -* This logic is run once for the first LOAD Program -* Header for ET_DYN binaries to calculate the -* randomization (load_bias) for all the LOAD -* Program Headers, and to calculate the entire -* size of the ELF mapping (total_size). (Note that -* load_addr_set is set to true later once the -* initial mapping is performed.) -* -* There are effectively two types of ET_DYN -* binaries: programs (i.e. PIE: ET_DYN with INTERP) -* and loaders (ET_DYN without INTERP, since they -* _are_ the ELF interpreter). The loaders must -* be loaded away from programs since the program -* may otherwise collide with the loader (especially -* for ET_EXEC which does not have a randomized -* position). For example to handle invocations of -* "./ld.so someprog" to test out a new version of -* the loader, the subsequent program that the -* loader loads must avoid the loader itself, so -* they cannot share the same load range. Sufficient -* room for the brk must be allocated with the -* loader as well, since brk must be available with -* the loader. -* -* Therefore, programs are loaded offset from -* ELF_ET_DYN_BASE and loaders are loaded into the -* independently randomized mmap region (0 load_bias -* without MAP_FIXED). -*/ -if (interpreter) { - load_bias =ELF_ET_DYN_BASE ; -if (current->flags &PF_RANDOMIZE ) - load_bias +=arch_mmap_rnd (); - alignment =maximum_alignment (elf_phdata, elf_ex->e_phnum); -if (alignment) - load_bias &= ~(alignment -1 ); - elf_flags |=MAP_FIXED ; - }else - load_bias =0 ; + goto proceed_normally; + } +if (elf_ex->e_type !=ET_DYN ) + goto proceed_normally; +/* +* This logic is run once for the first LOAD Program +* Header for ET_DYN binaries to calculate the +* randomization (load_bias) for all the LOAD +* Program Headers, and to calculate the entire +* size of the ELF mapping (total_size). (Note that +* load_addr_set is set to true later once the +* initial mapping is performed.) +* +* There are effectively two types of ET_DYN +* binaries: programs (i.e. PIE: ET_DYN with INTERP) +* and loaders (ET_DYN without INTERP, since they +* _are_ the ELF interpreter). The loaders must +* be loaded away from programs since the program +* may otherwise collide with the loader (especially +* for ET_EXEC which does not have a randomized +* position). For example to handle invocations of +* "./ld.so someprog" to test out a new version of +* the loader, the subsequent program that the +* loader loads must avoid the loader itself, so +* they cannot share the same load range. Sufficient +* room for the brk must be allocated with the +* loader as well, since brk must be available with +* the loader. +* +* Therefore, programs are loaded offset from +* ELF_ET_DYN_BASE and loaders are loaded into the +* independently randomized mmap region (0 load_bias +* without MAP_FIXED). +*/ +if (interpreter) { + load_bias =ELF_ET_DYN_BASE ; +if (current->flags &PF_RANDOMIZE ) + load_bias +=arch_mmap_rnd (); + alignment =maximum_alignment (elf_phdata, elf_ex->e_phnum); +if (alignment) + load_bias &= ~(alignment -1 ); + elf_flags |=MAP_FIXED ; + }else { + load_bias =0 ; + } -/* -* Since load_bias is used for all subsequent loading -* calculations, we must lower it by the first vaddr -* so that the remaining calculations based on the -* ELF vaddrs will be correctly offset. The result -* is then page aligned. -*/ - load_bias =ELF_PAGESTART (load_bias - vaddr); +/* +* Since load_bias is used for all subsequent loading +* calculations, we must lower it by the first vaddr +* so that the remaining calculations based on the +* ELF vaddrs will be correctly offset. The result +* is then page aligned. +*/ + load_bias =ELF_PAGESTART (load_bias - vaddr); - total_size =total_mapping_size (elf_phdata, - elf_ex->e_phnum); -if (!total_size) { - retval = -EINVAL ; - goto out_free_dentry; - } + total_size =total_mapping_size (elf_phdata, + elf_ex->e_phnum); +if (!total_size) { + retval = -EINVAL ; + goto out_free_dentry; } - +proceed_normally:/* FIXME: a better label name? */ error =elf_map (bprm->file, load_bias + vaddr, elf_ppnt, elf_prot, elf_flags, total_size);if (BAD_ADDR (error)) {
Signature · 1 line
2.28.0