Skip to contentSkip to conversation

drivers/soc/mediatek/mtk-svs.c:1740 svs_get_efuse_data() warn: passing zero to 'PTR_ERR'

PATCH New Dan Carpenter 1 participant 1 message Mar 13, 2023

lore
Share & tools
lore
#0 lore raw

PATCH 1161/2655 drivers/soc/mediatek/mtk-svs.c:1740 svs_get_efuse_data() warn: passing zero to 'PTR_ERR'

tree:   https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git master
head:   24469a0e5052ba01a35a15f104717a82b7a4798b
commit: 9f195f3a1e696b6576988c1e58fa7389beae3351 [1161/2655] soc: mediatek: mtk-svs: use svs get efuse common function
config: s390-randconfig-m031-20230310 (https://download.01.org/0day-ci/archive/20230312/[email protected]/config)
compiler: s390-linux-gcc (GCC) 12.1.0

If you fix the issue, kindly add following tag where applicable

| Reported-by: kernel test robot <[email protected]>
| Reported-by: Dan Carpenter <[email protected]>
| Link: https://lore.kernel.org/r/[email protected]/

New smatch warnings:
drivers/soc/mediatek/mtk-svs.c:1740 svs_get_efuse_data() warn: passing zero to 'PTR_ERR'

Old smatch warnings:
drivers/soc/mediatek/mtk-svs.c:1742 svs_get_efuse_data() warn: passing zero to 'PTR_ERR'

vim +/PTR_ERR +1740 drivers/soc/mediatek/mtk-svs.c

9f195f3a1e696b Roger Lu                   2023-02-02  1732  static int svs_get_efuse_data(struct svs_platform *svsp,
9f195f3a1e696b Roger Lu                   2023-02-02  1733  			      const char *nvmem_cell_name,
9f195f3a1e696b Roger Lu                   2023-02-02  1734  			      u32 **svsp_efuse, size_t *svsp_efuse_max)
43819e38533066 AngeloGioacchino Del Regno 2022-08-25  1735  {
43819e38533066 AngeloGioacchino Del Regno 2022-08-25  1736  	struct nvmem_cell *cell;
43819e38533066 AngeloGioacchino Del Regno 2022-08-25  1737  
9f195f3a1e696b Roger Lu                   2023-02-02  1738  	cell = nvmem_cell_get(svsp->dev, nvmem_cell_name);
43819e38533066 AngeloGioacchino Del Regno 2022-08-25  1739  	if (IS_ERR_OR_NULL(cell)) {
9f195f3a1e696b Roger Lu                   2023-02-02 @1740  		dev_err(svsp->dev, "no \"%s\"? %ld\n",
9f195f3a1e696b Roger Lu                   2023-02-02  1741  			nvmem_cell_name, PTR_ERR(cell));
43819e38533066 AngeloGioacchino Del Regno 2022-08-25  1742  		return PTR_ERR(cell);

I guess this warning is showing up as new because you renamed the svs_get_efuse_data() function.

The bug is that if nvmem_cell_get() returns NULL then the return is not handled correctly. But nvmem_cell_get() never returns NULL. So it's bad code, but in run time the bug is impossible to hit.

43819e38533066 AngeloGioacchino Del Regno 2022-08-25  1743  	}
43819e38533066 AngeloGioacchino Del Regno 2022-08-25  1744  
9f195f3a1e696b Roger Lu                   2023-02-02  1745  	*svsp_efuse = nvmem_cell_read(cell, svsp_efuse_max);
9f195f3a1e696b Roger Lu                   2023-02-02  1746  	if (IS_ERR(*svsp_efuse)) {
9f195f3a1e696b Roger Lu                   2023-02-02  1747  		dev_err(svsp->dev, "cannot read \"%s\" efuse: %ld\n",
9f195f3a1e696b Roger Lu                   2023-02-02  1748  			nvmem_cell_name, PTR_ERR(*svsp_efuse));
43819e38533066 AngeloGioacchino Del Regno 2022-08-25  1749  		nvmem_cell_put(cell);
9f195f3a1e696b Roger Lu                   2023-02-02  1750  		return PTR_ERR(*svsp_efuse);
43819e38533066 AngeloGioacchino Del Regno 2022-08-25  1751  	}
43819e38533066 AngeloGioacchino Del Regno 2022-08-25  1752  
9f195f3a1e696b Roger Lu                   2023-02-02  1753  	*svsp_efuse_max /= sizeof(u32);
43819e38533066 AngeloGioacchino Del Regno 2022-08-25  1754  	nvmem_cell_put(cell);
43819e38533066 AngeloGioacchino Del Regno 2022-08-25  1755  
43819e38533066 AngeloGioacchino Del Regno 2022-08-25  1756  	return 0;
43819e38533066 AngeloGioacchino Del Regno 2022-08-25  1757  }
Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests