On Wed, May 17, 2023 at 06:55:37AM +0000, Harshit Mogalapalli wrote: > Hi, > > When running kchecker(with spammy) on drivers/staging/media/imx/imx8mq-mipi-csi2.c > > I see a smatch warning like this: > > CC [M] drivers/staging/media/imx/imx8mq-mipi-csi2.o > CHECK drivers/staging/media/imx/imx8mq-mipi-csi2.c > ./include/linux/err.h:41 IS_ERR_OR_NULL() warn: 'ptr' could be an error pointer > > ^^^ Shouldn't warnings generally link the line number in the same file(drivers/staging/media/imx/imx8mq-mipi-csi2.c) instead? Warning about inline functions is a tricky thing... A different idea is to just silence that warning. That check has two warnings for if (!p) vs if (IS_ERR(p)). The default is to warn if p can be an error pointer and can't be NULL. The --spammy option warns if p can be an error pointer regardless of whether or not it can be NULL. I re-wrote a lot of this stuff because of some recent bugs that were discussed on LKML. Unfortunately, I never actually published it. I have pushed it now. While I was cleaning it up for publishing, I noticed that I hadn't dealt with the for_each_gpio_desc_with_flag() macro that was included in the kernel.ignore_bogus_null_checks file. So I added that. It's disappointing that that the smatch_comparison.c code doesn't handle this automatically... :( Also the other thing that I'm remembering now is that sometimes code does this: ptr = driver->get_ptr(); if (!ptr) ptr = -EIO; if (IS_ERR(ptr)) return PTR_ERR(ptr); What the code is doing here is that the subsystem maintainer does not trust driver authors to remember to return error pointers so they work around driver bugs by changing NULL to an error pointer. This is intentional (and probably a good idea). I had intended to make a list of untrusted "(struct driver)->get_ptr" functions and silence those false positives. Anway, I've attached that list. It's mostly garbage dead debugfs that people refuse to delete. I have had two subsystems refuse to accept delete patches for this old dead code. I didn't re-write the --spammy code. I should. The other temptation is to just delete the second check. One thing about that check is that it prints warnings about passed in error pointers, but the smatch_err_ptr.c code assumes no one will pass error pointers or it relies on the smatch_dereference.c code to print a warning in the caller. This check has 285 warnings on my .config: One thing about the check is that it does find bugs: drivers/block/drbd/drbd_nl.c:3361 drbd_adm_dump_devices() warn: 'resource_filter' could be an error pointer Maybe I should modify this warning to only warn if it checks for NULL but doesn't check for error pointers. That would silence the IS_ERR_OR_NULL() warning. I tried a different heuristic which also found this bug: drivers/block/drbd/drbd_nl.c:3363 drbd_adm_dump_devices() warn: passing error pointer 'resource_filter' to nla_data() But that check has over 2k warnings so it doesn't work at all. Passing error pointers is expected in debugfs. Also passing error pointer foo->bar to kfree(foo) is fine. The other problem is that Smatch doesn't see the dereference in: drbd_find_resource(nla_data(resource_filter)) I should hard code into smatch_dereference.c that nla_data() always dereferences $0. regards, dan carpenter
drivers/usb/host/max3421-hcd.c:1913 max3421_probe() warn: 'max3421_hcd->spi_thread' is an error pointer or valid drivers/mtd/ubi/debug.c:228 ubi_debugfs_init() warn: 'dfs_rootdir' is an error pointer or valid drivers/i2c/busses/i2c-imx.c:1392 i2c_imx_init_recovery_info() warn: 'i2c_imx->pinctrl' is an error pointer or valid drivers/i2c/busses/i2c-at91-master.c:835 at91_init_twi_recovery_gpio() warn: 'rinfo->pinctrl' is an error pointer or valid drivers/i2c/busses/i2c-gpio.c:268 i2c_gpio_fault_injector_init() warn: 'i2c_gpio_debug_dir' is an error pointer or valid drivers/i2c/busses/i2c-gpio.c:273 i2c_gpio_fault_injector_init() warn: 'priv->debug_dir' is an error pointer or valid drivers/hwmon/pmbus/adm1266.c:343 adm1266_init_debugfs() warn: 'data->debugfs_dir' is an error pointer or valid drivers/hwmon/pmbus/ucd9000.c:515 ucd9000_init_debugfs() warn: 'data->debugfs' is an error pointer or valid drivers/iommu/tegra-smmu.c:1059 tegra_smmu_debugfs_init() warn: 'smmu->debugfs' is an error pointer or valid drivers/edac/xgene_edac.c:872 xgene_edac_pmd_create_debugfs_nodes() warn: 'dbgfs_dir' is an error pointer or valid drivers/edac/xgene_edac.c:1176 xgene_edac_l3_create_debugfs_nodes() warn: 'dbgfs_dir' is an error pointer or valid drivers/edac/thunderx_edac.c:484 thunderx_create_debugfs_nodes() warn: 'ent' is an error pointer or valid drivers/platform/chrome/wilco_ec/core.c:130 wilco_ec_probe() warn: 'ec->debugfs_pdev' is an error pointer or valid drivers/clk/clk-sp7021.c:607 sp7021_clk_probe() warn: 'clk_base' is an error pointer or valid drivers/clk/clk-sp7021.c:610 sp7021_clk_probe() warn: 'pll_base' is an error pointer or valid drivers/clk/clk-sp7021.c:613 sp7021_clk_probe() warn: 'sys_base' is an error pointer or valid drivers/block/aoe/aoecmd.c:1259 aoe_ktstart() warn: 'task' is an error pointer or valid drivers/block/pktcdvd.c:454 pkt_debugfs_dev_new() warn: 'pd->dfs_d_root' is an error pointer or valid drivers/ras/debugfs.c:49 ras_add_daemon_trace() warn: 'fentry' is an error pointer or valid drivers/target/target_core_fabric_configfs.c:482 target_fabric_make_np() warn: 'se_tpg_np' is an error pointer or valid drivers/ntb/test/ntb_tool.c:1498 tool_setup_dbgfs() warn: 'tc->dbgfs_dir' is an error pointer or valid drivers/ntb/test/ntb_perf.c:1358 perf_setup_dbgfs() warn: 'perf->dbgfs_dir' is an error pointer or valid drivers/thermal/mediatek/lvts_thermal.c:191 lvts_debugfs_init() warn: 'lvts_td->dom_dentry' is an error pointer or valid drivers/thermal/mediatek/lvts_thermal.c:200 lvts_debugfs_init() warn: 'dentry' is an error pointer or valid drivers/spi/spi-dw-core.c:66 dw_spi_debugfs_init() warn: 'dws->debugfs' is an error pointer or valid drivers/spi/spi-hisi-kunpeng.c:172 hisi_spi_debugfs_init() warn: 'hs->debugfs' is an error pointer or valid drivers/gpu/drm/msm/adreno/a5xx_gpu.c:92 a5xx_submit_in_rb() warn: 'ptr' is an error pointer or valid drivers/nvme/host/fault_inject.c:30 nvme_fault_inject_init() warn: 'parent' is an error pointer or valid drivers/regulator/core.c:5259 rdev_init_debugfs() warn: 'rdev->debugfs' is an error pointer or valid drivers/regulator/core.c:6181 regulator_init() warn: 'debugfs_root' is an error pointer or valid drivers/hid/hid-wiimote-debug.c:186 wiidebug_init() warn: 'dbg->eeprom' is an error pointer or valid drivers/hid/hid-wiimote-debug.c:191 wiidebug_init() warn: 'dbg->drm' is an error pointer or valid drivers/dma/xilinx/xdma.c:895 xdma_probe() warn: 'reg_base' is an error pointer or valid drivers/media/i2c/rdacm20.c:641 rdacm20_probe() warn: 'dev->sensor' is an error pointer or valid drivers/media/platform/aspeed/aspeed-video.c:1979 aspeed_video_debugfs_create() warn: 'debugfs_entry' is an error pointer or valid drivers/media/platform/aspeed/aspeed-video.c:1982 aspeed_video_debugfs_create() warn: 'debugfs_entry' is an error pointer or valid drivers/media/common/siano/smsdvb-debugfs.c:472 smsdvb_debugfs_create() warn: 'd' is an error pointer or valid drivers/media/v4l2-core/v4l2-fwnode.c:1241 v4l2_fwnode_reference_parse_int_props() warn: 'fwnode' is an error pointer or valid drivers/scsi/lpfc/lpfc_debugfs.c:6072 lpfc_debugfs_initialize() warn: 'phba->debug_multixri_pools' is an error pointer or valid drivers/scsi/lpfc/lpfc_debugfs.c:6084 lpfc_debugfs_initialize() warn: 'phba->debug_cgn_buffer' is an error pointer or valid drivers/scsi/lpfc/lpfc_debugfs.c:6097 lpfc_debugfs_initialize() warn: 'phba->debug_rx_monitor' is an error pointer or valid drivers/scsi/lpfc/lpfc_debugfs.c:6110 lpfc_debugfs_initialize() warn: 'phba->debug_ras_log' is an error pointer or valid drivers/scsi/lpfc/lpfc_debugfs.c:6357 lpfc_debugfs_initialize() warn: 'vport->debug_scsistat' is an error pointer or valid drivers/scsi/lpfc/lpfc_debugfs.c:6368 lpfc_debugfs_initialize() warn: 'vport->debug_ioktime' is an error pointer or valid drivers/scsi/mpt3sas/mpt3sas_debugfs.c:102 mpt3sas_init_debugfs() warn: 'mpt3sas_debugfs_root' is an error pointer or valid drivers/scsi/mpt3sas/mpt3sas_debugfs.c:127 mpt3sas_setup_debugfs() warn: 'ioc->debugfs_root' is an error pointer or valid drivers/scsi/mpt3sas/mpt3sas_debugfs.c:137 mpt3sas_setup_debugfs() warn: 'ioc->ioc_dump' is an error pointer or valid drivers/scsi/qla2xxx/qla_dfs.c:119 qla2x00_dfs_create_rport() warn: 'fp->dfs_rport_dir' is an error pointer or valid drivers/scsi/qla2xxx/qla_dfs.c:701 qla2x00_dfs_setup() warn: 'ha->tgt.dfs_naqp' is an error pointer or valid drivers/scsi/qla2xxx/qla_dfs.c:708 qla2x00_dfs_setup() warn: 'vha->dfs_rport_root' is an error pointer or valid drivers/scsi/megaraid/megaraid_sas_debugfs.c:105 megasas_init_debugfs() warn: 'megasas_debugfs_root' is an error pointer or valid drivers/scsi/megaraid/megaraid_sas_debugfs.c:135 megasas_setup_debugfs() warn: 'instance->debugfs_root' is an error pointer or valid drivers/scsi/megaraid/megaraid_sas_debugfs.c:147 megasas_setup_debugfs() warn: 'instance->raidmap_dump' is an error pointer or valid drivers/mmc/core/block.c:2916 mmc_blk_add_debugfs() warn: 'md->status_dentry' is an error pointer or valid drivers/mmc/core/block.c:2924 mmc_blk_add_debugfs() warn: 'md->ext_csd_dentry' is an error pointer or valid drivers/nfc/nfcsim.c:340 nfcsim_debugfs_init() warn: 'nfcsim_debugfs_root' is an error pointer or valid drivers/net/wireless/ath/ath5k/debug.c:985 ath5k_debug_init_device() warn: 'phydir' is an error pointer or valid drivers/net/wireless/ath/ath9k/htc_drv_debug.c:494 ath9k_htc_init_debug() warn: 'priv->debug.debugfs_phy' is an error pointer or valid drivers/net/wireless/ath/ath9k/debug.c:1423 ath9k_init_debug() warn: 'sc->debug.debugfs_phy' is an error pointer or valid drivers/net/wireless/ath/ath6kl/debug.c:1796 ath6kl_debug_init_fs() warn: 'ar->debugfs_phy' is an error pointer or valid drivers/net/wireless/ath/ath11k/spectral.c:954 ath11k_spectral_debug_register() warn: 'ar->spectral.scan_ctl' is an error pointer or valid drivers/net/wireless/ath/ath11k/spectral.c:965 ath11k_spectral_debug_register() warn: 'ar->spectral.scan_count' is an error pointer or valid drivers/net/wireless/ath/ath11k/spectral.c:976 ath11k_spectral_debug_register() warn: 'ar->spectral.scan_bins' is an error pointer or valid drivers/net/wireless/marvell/mwifiex/debugfs.c:962 mwifiex_dev_debugfs_init() warn: 'priv->dfs_dev_dir' is an error pointer or valid drivers/net/wireless/mediatek/mt76/mt7615/debugfs.c:553 mt7615_init_debugfs() warn: 'dir' is an error pointer or valid drivers/net/wireless/mediatek/mt76/debugfs.c:112 mt76_register_debugfs_fops() warn: 'dir' is an error pointer or valid drivers/net/wireless/mediatek/mt76/mt7996/debugfs.c:788 mt7996_init_debugfs() warn: 'dir' is an error pointer or valid drivers/net/wireless/mediatek/mt76/mt7921/debugfs.c:433 mt7921_init_debugfs() warn: 'dir' is an error pointer or valid drivers/net/wireless/mediatek/mt76/mt7603/debugfs.c:101 mt7603_init_debugfs() warn: 'dir' is an error pointer or valid drivers/net/wireless/mediatek/mt76/mt7915/debugfs.c:1221 mt7915_init_debugfs() warn: 'dir' is an error pointer or valid drivers/net/wireless/mediatek/mt76/mt76x02_debugfs.c:137 mt76x02_init_debugfs() warn: 'dir' is an error pointer or valid drivers/net/ethernet/broadcom/genet/bcmmii.c:615 bcmgenet_mii_pd_init() warn: 'phydev' is an error pointer or valid drivers/net/ethernet/broadcom/bgmac.c:1451 bgmac_phy_connect_direct() warn: 'phy_dev' is an error pointer or valid drivers/net/ethernet/brocade/bna/bnad_debugfs.c:503 bnad_debugfs_init() warn: 'bna_debugfs_root' is an error pointer or valid drivers/net/ethernet/brocade/bna/bnad_debugfs.c:515 bnad_debugfs_init() warn: 'bnad->port_debugfs_root' is an error pointer or valid drivers/net/ethernet/marvell/octeontx2/nic/otx2_ptp.c:338 otx2_ptp_init() warn: 'ptp_ptr->ptp_clock' is an error pointer or valid drivers/net/ethernet/marvell/mvpp2/mvpp2_debugfs.c:596 mvpp2_dbgfs_c2_entry_init() warn: 'c2_entry_dir' is an error pointer or valid drivers/net/ethernet/marvell/mvpp2/mvpp2_debugfs.c:629 mvpp2_dbgfs_flow_tbl_entry_init() warn: 'flow_tbl_entry_dir' is an error pointer or valid drivers/net/ethernet/marvell/mvpp2/mvpp2_debugfs.c:649 mvpp2_dbgfs_cls_init() warn: 'cls_dir' is an error pointer or valid drivers/net/ethernet/marvell/mvpp2/mvpp2_debugfs.c:653 mvpp2_dbgfs_cls_init() warn: 'c2_dir' is an error pointer or valid drivers/net/ethernet/marvell/mvpp2/mvpp2_debugfs.c:663 mvpp2_dbgfs_cls_init() warn: 'flow_tbl_dir' is an error pointer or valid drivers/net/ethernet/marvell/sky2.c:4532 sky2_debug_init() warn: 'ent' is an error pointer or valid drivers/net/ethernet/ti/am65-cpts.c:1154 am65_cpts_create() warn: 'cpts->ptp_clock' is an error pointer or valid drivers/net/ethernet/microchip/vcap/vcap_api_kunit.c:291 test_vcap_xn_rule_creator() warn: '__right' is an error pointer or valid drivers/net/ethernet/microchip/vcap/vcap_api_kunit.c:1349 vcap_api_encode_rule_test() warn: '__right' is an error pointer or valid drivers/net/ethernet/intel/i40e/i40e_debugfs.c:1842 i40e_dbg_init() warn: 'i40e_dbg_root' is an error pointer or valid drivers/net/ethernet/hisilicon/hns/hns_dsaf_mac.c:708 hns_mac_register_phydev() warn: 'phy' is an error pointer or valid drivers/net/mdio/mdio-xgene.c:268 xgene_enet_phy_register() warn: 'phy_dev' is an error pointer or valid drivers/mailbox/mailbox-test.c:269 mbox_test_add_debugfs() warn: 'tdev->root_debugfs_dir' is an error pointer or valid drivers/gpio/gpiolib-of.c:790 of_gpiochip_remove_hog() warn: 'desc' is an error pointer or valid drivers/gpio/gpiolib-of.c:790 of_gpiochip_remove_hog() warn: 'desc' is an error pointer or valid drivers/gpio/gpiolib-sysfs.c:784 gpiochip_sysfs_unregister() warn: 'desc' is an error pointer or valid drivers/gpio/gpiolib-sysfs.c:784 gpiochip_sysfs_unregister() warn: 'desc' is an error pointer or valid drivers/gpio/gpiolib.c:4260 gpiochip_free_hogs() warn: 'desc' is an error pointer or valid drivers/gpio/gpiolib.c:4260 gpiochip_free_hogs() warn: 'desc' is an error pointer or valid drivers/android/binder.c:6569 binder_init() warn: 'binder_debugfs_dir_entry_root' is an error pointer or valid drivers/base/firmware_loader/main.c:815 fw_log_firmware_info() warn: 'alg' is an error pointer or valid drivers/soc/tegra/pmc.c:1197 tegra_powergate_debugfs_init() warn: 'pmc->debugfs' is an error pointer or valid security/apparmor/domain.c:1184 aa_change_hat() warn: 'new' is an error pointer or valid security/integrity/evm/evm_secfs.c:289 evm_init_xattrs() warn: 'evm_xattrs' is an error pointer or valid security/integrity/evm/evm_secfs.c:306 evm_init_secfs() warn: 'evm_dir' is an error pointer or valid security/integrity/evm/evm_secfs.c:311 evm_init_secfs() warn: 'evm_init_tpm' is an error pointer or valid security/integrity/evm/evm_secfs.c:318 evm_init_secfs() warn: 'evm_symlink' is an error pointer or valid security/keys/trusted-keys/trusted_tee.c:111 trusted_tee_seal() warn: 'reg_shm_out' is an error pointer or valid security/keys/trusted-keys/trusted_tee.c:170 trusted_tee_unseal() warn: 'reg_shm_out' is an error pointer or valid fs/9p/fid.h:30 v9fs_fid_clone() warn: 'fid' is an error pointer or valid fs/9p/fid.h:30 v9fs_fid_clone() warn: 'fid' is an error pointer or valid fs/configfs/dir.c:1339 configfs_mkdir() warn: 'item' is an error pointer or valid fs/ceph/cache.c:100 ceph_fscache_register_fs() warn: 'fsc->fscache' is an error pointer or valid fs/erofs/fscache.c:354 erofs_fscache_register_volume() warn: 'volume' is an error pointer or valid fs/nfsd/nfs4proc.c:377 nfsd4_create_file() warn: 'child' is an error pointer or valid fs/nfsd/nfs3proc.c:347 nfsd3_create_file() warn: 'child' is an error pointer or valid fs/overlayfs/readdir.c:906 ovl_dir_fsync() warn: 'realfile' is an error pointer or valid fs/pstore/zone.c:1222 psz_init_zones() warn: 'zone' is an error pointer or valid kernel/locking/lock_events.c:149 init_lockevent_counts() warn: 'd_counts' is an error pointer or valid kernel/cgroup/cgroup.c:5555 css_create() warn: 'css' is an error pointer or valid sound/soc/apple/mca.c:955 mca_pcm_new() warn: 'chan' is an error pointer or valid sound/soc/apple/mca.c:961 mca_pcm_new() warn: 'chan' is an error pointer or valid net/bluetooth/aosp.c:58 aosp_do_open() warn: 'skb' is an error pointer or valid net/bluetooth/aosp.c:159 enable_quality_report() warn: 'skb' is an error pointer or valid net/bluetooth/aosp.c:181 disable_quality_report() warn: 'skb' is an error pointer or valid net/bluetooth/msft.c:124 read_supported_features() warn: 'skb' is an error pointer or valid net/bluetooth/msft.c:326 msft_remove_monitor_sync() warn: 'skb' is an error pointer or valid net/bluetooth/msft.c:442 msft_add_monitor_sync() warn: 'skb' is an error pointer or valid lib/test_hmm.c:559 dmirror_allocate_chunk() warn: 'ptr' is an error pointer or valid lib/test_kmod.c:320 try_one_request() warn: 'info->task_sync' is an error pointer or valid lib/test_firmware.c:918 trigger_batched_requests_store() warn: 'req->task' is an error pointer or valid lib/notifier-error-inject.c:86 err_inject_init() warn: 'notifier_err_inject_dir' is an error pointer or valid lib/error-inject.c:220 ei_debugfs_init() warn: 'dir' is an error pointer or valid lib/error-inject.c:224 ei_debugfs_init() warn: 'file' is an error pointer or valid mm/frontswap.c:266 init_frontswap() warn: 'root' is an error pointer or valid mm/shrinker_debug.c:133 shrinker_debugfs_scan_write() warn: 'memcg' is an error pointer or valid