fs/ksmbd/smb_common.c:350 smb1_allocate_rsp_buf() warn: Please consider using kzalloc instead of kmalloc

From: Dan Carpenter
Date: Tue May 02 2023 - 07:31:53 EST


tree: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master
head: d06f5a3f7140921ada47d49574ae6fa4de5e2a89
commit: dc8289f912387c3bcfbc5d2db29c8947fa207c11 ksmbd: fix slab-out-of-bounds in init_smb2_rsp_hdr
config: openrisc-randconfig-m041-20230423 (https://download.01.org/0day-ci/archive/20230428/202304281001.oskkuJo0-lkp@xxxxxxxxx/config)
compiler: or1k-linux-gcc (GCC) 12.1.0

If you fix the issue, kindly add following tag where applicable
| Reported-by: kernel test robot <lkp@xxxxxxxxx>
| Reported-by: Dan Carpenter <error27@xxxxxxxxx>
| Link: https://lore.kernel.org/r/202304281001.oskkuJo0-lkp@xxxxxxxxx/

smatch warnings:
fs/ksmbd/smb_common.c:350 smb1_allocate_rsp_buf() warn: Please consider using kzalloc instead of kmalloc

vim +350 fs/ksmbd/smb_common.c

dc8289f912387c Namjae Jeon 2023-04-01 348 static int smb1_allocate_rsp_buf(struct ksmbd_work *work)
dc8289f912387c Namjae Jeon 2023-04-01 349 {
dc8289f912387c Namjae Jeon 2023-04-01 @350 work->response_buf = kmalloc(MAX_CIFS_SMALL_BUFFER_SIZE,
dc8289f912387c Namjae Jeon 2023-04-01 351 GFP_KERNEL | __GFP_ZERO);

Someone else wrote this Smatch check to encourage people to use kzalloc()
instead of __GFP_ZERO. I try stay out of style debates. :P

dc8289f912387c Namjae Jeon 2023-04-01 352 work->response_sz = MAX_CIFS_SMALL_BUFFER_SIZE;
dc8289f912387c Namjae Jeon 2023-04-01 353
dc8289f912387c Namjae Jeon 2023-04-01 354 if (!work->response_buf) {
dc8289f912387c Namjae Jeon 2023-04-01 355 pr_err("Failed to allocate %u bytes buffer\n",
dc8289f912387c Namjae Jeon 2023-04-01 356 MAX_CIFS_SMALL_BUFFER_SIZE);
dc8289f912387c Namjae Jeon 2023-04-01 357 return -ENOMEM;
dc8289f912387c Namjae Jeon 2023-04-01 358 }
dc8289f912387c Namjae Jeon 2023-04-01 359
dc8289f912387c Namjae Jeon 2023-04-01 360 return 0;
dc8289f912387c Namjae Jeon 2023-04-01 361 }

--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests