2022-09-24 14:20:00

by liujing

[permalink] [raw]
Subject: [PATCH] virtio_fs.c: add check kmalloc return

Signed-off-by: liujing <[email protected]>
---
fs/fuse/virtio_fs.c | 4 ++++
1 file changed, 4 insertions(+)

diff --git a/fs/fuse/virtio_fs.c b/fs/fuse/virtio_fs.c
index 4d8d4f16c727..07334c9c2883 100644
--- a/fs/fuse/virtio_fs.c
+++ b/fs/fuse/virtio_fs.c
@@ -989,6 +989,10 @@ __releases(fiq->lock)

/* Allocate a buffer for the request */
forget = kmalloc(sizeof(*forget), GFP_NOFS | __GFP_NOFAIL);
+
+ if (forget == NULL)
+ return -ENOMEM;
+
req = &forget->req;

req->ih = (struct fuse_in_header){
--
2.18.2




2022-09-24 22:04:37

by Joe Perches

[permalink] [raw]
Subject: Re: [PATCH] virtio_fs.c: add check kmalloc return

On Sat, 2022-09-24 at 10:17 -0400, liujing wrote:
> Signed-off-by: liujing <[email protected]>

Generally it's better to have a commit message

> diff --git a/fs/fuse/virtio_fs.c b/fs/fuse/virtio_fs.c
[]
> @@ -989,6 +989,10 @@ __releases(fiq->lock)
>
> /* Allocate a buffer for the request */
> forget = kmalloc(sizeof(*forget), GFP_NOFS | __GFP_NOFAIL);
> +

A blank line is not typically used here.

> + if (forget == NULL)
> + return -ENOMEM;

And this is unnecessary as __GFP_NOFAIL will do what it says.

include/linux/gfp_types.h:

* %__GFP_NOFAIL: The VM implementation _must_ retry infinitely: the caller
* cannot handle allocation failures. The allocation could block
* indefinitely but will never return with failure. Testing for
* failure is pointless.

2022-09-25 11:05:46

by kernel test robot

[permalink] [raw]
Subject: Re: [PATCH] virtio_fs.c: add check kmalloc return

Hi liujing,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on mszeredi-fuse/for-next]
[also build test ERROR on linus/master v6.0-rc6 next-20220923]
[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/liujing/virtio_fs-c-add-check-kmalloc-return/20220924-221859
base: https://git.kernel.org/pub/scm/linux/kernel/git/mszeredi/fuse.git for-next
config: x86_64-randconfig-a014
compiler: clang version 14.0.6 (https://github.com/llvm/llvm-project f28c006a5895fc0e329fe15fead81e37457cb1d1)
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
chmod +x ~/bin/make.cross
# https://github.com/intel-lab-lkp/linux/commit/41a643d745bd8722546399d1272b91a808cbd5d5
git remote add linux-review https://github.com/intel-lab-lkp/linux
git fetch --no-tags linux-review liujing/virtio_fs-c-add-check-kmalloc-return/20220924-221859
git checkout 41a643d745bd8722546399d1272b91a808cbd5d5
# save the config file
mkdir build_dir && cp config build_dir/.config
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=x86_64 SHELL=/bin/bash fs/

If you fix the issue, kindly add following tag where applicable
| Reported-by: kernel test robot <[email protected]>

All errors (new ones prefixed by >>):

>> fs/fuse/virtio_fs.c:994:3: error: void function 'virtio_fs_wake_forget_and_unlock' should not return a value [-Wreturn-type]
return -ENOMEM;
^ ~~~~~~~
1 error generated.


vim +/virtio_fs_wake_forget_and_unlock +994 fs/fuse/virtio_fs.c

972
973 static void virtio_fs_wake_forget_and_unlock(struct fuse_iqueue *fiq)
974 __releases(fiq->lock)
975 {
976 struct fuse_forget_link *link;
977 struct virtio_fs_forget *forget;
978 struct virtio_fs_forget_req *req;
979 struct virtio_fs *fs;
980 struct virtio_fs_vq *fsvq;
981 u64 unique;
982
983 link = fuse_dequeue_forget(fiq, 1, NULL);
984 unique = fuse_get_unique(fiq);
985
986 fs = fiq->priv;
987 fsvq = &fs->vqs[VQ_HIPRIO];
988 spin_unlock(&fiq->lock);
989
990 /* Allocate a buffer for the request */
991 forget = kmalloc(sizeof(*forget), GFP_NOFS | __GFP_NOFAIL);
992
993 if (forget == NULL)
> 994 return -ENOMEM;
995
996 req = &forget->req;
997
998 req->ih = (struct fuse_in_header){
999 .opcode = FUSE_FORGET,
1000 .nodeid = link->forget_one.nodeid,
1001 .unique = unique,
1002 .len = sizeof(*req),
1003 };
1004 req->arg = (struct fuse_forget_in){
1005 .nlookup = link->forget_one.nlookup,
1006 };
1007
1008 send_forget_request(fsvq, forget, false);
1009 kfree(link);
1010 }
1011

--
0-DAY CI Kernel Test Service
https://01.org/lkp


Attachments:
(No filename) (3.08 kB)
config (164.44 kB)
Download all attachments