drivers/gpu/drm/msm/disp/dpu1/dpu_hw_catalog.c:1948 dpu_hw_catalog_init() warn: possible memory leak of 'dpu_cfg'

From: Dan Carpenter
Date: Mon Aug 22 2022 - 04:29:44 EST


tree: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master
head: 15b3f48a4339e3c16acf18624e2b7f60bc5e9a2c
commit: de7d480f5e8ca6eace02a725abdadb9ea13294ef drm/msm/dpu: make dpu hardware catalog static const
config: microblaze-randconfig-m041-20220820 (https://download.01.org/0day-ci/archive/20220821/202208211344.YIwVJkR3-lkp@xxxxxxxxx/config)
compiler: microblaze-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 <dan.carpenter@xxxxxxxxxx>

New smatch warnings:
drivers/gpu/drm/msm/disp/dpu1/dpu_hw_catalog.c:1948 dpu_hw_catalog_init() warn: possible memory leak of 'dpu_cfg'

Old smatch warnings:
drivers/gpu/drm/msm/disp/dpu1/dpu_hw_catalog.c:1953 dpu_hw_catalog_init() warn: possible memory leak of 'dpu_cfg'

vim +/dpu_cfg +1948 drivers/gpu/drm/msm/disp/dpu1/dpu_hw_catalog.c

de7d480f5e8ca6 Dmitry Baryshkov 2022-06-02 1937 const struct dpu_mdss_cfg *dpu_hw_catalog_init(u32 hw_rev)
25fdd5933e4c0f Jeykumar Sankaran 2018-06-27 1938 {
25fdd5933e4c0f Jeykumar Sankaran 2018-06-27 1939 int i;
25fdd5933e4c0f Jeykumar Sankaran 2018-06-27 1940 struct dpu_mdss_cfg *dpu_cfg;
25fdd5933e4c0f Jeykumar Sankaran 2018-06-27 1941
de7d480f5e8ca6 Dmitry Baryshkov 2022-06-02 1942 dpu_cfg = kzalloc(sizeof(*dpu_cfg), GFP_KERNEL);

This allocation is never used

25fdd5933e4c0f Jeykumar Sankaran 2018-06-27 1943 if (!dpu_cfg)
25fdd5933e4c0f Jeykumar Sankaran 2018-06-27 1944 return ERR_PTR(-ENOMEM);
25fdd5933e4c0f Jeykumar Sankaran 2018-06-27 1945
25fdd5933e4c0f Jeykumar Sankaran 2018-06-27 1946 for (i = 0; i < ARRAY_SIZE(cfg_handler); i++) {
de7d480f5e8ca6 Dmitry Baryshkov 2022-06-02 1947 if (cfg_handler[i].hw_rev == hw_rev)
de7d480f5e8ca6 Dmitry Baryshkov 2022-06-02 @1948 return cfg_handler[i].dpu_cfg;
25fdd5933e4c0f Jeykumar Sankaran 2018-06-27 1949 }
25fdd5933e4c0f Jeykumar Sankaran 2018-06-27 1950
25fdd5933e4c0f Jeykumar Sankaran 2018-06-27 1951 DPU_ERROR("unsupported chipset id:%X\n", hw_rev);
3208496720a180 Dmitry Baryshkov 2022-06-02 1952
25fdd5933e4c0f Jeykumar Sankaran 2018-06-27 1953 return ERR_PTR(-ENODEV);
25fdd5933e4c0f Jeykumar Sankaran 2018-06-27 1954 }

--
0-DAY CI Kernel Test Service
https://01.org/lkp