Message ID | 20240513124141.3788846-1-lihongbo22@huawei.com |
---|---|
State | Superseded |
Headers | show |
Series | hostfs: convert hostfs to use the new mount api | expand |
Hi Hongbo, kernel test robot noticed the following build warnings: [auto build test WARNING on uml/next] [also build test WARNING on wireless-next/main wireless/main linus/master v6.9 next-20240513] [cannot apply to uml/fixes] [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/Hongbo-Li/hostfs-convert-hostfs-to-use-the-new-mount-api/20240513-204233 base: git://git.kernel.org/pub/scm/linux/kernel/git/uml/linux next patch link: https://lore.kernel.org/r/20240513124141.3788846-1-lihongbo22%40huawei.com patch subject: [PATCH] hostfs: convert hostfs to use the new mount api config: um-allnoconfig (https://download.01.org/0day-ci/archive/20240513/202405132349.LJ3Qx7on-lkp@intel.com/config) compiler: clang version 17.0.6 (https://github.com/llvm/llvm-project 6009708b4367171ccdbf4b5905cb6a803753fe18) reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20240513/202405132349.LJ3Qx7on-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/202405132349.LJ3Qx7on-lkp@intel.com/ All warnings (new ones prefixed by >>): In file included from fs/hostfs/hostfs_kern.c:13: 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 fs/hostfs/hostfs_kern.c:13: 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 fs/hostfs/hostfs_kern.c:13: 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); | ~~~~~~~~~~ ^ >> fs/hostfs/hostfs_kern.c:956:6: warning: variable 'host_root' is used uninitialized whenever 'if' condition is false [-Wsometimes-uninitialized] 956 | if (fc->source == NULL) | ^~~~~~~~~~~~~~~~~~ fs/hostfs/hostfs_kern.c:960:44: note: uninitialized use occurs here 960 | kasprintf(GFP_KERNEL, "%s/%s", root_ino, host_root); | ^~~~~~~~~ fs/hostfs/hostfs_kern.c:956:2: note: remove the 'if' if its condition is always true 956 | if (fc->source == NULL) | ^~~~~~~~~~~~~~~~~~~~~~~ 957 | host_root = ""; fs/hostfs/hostfs_kern.c:942:17: note: initialize the variable 'host_root' to silence this warning 942 | char *host_root; | ^ | = NULL 13 warnings generated. vim +956 fs/hostfs/hostfs_kern.c 937 938 static int hostfs_fill_super(struct super_block *sb, struct fs_context *fc) 939 { 940 struct hostfs_fs_info *fsi = sb->s_fs_info; 941 struct inode *root_inode; 942 char *host_root; 943 int err; 944 945 sb->s_blocksize = 1024; 946 sb->s_blocksize_bits = 10; 947 sb->s_magic = HOSTFS_SUPER_MAGIC; 948 sb->s_op = &hostfs_sbops; 949 sb->s_d_op = &simple_dentry_operations; 950 sb->s_maxbytes = MAX_LFS_FILESIZE; 951 err = super_setup_bdi(sb); 952 if (err) 953 return err; 954 955 /* NULL is printed as '(null)' by printf(): avoid that. */ > 956 if (fc->source == NULL) 957 host_root = ""; 958 959 fsi->host_root_path = 960 kasprintf(GFP_KERNEL, "%s/%s", root_ino, host_root); 961 if (fsi->host_root_path == NULL) 962 return -ENOMEM; 963 964 root_inode = hostfs_iget(sb, fsi->host_root_path); 965 if (IS_ERR(root_inode)) 966 return PTR_ERR(root_inode); 967 968 if (S_ISLNK(root_inode->i_mode)) { 969 char *name; 970 971 iput(root_inode); 972 name = follow_link(fsi->host_root_path); 973 if (IS_ERR(name)) 974 return PTR_ERR(name); 975 976 root_inode = hostfs_iget(sb, name); 977 kfree(name); 978 if (IS_ERR(root_inode)) 979 return PTR_ERR(root_inode); 980 } 981 982 sb->s_root = d_make_root(root_inode); 983 if (sb->s_root == NULL) 984 return -ENOMEM; 985 986 return 0; 987 } 988
Hi Hongbo, kernel test robot noticed the following build warnings: https://git-scm.com/docs/git-format-patch#_base_tree_information] url: https://github.com/intel-lab-lkp/linux/commits/Hongbo-Li/hostfs-convert-hostfs-to-use-the-new-mount-api/20240513-204233 base: git://git.kernel.org/pub/scm/linux/kernel/git/uml/linux next patch link: https://lore.kernel.org/r/20240513124141.3788846-1-lihongbo22%40huawei.com patch subject: [PATCH] hostfs: convert hostfs to use the new mount api config: um-randconfig-r081-20240517 (https://download.01.org/0day-ci/archive/20240517/202405171154.21q42SWy-lkp@intel.com/config) compiler: clang version 19.0.0git (https://github.com/llvm/llvm-project d3455f4ddd16811401fa153298fadd2f59f6914e) 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> | Reported-by: Dan Carpenter <dan.carpenter@linaro.org> | Closes: https://lore.kernel.org/r/202405171154.21q42SWy-lkp@intel.com/ smatch warnings: fs/hostfs/hostfs_kern.c:960 hostfs_fill_super() error: uninitialized symbol 'host_root'. vim +/host_root +960 fs/hostfs/hostfs_kern.c 2c2593890079e8 Hongbo Li 2024-05-13 938 static int hostfs_fill_super(struct super_block *sb, struct fs_context *fc) ^1da177e4c3f41 Linus Torvalds 2005-04-16 939 { 2c2593890079e8 Hongbo Li 2024-05-13 940 struct hostfs_fs_info *fsi = sb->s_fs_info; ^1da177e4c3f41 Linus Torvalds 2005-04-16 941 struct inode *root_inode; 2c2593890079e8 Hongbo Li 2024-05-13 942 char *host_root; ^1da177e4c3f41 Linus Torvalds 2005-04-16 943 int err; ^1da177e4c3f41 Linus Torvalds 2005-04-16 944 ^1da177e4c3f41 Linus Torvalds 2005-04-16 945 sb->s_blocksize = 1024; ^1da177e4c3f41 Linus Torvalds 2005-04-16 946 sb->s_blocksize_bits = 10; ^1da177e4c3f41 Linus Torvalds 2005-04-16 947 sb->s_magic = HOSTFS_SUPER_MAGIC; ^1da177e4c3f41 Linus Torvalds 2005-04-16 948 sb->s_op = &hostfs_sbops; b26d4cd385fc51 Al Viro 2013-10-25 949 sb->s_d_op = &simple_dentry_operations; 752fa51e4c5182 Wolfgang Illmeyer 2009-06-30 950 sb->s_maxbytes = MAX_LFS_FILESIZE; ce72750f04d68a Sjoerd Simons 2021-11-05 951 err = super_setup_bdi(sb); ce72750f04d68a Sjoerd Simons 2021-11-05 952 if (err) 74ce793bcbde5c Mickaël Salaün 2023-06-12 953 return err; ^1da177e4c3f41 Linus Torvalds 2005-04-16 954 b58c4e96192ee7 Andy Shevchenko 2020-03-20 955 /* NULL is printed as '(null)' by printf(): avoid that. */ 2c2593890079e8 Hongbo Li 2024-05-13 956 if (fc->source == NULL) 2c2593890079e8 Hongbo Li 2024-05-13 957 host_root = ""; Uninitialized on else path ^1da177e4c3f41 Linus Torvalds 2005-04-16 958 2c2593890079e8 Hongbo Li 2024-05-13 959 fsi->host_root_path = 2c2593890079e8 Hongbo Li 2024-05-13 @960 kasprintf(GFP_KERNEL, "%s/%s", root_ino, host_root); ^^^^^^^^^ 2c2593890079e8 Hongbo Li 2024-05-13 961 if (fsi->host_root_path == NULL) 74ce793bcbde5c Mickaël Salaün 2023-06-12 962 return -ENOMEM;
Thanks for your attention, I have solved the warnings in the following patch (the similar title: hostfs: convert hostfs to use the new mount API): https://lore.kernel.org/all/20240515025536.3667017-1-lihongbo22@huawei.com/ or https://patchwork.ozlabs.org/project/linux-um/patch/20240515025536.3667017-1-lihongbo22@huawei.com/ It was strange that the kernel test robot did not send the results on the new patch. Thanks, Hongbo On 2024/5/17 19:01, Dan Carpenter wrote: > Hi Hongbo, > > kernel test robot noticed the following build warnings: > > https://git-scm.com/docs/git-format-patch#_base_tree_information] > > url: https://github.com/intel-lab-lkp/linux/commits/Hongbo-Li/hostfs-convert-hostfs-to-use-the-new-mount-api/20240513-204233 > base: git://git.kernel.org/pub/scm/linux/kernel/git/uml/linux next > patch link: https://lore.kernel.org/r/20240513124141.3788846-1-lihongbo22%40huawei.com > patch subject: [PATCH] hostfs: convert hostfs to use the new mount api > config: um-randconfig-r081-20240517 (https://download.01.org/0day-ci/archive/20240517/202405171154.21q42SWy-lkp@intel.com/config) > compiler: clang version 19.0.0git (https://github.com/llvm/llvm-project d3455f4ddd16811401fa153298fadd2f59f6914e) > > 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> > | Reported-by: Dan Carpenter <dan.carpenter@linaro.org> > | Closes: https://lore.kernel.org/r/202405171154.21q42SWy-lkp@intel.com/ > > smatch warnings: > fs/hostfs/hostfs_kern.c:960 hostfs_fill_super() error: uninitialized symbol 'host_root'. > > vim +/host_root +960 fs/hostfs/hostfs_kern.c > > 2c2593890079e8 Hongbo Li 2024-05-13 938 static int hostfs_fill_super(struct super_block *sb, struct fs_context *fc) > ^1da177e4c3f41 Linus Torvalds 2005-04-16 939 { > 2c2593890079e8 Hongbo Li 2024-05-13 940 struct hostfs_fs_info *fsi = sb->s_fs_info; > ^1da177e4c3f41 Linus Torvalds 2005-04-16 941 struct inode *root_inode; > 2c2593890079e8 Hongbo Li 2024-05-13 942 char *host_root; > ^1da177e4c3f41 Linus Torvalds 2005-04-16 943 int err; > ^1da177e4c3f41 Linus Torvalds 2005-04-16 944 > ^1da177e4c3f41 Linus Torvalds 2005-04-16 945 sb->s_blocksize = 1024; > ^1da177e4c3f41 Linus Torvalds 2005-04-16 946 sb->s_blocksize_bits = 10; > ^1da177e4c3f41 Linus Torvalds 2005-04-16 947 sb->s_magic = HOSTFS_SUPER_MAGIC; > ^1da177e4c3f41 Linus Torvalds 2005-04-16 948 sb->s_op = &hostfs_sbops; > b26d4cd385fc51 Al Viro 2013-10-25 949 sb->s_d_op = &simple_dentry_operations; > 752fa51e4c5182 Wolfgang Illmeyer 2009-06-30 950 sb->s_maxbytes = MAX_LFS_FILESIZE; > ce72750f04d68a Sjoerd Simons 2021-11-05 951 err = super_setup_bdi(sb); > ce72750f04d68a Sjoerd Simons 2021-11-05 952 if (err) > 74ce793bcbde5c Mickaël Salaün 2023-06-12 953 return err; > ^1da177e4c3f41 Linus Torvalds 2005-04-16 954 > b58c4e96192ee7 Andy Shevchenko 2020-03-20 955 /* NULL is printed as '(null)' by printf(): avoid that. */ > 2c2593890079e8 Hongbo Li 2024-05-13 956 if (fc->source == NULL) > 2c2593890079e8 Hongbo Li 2024-05-13 957 host_root = ""; > > Uninitialized on else path > > ^1da177e4c3f41 Linus Torvalds 2005-04-16 958 > 2c2593890079e8 Hongbo Li 2024-05-13 959 fsi->host_root_path = > 2c2593890079e8 Hongbo Li 2024-05-13 @960 kasprintf(GFP_KERNEL, "%s/%s", root_ino, host_root); > ^^^^^^^^^ > > > 2c2593890079e8 Hongbo Li 2024-05-13 961 if (fsi->host_root_path == NULL) > 74ce793bcbde5c Mickaël Salaün 2023-06-12 962 return -ENOMEM; >
On Fri, May 17, 2024 at 07:21:09PM +0800, Hongbo Li wrote: > Thanks for your attention, I have solved the warnings in the following patch > (the similar title: hostfs: convert hostfs to use the new mount API): > > https://lore.kernel.org/all/20240515025536.3667017-1-lihongbo22@huawei.com/ > > or > > https://patchwork.ozlabs.org/project/linux-um/patch/20240515025536.3667017-1-lihongbo22@huawei.com/ > > It was strange that the kernel test robot did not send the results on the > new patch. With uninitialized variable warnings, quite often Smatch is not the only or first checker to report the bug so I normally search lore to see if it has already been fixed. In this case there were no bug reports from Nathan Chancelor and the second version of the patch wasn't marked as a v2 and there was no note explaining it like: --- v2: fixed uninitialized variable warning So it wasn't immediately clear that it had been fixed already. https://staticthinking.wordpress.com/2022/07/27/how-to-send-a-v2-patch/ regards, dan carpenter
diff --git a/fs/hostfs/hostfs_kern.c b/fs/hostfs/hostfs_kern.c index a73d27c4dd58..24e64dda65df 100644 --- a/fs/hostfs/hostfs_kern.c +++ b/fs/hostfs/hostfs_kern.c @@ -16,11 +16,16 @@ #include <linux/seq_file.h> #include <linux/writeback.h> #include <linux/mount.h> +#include <linux/fs_context.h> #include <linux/namei.h> #include "hostfs.h" #include <init.h> #include <kern.h> +struct hostfs_fs_info { + char *host_root_path; +}; + struct hostfs_inode_info { int fd; fmode_t mode; @@ -90,8 +95,10 @@ static char *__dentry_name(struct dentry *dentry, char *name) char *p = dentry_path_raw(dentry, name, PATH_MAX); char *root; size_t len; + struct hostfs_fs_info *fsi; - root = dentry->d_sb->s_fs_info; + fsi = dentry->d_sb->s_fs_info; + root = fsi->host_root_path; len = strlen(root); if (IS_ERR(p)) { __putname(name); @@ -196,8 +203,10 @@ static int hostfs_statfs(struct dentry *dentry, struct kstatfs *sf) long long f_bavail; long long f_files; long long f_ffree; + struct hostfs_fs_info *fsi; - err = do_statfs(dentry->d_sb->s_fs_info, + fsi = dentry->d_sb->s_fs_info; + err = do_statfs(fsi->host_root_path, &sf->f_bsize, &f_blocks, &f_bfree, &f_bavail, &f_files, &f_ffree, &sf->f_fsid, sizeof(sf->f_fsid), &sf->f_namelen); @@ -245,7 +254,11 @@ static void hostfs_free_inode(struct inode *inode) static int hostfs_show_options(struct seq_file *seq, struct dentry *root) { - const char *root_path = root->d_sb->s_fs_info; + struct hostfs_fs_info *fsi; + const char *root_path; + + fsi = root->d_sb->s_fs_info; + root_path = fsi->host_root_path; size_t offset = strlen(root_ino) + 1; if (strlen(root_path) > offset) @@ -922,10 +935,11 @@ static const struct inode_operations hostfs_link_iops = { .get_link = hostfs_get_link, }; -static int hostfs_fill_sb_common(struct super_block *sb, void *d, int silent) +static int hostfs_fill_super(struct super_block *sb, struct fs_context *fc) { + struct hostfs_fs_info *fsi = sb->s_fs_info; struct inode *root_inode; - char *host_root_path, *req_root = d; + char *host_root; int err; sb->s_blocksize = 1024; @@ -939,15 +953,15 @@ static int hostfs_fill_sb_common(struct super_block *sb, void *d, int silent) return err; /* NULL is printed as '(null)' by printf(): avoid that. */ - if (req_root == NULL) - req_root = ""; + if (fc->source == NULL) + host_root = ""; - sb->s_fs_info = host_root_path = - kasprintf(GFP_KERNEL, "%s/%s", root_ino, req_root); - if (host_root_path == NULL) + fsi->host_root_path = + kasprintf(GFP_KERNEL, "%s/%s", root_ino, host_root); + if (fsi->host_root_path == NULL) return -ENOMEM; - root_inode = hostfs_iget(sb, host_root_path); + root_inode = hostfs_iget(sb, fsi->host_root_path); if (IS_ERR(root_inode)) return PTR_ERR(root_inode); @@ -955,7 +969,7 @@ static int hostfs_fill_sb_common(struct super_block *sb, void *d, int silent) char *name; iput(root_inode); - name = follow_link(host_root_path); + name = follow_link(fsi->host_root_path); if (IS_ERR(name)) return PTR_ERR(name); @@ -972,11 +986,38 @@ static int hostfs_fill_sb_common(struct super_block *sb, void *d, int silent) return 0; } -static struct dentry *hostfs_read_sb(struct file_system_type *type, - int flags, const char *dev_name, - void *data) +static int hostfs_fc_get_tree(struct fs_context *fc) { - return mount_nodev(type, flags, data, hostfs_fill_sb_common); + return get_tree_nodev(fc, hostfs_fill_super); +} + +static void hostfs_fc_free(struct fs_context *fc) +{ + struct hostfs_fs_info *fsi = fc->s_fs_info; + + if (!fsi) + return; + + kfree(fsi->host_root_path); + kfree(fsi); +} + +static const struct fs_context_operations hostfs_context_ops = { + .get_tree = hostfs_fc_get_tree, + .free = hostfs_fc_free, +}; + +static int hostfs_init_fs_context(struct fs_context *fc) +{ + struct hostfs_fs_info *fsi; + + fsi = kzalloc(sizeof(*fsi), GFP_KERNEL); + if (!fsi) + return -ENOMEM; + + fc->s_fs_info = fsi; + fc->ops = &hostfs_context_ops; + return 0; } static void hostfs_kill_sb(struct super_block *s) @@ -986,11 +1027,11 @@ static void hostfs_kill_sb(struct super_block *s) } static struct file_system_type hostfs_type = { - .owner = THIS_MODULE, - .name = "hostfs", - .mount = hostfs_read_sb, - .kill_sb = hostfs_kill_sb, - .fs_flags = 0, + .owner = THIS_MODULE, + .name = "hostfs", + .init_fs_context = hostfs_init_fs_context, + .kill_sb = hostfs_kill_sb, + .fs_flags = 0, }; MODULE_ALIAS_FS("hostfs");
Convert the hostfs filesystem to use the new mount API. Signed-off-by: Hongbo Li <lihongbo22@huawei.com> --- fs/hostfs/hostfs_kern.c | 83 ++++++++++++++++++++++++++++++----------- 1 file changed, 62 insertions(+), 21 deletions(-)