drivers/soc/tegra/cbb/tegra-cbb.c:96 tegra_cbb_err_debugfs_init() warn: passing zero to 'PTR_ERR'

From: Dan Carpenter
Date: Thu Apr 20 2023 - 06:19:40 EST


tree: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master
head: cb0856346a60fe3eb837ba5e73588a41f81ac05f
commit: b7134422146692e096e807751656fc58ee1a717d soc/tegra: cbb: Add CBB 1.0 driver for Tegra194
config: arm64-randconfig-m041-20230419 (https://download.01.org/0day-ci/archive/20230420/202304201719.AnFYgA2p-lkp@xxxxxxxxx/config)
compiler: aarch64-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/202304201719.AnFYgA2p-lkp@xxxxxxxxx/

smatch warnings:
drivers/soc/tegra/cbb/tegra-cbb.c:96 tegra_cbb_err_debugfs_init() warn: passing zero to 'PTR_ERR'

vim +/PTR_ERR +96 drivers/soc/tegra/cbb/tegra-cbb.c

b7134422146692 Sumit Gupta 2022-05-12 88 static int tegra_cbb_err_debugfs_init(struct tegra_cbb *cbb)
b7134422146692 Sumit Gupta 2022-05-12 89 {
b7134422146692 Sumit Gupta 2022-05-12 90 static struct dentry *root;
b7134422146692 Sumit Gupta 2022-05-12 91
b7134422146692 Sumit Gupta 2022-05-12 92 if (!root) {
b7134422146692 Sumit Gupta 2022-05-12 93 root = debugfs_create_file("tegra_cbb_err", 0444, NULL, cbb, &tegra_cbb_err_fops);
b7134422146692 Sumit Gupta 2022-05-12 94 if (IS_ERR_OR_NULL(root)) {
b7134422146692 Sumit Gupta 2022-05-12 95 pr_err("%s(): could not create debugfs node\n", __func__);
b7134422146692 Sumit Gupta 2022-05-12 @96 return PTR_ERR(root);
b7134422146692 Sumit Gupta 2022-05-12 97 }
b7134422146692 Sumit Gupta 2022-05-12 98 }
b7134422146692 Sumit Gupta 2022-05-12 99
b7134422146692 Sumit Gupta 2022-05-12 100 return 0;

Debugfs stopped returning NULL years ago. Debugfs is weird, it's not
supposed to be checked for errors. So the correct way to write this
is:

static void tegra_cbb_err_debugfs_init(struct tegra_cbb *cbb)
{
static struct dentry *root;

if (!root)
root = debugfs_create_file("tegra_cbb_err", 0444, NULL, cbb, &tegra_cbb_err_fops);
}

regards,
dan carpenter

b7134422146692 Sumit Gupta 2022-05-12 101 }

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