On Tue, Apr 04, 2023 at 03:20:44PM +0800, Dongliang Mu wrote: > 3. I added a paired function - request_firmware vs release_firmware > with the following. Is this patch fine to check the unmatch state? > > diff --git a/check_unwind.c b/check_unwind.c > index f689181b..830dcfc7 100644 > --- a/check_unwind.c > +++ b/check_unwind.c > @@ -94,6 +94,9 @@ static struct ref_func_info func_table[] = { > > { "ieee80211_alloc_hw", ALLOC, -1, "$", &valid_ptr_min_sval, > &valid_ptr_max_sval }, > { "ieee80211_free_hw", RELEASE, 0, "$" }, > + > + { "request_firmware", ALLOC, 0, "$", &int_zero, &int_zero}, It should be "*$" instead of "$". > + { "release_firmware", RELEASE, 0, "$"} > }; I had some result for that but when I looked through them I saw some false positives and fixed those bugs. Here are the results: False positives: drivers/crypto/qat/qat_common/adf_accel_engine.c:105 adf_ae_fw_load() warn: 'loader_data->mmp_fw' from request_firmware() not released on lines: 91,105. Smatch isn't connecting adf_ae_fw_release() to the correct firmware. drivers/net/wireless/st/cw1200/sta.c:1161 cw1200_setup_mac() warn: 'priv->sdd' from request_firmware() not released on lines: 1156. Firmware isn't supposed to be released on error. drivers/net/wireless/intersil/orinoco/fw.c:329 symbol_dl_firmware() warn: 'fw_entry' from request_firmware() not released on lines: 310,316,329. drivers/net/wireless/intersil/orinoco/fw.c:329 symbol_dl_firmware() warn: 'fw_entry' from request_firmware() not released on lines: 329. drivers/net/wireless/intersil/p54/p54spi.c:171 p54spi_request_firmware() warn: 'priv->firmware' from request_firmware() not released on lines: 168. Smatch gets confused by orinoco_cached_fw_get(). drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c:2166 qlcnic_83xx_run_post() warn: 'fw_info->fw' from request_firmware() not released on lines: 2106,2132,2166. The firmware is released in qlcnic_83xx_copy_fw_file() but smatch isn't able to connect adapter->ahw->fw_info->fw to &fw_info->fw properly. This is a feature that needs to be added to smatch_ssa.c. It's not super complicated to do, but it's not a one liner either. drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c:2187 qlcnic_83xx_load_fw_image_from_host() warn: 'fw_info->fw' from request_firmware() not released on lines: 2182. I can't promise that the others are not false positives as well. This is just to give you an idea. regards, dan carpenter
drivers/staging/rtl8192u/r819xU_firmware.c:335 init_firmware() warn: 'fw_entry' from request_firmware() not released on lines: 335. drivers/gpu/drm/radeon/ni.c:835 ni_init_microcode() warn: 'rdev->smc_fw' from request_firmware() not released on lines: 835. drivers/gpu/drm/radeon/radeon_uvd.c:227 radeon_uvd_init() warn: 'rdev->uvd_fw' from request_firmware() not released on lines: 151,194,201,210. drivers/gpu/drm/radeon/radeon_uvd.c:227 radeon_uvd_init() warn: 'rdev->uvd_fw' from request_firmware() not released on lines: 194,201,210. drivers/gpu/drm/radeon/radeon_vce.c:170 radeon_vce_init() warn: 'rdev->vce_fw' from request_firmware() not released on lines: 103,107,118,122,133,146,153,162. drivers/gpu/drm/amd/amdgpu/amdgpu_ucode.c:1329 amdgpu_ucode_request() warn: '*fw' from request_firmware() not released on lines: 1329. drivers/gpu/drm/amd/amdgpu/amdgpu_device.c:1352 amdgpu_device_need_post() warn: 'adev->pm.fw' from request_firmware() not released on lines: 1335. drivers/media/usb/dvb-usb/dib0700_devices.c:2415 stk9090m_frontend_attach() warn: 'state->frontend_firmware' from request_firmware() not released on lines: 2415. drivers/media/usb/dvb-usb/dib0700_devices.c:2497 nim9090md_frontend_attach() warn: 'state->frontend_firmware' from request_firmware() not released on lines: 2489,2497. drivers/media/tuners/xc5000.c:1213 xc_load_fw_and_init_tuner() warn: 'fw' from request_firmware() not released on lines: 1213. drivers/bluetooth/hci_ll.c:587 download_firmware() warn: 'fw' from request_firmware() not released on lines: 544. drivers/crypto/qat/qat_common/adf_accel_engine.c:105 adf_ae_fw_load() warn: 'loader_data->mmp_fw' from request_firmware() not released on lines: 91,105. drivers/crypto/qat/qat_common/adf_accel_engine.c:105 adf_ae_fw_load() warn: 'loader_data->uof_fw' from request_firmware() not released on lines: 91,105. drivers/net/wireless/broadcom/b43legacy/main.c:1554 do_request_fw() warn: '*fw' from request_firmware() not released on lines: 1554. drivers/net/wireless/ath/wcn36xx/smd.c:569 wcn36xx_smd_load_nv() warn: 'wcn->nv' from request_firmware() not released on lines: 569. drivers/net/wireless/marvell/libertas_tf/if_usb.c:901 if_usb_prog_firmware() warn: 'cardp->fw' from request_firmware() not released on lines: 858. drivers/net/wireless/st/cw1200/sta.c:1161 cw1200_setup_mac() warn: 'priv->sdd' from request_firmware() not released on lines: 1156. drivers/net/wireless/intersil/orinoco/fw.c:329 symbol_dl_firmware() warn: 'fw_entry' from request_firmware() not released on lines: 310,316,329. drivers/net/wireless/intersil/orinoco/fw.c:329 symbol_dl_firmware() warn: 'fw_entry' from request_firmware() not released on lines: 329. drivers/net/wireless/intersil/p54/p54spi.c:171 p54spi_request_firmware() warn: 'priv->firmware' from request_firmware() not released on lines: 168. drivers/net/wireless/intel/ipw2x00/ipw2200.c:3392 ipw_get_fw() warn: '*raw' from request_firmware() not released on lines: 3375,3384. drivers/net/wireless/atmel/at76c50x-usb.c:1673 at76_load_firmware() warn: 'fwe->fw' from request_firmware() not released on lines: 1673. drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c:2166 qlcnic_83xx_run_post() warn: 'fw_info->fw' from request_firmware() not released on lines: 2106,2132,2166. drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c:2187 qlcnic_83xx_load_fw_image_from_host() warn: 'fw_info->fw' from request_firmware() not released on lines: 2182. drivers/misc/ti-st/st_kim.c:417 download_firmware() warn: 'kim_gdata->fw_entry' from request_firmware() not released on lines: 301. sound/pci/ymfpci/ymfpci_main.c:2054 snd_ymfpci_request_firmware() warn: 'chip->controller_microcode' from request_firmware() not released on lines: 2053. sound/pci/ymfpci/ymfpci_main.c:2054 snd_ymfpci_request_firmware() warn: 'chip->dsp_microcode' from request_firmware() not released on lines: 2037,2053. sound/pci/rme9652/hdsp.c:5245 hdsp_request_fw_loader() warn: 'fw' from request_firmware() not released on lines: 5223,5228,5234,5242. sound/pci/riptide/riptide.c:1240 try_to_load_firmware() warn: 'chip->fw_entry' from request_firmware() not released on lines: 1235. sound/soc/sof/loader.c:64 snd_sof_load_firmware_raw() warn: 'sdev->basefw.fw' from request_firmware() not released on lines: 64. sound/soc/intel/skylake/skl-sst-utils.c:410 skl_prepare_lib_load() warn: 'linfo->fw' from request_firmware() not released on lines: 403. sound/soc/intel/skylake/bxt-sst.c:249 bxt_load_base_firmware() warn: 'ctx->fw' from request_firmware() not released on lines: 244.