[kbuild] drivers/soc/ti/k3-ringacc.c:562 k3_ringacc_ring_cfg() warn: variable dereferenced before check 'ring' (see line 559)

From: Dan Carpenter
Date: Fri Jun 12 2020 - 09:43:25 EST


tree: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master
head: b791d1bdf9212d944d749a5c7ff6febdba241771
commit: 3277e8aa2504d97e022ecb9777d784ac1a439d36 soc: ti: k3: add navss ringacc driver
config: arm64-randconfig-m031-20200612 (attached as .config)
compiler: aarch64-linux-gcc (GCC) 9.3.0

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@xxxxxxxxx>
Reported-by: Dan Carpenter <dan.carpenter@xxxxxxxxxx>

smatch warnings:
drivers/soc/ti/k3-ringacc.c:562 k3_ringacc_ring_cfg() warn: variable dereferenced before check 'ring' (see line 559)

# https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=3277e8aa2504d97e022ecb9777d784ac1a439d36
git remote add linus https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
git remote update linus
git checkout 3277e8aa2504d97e022ecb9777d784ac1a439d36
vim +/ring +562 drivers/soc/ti/k3-ringacc.c

3277e8aa2504d97 Grygorii Strashko 2020-01-15 557 int k3_ringacc_ring_cfg(struct k3_ring *ring, struct k3_ring_cfg *cfg)
3277e8aa2504d97 Grygorii Strashko 2020-01-15 558 {
3277e8aa2504d97 Grygorii Strashko 2020-01-15 @559 struct k3_ringacc *ringacc = ring->parent;
^^^^^^^^^^^^
Dereference.

3277e8aa2504d97 Grygorii Strashko 2020-01-15 560 int ret = 0;
3277e8aa2504d97 Grygorii Strashko 2020-01-15 561
3277e8aa2504d97 Grygorii Strashko 2020-01-15 @562 if (!ring || !cfg)
^^^^
Check too late. Delete it?

3277e8aa2504d97 Grygorii Strashko 2020-01-15 563 return -EINVAL;
3277e8aa2504d97 Grygorii Strashko 2020-01-15 564 if (cfg->elm_size > K3_RINGACC_RING_ELSIZE_256 ||
3277e8aa2504d97 Grygorii Strashko 2020-01-15 565 cfg->mode >= K3_RINGACC_RING_MODE_INVALID ||
3277e8aa2504d97 Grygorii Strashko 2020-01-15 566 cfg->size & ~K3_RINGACC_CFG_RING_SIZE_ELCNT_MASK ||
3277e8aa2504d97 Grygorii Strashko 2020-01-15 567 !test_bit(ring->ring_id, ringacc->rings_inuse))
3277e8aa2504d97 Grygorii Strashko 2020-01-15 568 return -EINVAL;
3277e8aa2504d97 Grygorii Strashko 2020-01-15 569
3277e8aa2504d97 Grygorii Strashko 2020-01-15 570 if (cfg->mode == K3_RINGACC_RING_MODE_MESSAGE &&

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@xxxxxxxxxxxx

Attachment: .config.gz
Description: application/gzip

_______________________________________________
kbuild mailing list -- kbuild@xxxxxxxxxxxx
To unsubscribe send an email to kbuild-leave@xxxxxxxxxxxx