Message ID | 20231109062228.10227-1-ov.wagle@gmail.com (mailing list archive) |
---|---|
State | New |
Headers | show |
Series | MM: shmem: Remove code sytle warnings | expand |
mm not MM, style not sytle. On Wed, 8 Nov 2023, Omkar Wagle wrote: > Remove most of the code style warnings > > Signed-off-by: Omkar Wagle<ov.wagle@gmail.com> > --- > mm/shmem.c | 51 +++++++++++++++++++++++++++++++++------------------ > 1 file changed, 33 insertions(+), 18 deletions(-) Thanks for trying, but I'm sorry: very little of this is an improvement. Almost all of it is just adding a blank line in between declaration and code in some small block (including at least one from Linus himself). checkpatch does a good job of encouraging tidy patches, but it makes no claim to being right; and that particular nag annoys me more often than any other (though I often grudgingly give in to it, just for a quiet life - Cc'ing Matthew because I suspect he resents it even more than I do). And look at those fsparams: Al and others have gone to the trouble of lining them up nicely, but you've decided to undo their work. I believe it's explained somewhere (but admit that a quick look in Documentation didn't show me where), that checkpatch is something to run to tidy up your patches, or new source files (or perhaps even staging); but please don't send its advice on well-established source files. Hugh
Hi Omkar, kernel test robot noticed the following build errors: [auto build test ERROR on akpm-mm/mm-everything] [also build test ERROR on linus/master next-20231109] [cannot apply to v6.6] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in https://git-scm.com/docs/git-format-patch#_base_tree_information] url: https://github.com/intel-lab-lkp/linux/commits/Omkar-Wagle/MM-shmem-Remove-code-sytle-warnings/20231109-163742 base: https://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm.git mm-everything patch link: https://lore.kernel.org/r/20231109062228.10227-1-ov.wagle%40gmail.com patch subject: [PATCH] MM: shmem: Remove code sytle warnings config: mips-allnoconfig (https://download.01.org/0day-ci/archive/20231109/202311092136.KQoibaVV-lkp@intel.com/config) compiler: mips-linux-gcc (GCC) 13.2.0 reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20231109/202311092136.KQoibaVV-lkp@intel.com/reproduce) If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags | Reported-by: kernel test robot <lkp@intel.com> | Closes: https://lore.kernel.org/oe-kbuild-all/202311092136.KQoibaVV-lkp@intel.com/ All errors (new ones prefixed by >>): mm/shmem.c: In function 'shmem_fill_super': >> mm/shmem.c:4310:47: error: macro "max_t" requires 3 arguments, but only 2 given 4310 | L1_CACHE_BYTES), GFP_KERNEL); | ^ In file included from include/linux/kernel.h:28, from include/linux/cpumask.h:10, from arch/mips/include/asm/processor.h:15, from arch/mips/include/asm/thread_info.h:16, from include/linux/thread_info.h:60, from include/asm-generic/preempt.h:5, from ./arch/mips/include/generated/asm/preempt.h:1, from include/linux/preempt.h:79, from include/linux/spinlock.h:56, from include/linux/wait.h:9, from include/linux/wait_bit.h:8, from include/linux/fs.h:6, from mm/shmem.c:24: include/linux/minmax.h:169: note: macro "max_t" defined here 169 | #define max_t(type, x, y) __careful_cmp(max, (type)(x), (type)(y)) | >> mm/shmem.c:4309:26: error: 'max_t' undeclared (first use in this function); did you mean 'rmap_t'? 4309 | sbinfo = kzalloc(max_t((int)sizeof(struct shmem_sb_info), | ^~~~~ | rmap_t mm/shmem.c:4309:26: note: each undeclared identifier is reported only once for each function it appears in vim +/max_t +4310 mm/shmem.c ^1da177e4c3f41 Linus Torvalds 2005-04-16 4300 f32356261d44d5 David Howells 2019-03-25 4301 static int shmem_fill_super(struct super_block *sb, struct fs_context *fc) ^1da177e4c3f41 Linus Torvalds 2005-04-16 4302 { f32356261d44d5 David Howells 2019-03-25 4303 struct shmem_options *ctx = fc->fs_private; ^1da177e4c3f41 Linus Torvalds 2005-04-16 4304 struct inode *inode; 0edd73b33426df Hugh Dickins 2005-06-21 4305 struct shmem_sb_info *sbinfo; 71480663b751de Carlos Maiolino 2023-07-25 4306 int error = -ENOMEM; 680d794babebc7 Andrew Morton 2008-02-08 4307 680d794babebc7 Andrew Morton 2008-02-08 4308 /* Round up to L1_CACHE_BYTES to resist false sharing */ 1c6e8dc111cb86 Omkar Wagle 2023-11-08 @4309 sbinfo = kzalloc(max_t((int)sizeof(struct shmem_sb_info), 680d794babebc7 Andrew Morton 2008-02-08 @4310 L1_CACHE_BYTES), GFP_KERNEL); 680d794babebc7 Andrew Morton 2008-02-08 4311 if (!sbinfo) 71480663b751de Carlos Maiolino 2023-07-25 4312 return error; 680d794babebc7 Andrew Morton 2008-02-08 4313 680d794babebc7 Andrew Morton 2008-02-08 4314 sb->s_fs_info = sbinfo; ^1da177e4c3f41 Linus Torvalds 2005-04-16 4315
Hi Omkar, kernel test robot noticed the following build errors: [auto build test ERROR on akpm-mm/mm-everything] [also build test ERROR on linus/master next-20231109] [cannot apply to v6.6] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in https://git-scm.com/docs/git-format-patch#_base_tree_information] url: https://github.com/intel-lab-lkp/linux/commits/Omkar-Wagle/MM-shmem-Remove-code-sytle-warnings/20231109-163742 base: https://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm.git mm-everything patch link: https://lore.kernel.org/r/20231109062228.10227-1-ov.wagle%40gmail.com patch subject: [PATCH] MM: shmem: Remove code sytle warnings config: um-allnoconfig (https://download.01.org/0day-ci/archive/20231110/202311100217.l1zmB8In-lkp@intel.com/config) compiler: clang version 17.0.0 (https://github.com/llvm/llvm-project.git 4a5ac14ee968ff0ad5d2cc1ffa0299048db4c88a) reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20231110/202311100217.l1zmB8In-lkp@intel.com/reproduce) If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags | Reported-by: kernel test robot <lkp@intel.com> | Closes: https://lore.kernel.org/oe-kbuild-all/202311100217.l1zmB8In-lkp@intel.com/ All errors (new ones prefixed by >>): In file included from mm/shmem.c:29: In file included from include/linux/pagemap.h:11: In file included from include/linux/highmem.h:12: In file included from include/linux/hardirq.h:11: In file included from arch/um/include/asm/hardirq.h:5: In file included from include/asm-generic/hardirq.h:17: In file included from include/linux/irq.h:20: In file included from include/linux/io.h:13: In file included from arch/um/include/asm/io.h:24: include/asm-generic/io.h:547:31: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic] 547 | val = __raw_readb(PCI_IOBASE + addr); | ~~~~~~~~~~ ^ include/asm-generic/io.h:560:61: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic] 560 | val = __le16_to_cpu((__le16 __force)__raw_readw(PCI_IOBASE + addr)); | ~~~~~~~~~~ ^ include/uapi/linux/byteorder/little_endian.h:37:51: note: expanded from macro '__le16_to_cpu' 37 | #define __le16_to_cpu(x) ((__force __u16)(__le16)(x)) | ^ In file included from mm/shmem.c:29: In file included from include/linux/pagemap.h:11: In file included from include/linux/highmem.h:12: In file included from include/linux/hardirq.h:11: In file included from arch/um/include/asm/hardirq.h:5: In file included from include/asm-generic/hardirq.h:17: In file included from include/linux/irq.h:20: In file included from include/linux/io.h:13: In file included from arch/um/include/asm/io.h:24: include/asm-generic/io.h:573:61: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic] 573 | val = __le32_to_cpu((__le32 __force)__raw_readl(PCI_IOBASE + addr)); | ~~~~~~~~~~ ^ include/uapi/linux/byteorder/little_endian.h:35:51: note: expanded from macro '__le32_to_cpu' 35 | #define __le32_to_cpu(x) ((__force __u32)(__le32)(x)) | ^ In file included from mm/shmem.c:29: In file included from include/linux/pagemap.h:11: In file included from include/linux/highmem.h:12: In file included from include/linux/hardirq.h:11: In file included from arch/um/include/asm/hardirq.h:5: In file included from include/asm-generic/hardirq.h:17: In file included from include/linux/irq.h:20: In file included from include/linux/io.h:13: In file included from arch/um/include/asm/io.h:24: include/asm-generic/io.h:584:33: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic] 584 | __raw_writeb(value, PCI_IOBASE + addr); | ~~~~~~~~~~ ^ include/asm-generic/io.h:594:59: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic] 594 | __raw_writew((u16 __force)cpu_to_le16(value), PCI_IOBASE + addr); | ~~~~~~~~~~ ^ include/asm-generic/io.h:604:59: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic] 604 | __raw_writel((u32 __force)cpu_to_le32(value), PCI_IOBASE + addr); | ~~~~~~~~~~ ^ include/asm-generic/io.h:692:20: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic] 692 | readsb(PCI_IOBASE + addr, buffer, count); | ~~~~~~~~~~ ^ include/asm-generic/io.h:700:20: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic] 700 | readsw(PCI_IOBASE + addr, buffer, count); | ~~~~~~~~~~ ^ include/asm-generic/io.h:708:20: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic] 708 | readsl(PCI_IOBASE + addr, buffer, count); | ~~~~~~~~~~ ^ include/asm-generic/io.h:717:21: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic] 717 | writesb(PCI_IOBASE + addr, buffer, count); | ~~~~~~~~~~ ^ include/asm-generic/io.h:726:21: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic] 726 | writesw(PCI_IOBASE + addr, buffer, count); | ~~~~~~~~~~ ^ include/asm-generic/io.h:735:21: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic] 735 | writesl(PCI_IOBASE + addr, buffer, count); | ~~~~~~~~~~ ^ >> mm/shmem.c:4310:19: error: too few arguments provided to function-like macro invocation 4310 | L1_CACHE_BYTES), GFP_KERNEL); | ^ include/linux/minmax.h:169:9: note: macro 'max_t' defined here 169 | #define max_t(type, x, y) __careful_cmp(max, (type)(x), (type)(y)) | ^ >> mm/shmem.c:4309:19: error: use of undeclared identifier 'max_t' 4309 | sbinfo = kzalloc(max_t((int)sizeof(struct shmem_sb_info), | ^ 12 warnings and 2 errors generated. vim +4310 mm/shmem.c ^1da177e4c3f41 Linus Torvalds 2005-04-16 4300 f32356261d44d5 David Howells 2019-03-25 4301 static int shmem_fill_super(struct super_block *sb, struct fs_context *fc) ^1da177e4c3f41 Linus Torvalds 2005-04-16 4302 { f32356261d44d5 David Howells 2019-03-25 4303 struct shmem_options *ctx = fc->fs_private; ^1da177e4c3f41 Linus Torvalds 2005-04-16 4304 struct inode *inode; 0edd73b33426df Hugh Dickins 2005-06-21 4305 struct shmem_sb_info *sbinfo; 71480663b751de Carlos Maiolino 2023-07-25 4306 int error = -ENOMEM; 680d794babebc7 Andrew Morton 2008-02-08 4307 680d794babebc7 Andrew Morton 2008-02-08 4308 /* Round up to L1_CACHE_BYTES to resist false sharing */ 1c6e8dc111cb86 Omkar Wagle 2023-11-08 @4309 sbinfo = kzalloc(max_t((int)sizeof(struct shmem_sb_info), 680d794babebc7 Andrew Morton 2008-02-08 @4310 L1_CACHE_BYTES), GFP_KERNEL); 680d794babebc7 Andrew Morton 2008-02-08 4311 if (!sbinfo) 71480663b751de Carlos Maiolino 2023-07-25 4312 return error; 680d794babebc7 Andrew Morton 2008-02-08 4313 680d794babebc7 Andrew Morton 2008-02-08 4314 sb->s_fs_info = sbinfo; ^1da177e4c3f41 Linus Torvalds 2005-04-16 4315
diff --git a/mm/shmem.c b/mm/shmem.c index 91e2620148b2..fce230cc5ccc 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -395,6 +395,7 @@ static int shmem_reserve_inode(struct super_block *sb, ino_t *inop) static void shmem_free_inode(struct super_block *sb, size_t freed_ispace) { struct shmem_sb_info *sbinfo = SHMEM_SB(sb); + if (sbinfo->max_inodes) { raw_spin_lock(&sbinfo->stat_lock); sbinfo->free_ispace += BOGO_INODE_SIZE + freed_ispace; @@ -735,6 +736,7 @@ static long shmem_unused_huge_count(struct super_block *sb, struct shrink_control *sc) { struct shmem_sb_info *sbinfo = SHMEM_SB(sb); + return READ_ONCE(sbinfo->shrinklist_len); } #else /* !CONFIG_TRANSPARENT_HUGEPAGE */ @@ -1146,9 +1148,8 @@ static int shmem_setattr(struct mnt_idmap *idmap, return error; if ((info->seals & F_SEAL_EXEC) && (attr->ia_valid & ATTR_MODE)) { - if ((inode->i_mode ^ attr->ia_mode) & 0111) { + if ((inode->i_mode ^ attr->ia_mode) & 0111) return -EPERM; - } } if (S_ISREG(inode->i_mode) && (attr->ia_valid & ATTR_SIZE)) { @@ -1172,6 +1173,7 @@ static int shmem_setattr(struct mnt_idmap *idmap, } if (newsize <= oldsize) { loff_t holebegin = round_up(newsize, PAGE_SIZE); + if (oldsize > holebegin) unmap_mapping_range(inode->i_mapping, holebegin, 0, 1); @@ -1454,6 +1456,7 @@ static int shmem_writepage(struct page *page, struct writeback_control *wbc) if (!folio_test_uptodate(folio)) { if (inode->i_private) { struct shmem_falloc *shmem_falloc; + spin_lock(&inode->i_lock); shmem_falloc = inode->i_private; if (shmem_falloc && @@ -1527,6 +1530,7 @@ static void shmem_show_mpol(struct seq_file *seq, struct mempolicy *mpol) static struct mempolicy *shmem_get_sbmpol(struct shmem_sb_info *sbinfo) { struct mempolicy *mpol = NULL; + if (sbinfo->mpol) { raw_spin_lock(&sbinfo->stat_lock); /* prevent replace/use races */ mpol = sbinfo->mpol; @@ -2129,6 +2133,7 @@ static int synchronous_wake_function(wait_queue_entry_t *wait, unsigned int mode, int sync, void *key) { int ret = default_wake_function(wait, mode, sync, key); + list_del_init(&wait->entry); return ret; } @@ -2314,6 +2319,7 @@ unsigned long shmem_get_unmapped_area(struct file *file, static int shmem_set_policy(struct vm_area_struct *vma, struct mempolicy *mpol) { struct inode *inode = file_inode(vma->vm_file); + return mpol_set_shared_policy(&SHMEM_I(inode)->policy, vma, mpol); } @@ -2681,7 +2687,7 @@ static const struct inode_operations shmem_short_symlink_operations; static int shmem_write_begin(struct file *file, struct address_space *mapping, - loff_t pos, unsigned len, + loff_t pos, unsigned int len, struct page **pagep, void **fsdata) { struct inode *inode = mapping->host; @@ -2716,7 +2722,7 @@ shmem_write_begin(struct file *file, struct address_space *mapping, static int shmem_write_end(struct file *file, struct address_space *mapping, - loff_t pos, unsigned len, unsigned copied, + loff_t pos, unsigned int len, unsigned int copied, struct page *page, void *fsdata) { struct folio *folio = page_folio(page); @@ -2728,6 +2734,7 @@ shmem_write_end(struct file *file, struct address_space *mapping, if (!folio_test_uptodate(folio)) { if (copied < folio_size(folio)) { size_t from = offset_in_folio(folio, pos); + folio_zero_segments(folio, 0, from, from + copied, folio_size(folio)); } @@ -3731,6 +3738,7 @@ static const struct xattr_handler * const shmem_xattr_handlers[] = { static ssize_t shmem_listxattr(struct dentry *dentry, char *buffer, size_t size) { struct shmem_inode_info *info = SHMEM_I(d_inode(dentry)); + return simple_xattr_list(d_inode(dentry), &info->xattrs, buffer, size); } #endif /* CONFIG_TMPFS_XATTR */ @@ -3762,6 +3770,7 @@ static int shmem_match(struct inode *ino, void *vfh) { __u32 *fh = vfh; __u64 inum = fh[2]; + inum = (inum << 32) | fh[1]; return ino->i_ino == inum && fh[0] == ino->i_generation; } @@ -3812,6 +3821,7 @@ static int shmem_encode_fh(struct inode *inode, __u32 *fh, int *len, * to do it once */ static DEFINE_SPINLOCK(lock); + spin_lock(&lock); if (inode_unhashed(inode)) __insert_inode_hash(inode, @@ -3864,20 +3874,20 @@ static const struct constant_table shmem_param_enums_huge[] = { const struct fs_parameter_spec shmem_fs_parameters[] = { fsparam_u32 ("gid", Opt_gid), - fsparam_enum ("huge", Opt_huge, shmem_param_enums_huge), + fsparam_enum("huge", Opt_huge, shmem_param_enums_huge), fsparam_u32oct("mode", Opt_mode), fsparam_string("mpol", Opt_mpol), fsparam_string("nr_blocks", Opt_nr_blocks), fsparam_string("nr_inodes", Opt_nr_inodes), fsparam_string("size", Opt_size), fsparam_u32 ("uid", Opt_uid), - fsparam_flag ("inode32", Opt_inode32), - fsparam_flag ("inode64", Opt_inode64), - fsparam_flag ("noswap", Opt_noswap), + fsparam_flag("inode32", Opt_inode32), + fsparam_flag("inode64", Opt_inode64), + fsparam_flag("noswap", Opt_noswap), #ifdef CONFIG_TMPFS_QUOTA - fsparam_flag ("quota", Opt_quota), - fsparam_flag ("usrquota", Opt_usrquota), - fsparam_flag ("grpquota", Opt_grpquota), + fsparam_flag("quota", Opt_quota), + fsparam_flag("usrquota", Opt_usrquota), + fsparam_flag("grpquota", Opt_grpquota), fsparam_string("usrquota_block_hardlimit", Opt_usrquota_block_hardlimit), fsparam_string("usrquota_inode_hardlimit", Opt_usrquota_inode_hardlimit), fsparam_string("grpquota_block_hardlimit", Opt_grpquota_block_hardlimit), @@ -4063,12 +4073,14 @@ static int shmem_parse_options(struct fs_context *fc, void *data) if (options) { int err = security_sb_eat_lsm_opts(options, &fc->security); + if (err) return err; } while (options != NULL) { char *this_char = options; + for (;;) { /* * NUL-terminate this option: unfortunately, @@ -4249,7 +4261,7 @@ static int shmem_show_options(struct seq_file *seq, struct dentry *root) shmem_show_mpol(seq, mpol); mpol_put(mpol); if (sbinfo->noswap) - seq_printf(seq, ",noswap"); + seq_puts(seq, ",noswap"); return 0; } @@ -4277,7 +4289,7 @@ static int shmem_fill_super(struct super_block *sb, struct fs_context *fc) int error = -ENOMEM; /* Round up to L1_CACHE_BYTES to resist false sharing */ - sbinfo = kzalloc(max((int)sizeof(struct shmem_sb_info), + sbinfo = kzalloc(max_t((int)sizeof(struct shmem_sb_info), L1_CACHE_BYTES), GFP_KERNEL); if (!sbinfo) return error; @@ -4405,6 +4417,7 @@ static struct kmem_cache *shmem_inode_cachep __ro_after_init; static struct inode *shmem_alloc_inode(struct super_block *sb) { struct shmem_inode_info *info; + info = alloc_inode_sb(sb, shmem_inode_cachep, GFP_KERNEL); if (!info) return NULL; @@ -4429,6 +4442,7 @@ static void shmem_destroy_inode(struct inode *inode) static void shmem_init_inode(void *foo) { struct shmem_inode_info *info = foo; + inode_init_once(&info->vfs_inode); } @@ -4761,6 +4775,7 @@ static inline struct inode *shmem_get_inode(struct mnt_idmap *idmap, umode_t mode, dev_t dev, unsigned long flags) { struct inode *inode = ramfs_get_inode(sb, dir, mode, dev); + return inode ? inode : ERR_PTR(-ENOSPC); } @@ -4787,7 +4802,7 @@ static struct file *__shmem_file_setup(struct vfsmount *mnt, const char *name, return ERR_PTR(-EINVAL); inode = shmem_get_inode(&nop_mnt_idmap, mnt->mnt_sb, NULL, - S_IFREG | S_IRWXUGO, 0, flags); + S_IFREG | 0777, 0, flags); if (IS_ERR(inode)) { shmem_unacct_size(flags, size); return ERR_CAST(inode); @@ -4806,10 +4821,10 @@ static struct file *__shmem_file_setup(struct vfsmount *mnt, const char *name, /** * shmem_kernel_file_setup - get an unlinked file living in tmpfs which must be - * kernel internal. There will be NO LSM permission checks against the - * underlying inode. So users of this interface must do LSM checks at a - * higher layer. The users are the big_key and shm implementations. LSM - * checks are provided at the key or shm level rather than the inode. + * kernel internal. There will be NO LSM permission checks against the + * underlying inode. So users of this interface must do LSM checks at a + * higher layer. The users are the big_key and shm implementations. LSM + * checks are provided at the key or shm level rather than the inode. * @name: name for dentry (to be seen in /proc/<pid>/maps * @size: size to be set for the file * @flags: VM_NORESERVE suppresses pre-accounting of the entire object size
Remove most of the code style warnings Signed-off-by: Omkar Wagle<ov.wagle@gmail.com> --- mm/shmem.c | 51 +++++++++++++++++++++++++++++++++------------------ 1 file changed, 33 insertions(+), 18 deletions(-)