drivers/remoteproc/pru_rproc.c:341 pru_rproc_set_ctable() warn: variable dereferenced before IS_ERR check 'rproc' (see line 335)
From: Dan Carpenter
Date: Fri Jul 28 2023 - 17:07:29 EST
Hi Simon,
FYI, the error/warning was bisected to this commit, please ignore it if it's irrelevant.
tree: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master
head: f837f0a3c94882a29e38ff211a36c1c8a0f07804
commit: e752f9b924a1fd1afcf36e51b03dfa9c3096a3bd soc: ti: pruss: Allow compile-testing
config: csky-randconfig-m041-20230727 (https://download.01.org/0day-ci/archive/20230729/202307290417.hrgfPCcg-lkp@xxxxxxxxx/config)
compiler: csky-linux-gcc (GCC) 12.3.0
reproduce: (https://download.01.org/0day-ci/archive/20230729/202307290417.hrgfPCcg-lkp@xxxxxxxxx/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@xxxxxxxxx>
| Reported-by: Dan Carpenter <dan.carpenter@xxxxxxxxxx>
| Closes: https://lore.kernel.org/r/202307290417.hrgfPCcg-lkp@xxxxxxxxx/
smatch warnings:
drivers/remoteproc/pru_rproc.c:341 pru_rproc_set_ctable() warn: variable dereferenced before IS_ERR check 'rproc' (see line 335)
vim +/rproc +341 drivers/remoteproc/pru_rproc.c
102853400321bae Roger Quadros 2023-01-06 333 int pru_rproc_set_ctable(struct rproc *rproc, enum pru_ctable_idx c, u32 addr)
102853400321bae Roger Quadros 2023-01-06 334 {
102853400321bae Roger Quadros 2023-01-06 @335 struct pru_rproc *pru = rproc->priv;
^^^^^^^^^^^^
Dereference
102853400321bae Roger Quadros 2023-01-06 336 unsigned int reg;
102853400321bae Roger Quadros 2023-01-06 337 u32 mask, set;
102853400321bae Roger Quadros 2023-01-06 338 u16 idx;
102853400321bae Roger Quadros 2023-01-06 339 u16 idx_mask;
102853400321bae Roger Quadros 2023-01-06 340
102853400321bae Roger Quadros 2023-01-06 @341 if (IS_ERR_OR_NULL(rproc))
102853400321bae Roger Quadros 2023-01-06 342 return -EINVAL;
Checked too late. Also ideally it would be:
if (IS_ERR_OR_NULL(rproc))
return PTR_ERR(rproc);
If a pointer can be both error and NULL then generally the NULL is a
special kind of success. It means the option is turned off so there
is nothing to do, so an early return is success.
https://staticthinking.wordpress.com/2022/08/01/mixing-error-pointers-and-null/
102853400321bae Roger Quadros 2023-01-06 343
102853400321bae Roger Quadros 2023-01-06 344 if (!rproc->dev.parent || !is_pru_rproc(rproc->dev.parent))
102853400321bae Roger Quadros 2023-01-06 345 return -ENODEV;
102853400321bae Roger Quadros 2023-01-06 346
102853400321bae Roger Quadros 2023-01-06 347 /* pointer is 16 bit and index is 8-bit so mask out the rest */
102853400321bae Roger Quadros 2023-01-06 348 idx_mask = (c >= PRU_C28) ? 0xFFFF : 0xFF;
102853400321bae Roger Quadros 2023-01-06 349
102853400321bae Roger Quadros 2023-01-06 350 /* ctable uses bit 8 and upwards only */
102853400321bae Roger Quadros 2023-01-06 351 idx = (addr >> 8) & idx_mask;
--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki