drivers/gpu/drm/amd/amdgpu/../display/amdgpu_dm/amdgpu_dm_debugfs.c:2721 crc_win_update_set() error: we previously assumed 'crc_rd_wrk' could be null (see line 2700)

From: Dan Carpenter
Date: Mon Nov 22 2021 - 05:30:05 EST


tree: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master
head: a90af8f15bdc9449ee2d24e1d73fa3f7e8633f81
commit: 9a65df19310859bbc185a4bb8ed45fe1479bd8f2 drm/amd/display: Use PSP TA to read out crc
config: x86_64-randconfig-m001-20211103 (attached as .config)
compiler: gcc-9 (Debian 9.3.0-22) 9.3.0

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@xxxxxxxxx>
Reported-by: Dan Carpenter <dan.carpenter@xxxxxxxxxx>

New smatch warnings:
drivers/gpu/drm/amd/amdgpu/../display/amdgpu_dm/amdgpu_dm_debugfs.c:2721 crc_win_update_set() error: we previously assumed 'crc_rd_wrk' could be null (see line 2700)

Old smatch warnings:
drivers/gpu/drm/amd/amdgpu/../display/amdgpu_dm/amdgpu_dm_debugfs.c:1190 dp_dsc_clock_en_read() warn: inconsistent indenting
drivers/gpu/drm/amd/amdgpu/../display/amdgpu_dm/amdgpu_dm_debugfs.c:1204 dp_dsc_clock_en_read() error: snprintf() is printing too much 30 vs 10
drivers/gpu/drm/amd/amdgpu/../display/amdgpu_dm/amdgpu_dm_debugfs.c:1292 dp_dsc_clock_en_write() warn: inconsistent indenting
drivers/gpu/drm/amd/amdgpu/../display/amdgpu_dm/amdgpu_dm_debugfs.c:1377 dp_dsc_slice_width_read() warn: inconsistent indenting
drivers/gpu/drm/amd/amdgpu/../display/amdgpu_dm/amdgpu_dm_debugfs.c:1477 dp_dsc_slice_width_write() warn: inconsistent indenting
drivers/gpu/drm/amd/amdgpu/../display/amdgpu_dm/amdgpu_dm_debugfs.c:1562 dp_dsc_slice_height_read() warn: inconsistent indenting
drivers/gpu/drm/amd/amdgpu/../display/amdgpu_dm/amdgpu_dm_debugfs.c:1662 dp_dsc_slice_height_write() warn: inconsistent indenting
drivers/gpu/drm/amd/amdgpu/../display/amdgpu_dm/amdgpu_dm_debugfs.c:1743 dp_dsc_bits_per_pixel_read() warn: inconsistent indenting
drivers/gpu/drm/amd/amdgpu/../display/amdgpu_dm/amdgpu_dm_debugfs.c:1840 dp_dsc_bits_per_pixel_write() warn: inconsistent indenting
drivers/gpu/drm/amd/amdgpu/../display/amdgpu_dm/amdgpu_dm_debugfs.c:1919 dp_dsc_pic_width_read() warn: inconsistent indenting
drivers/gpu/drm/amd/amdgpu/../display/amdgpu_dm/amdgpu_dm_debugfs.c:1976 dp_dsc_pic_height_read() warn: inconsistent indenting
drivers/gpu/drm/amd/amdgpu/../display/amdgpu_dm/amdgpu_dm_debugfs.c:2048 dp_dsc_chunk_size_read() warn: inconsistent indenting
drivers/gpu/drm/amd/amdgpu/../display/amdgpu_dm/amdgpu_dm_debugfs.c:2120 dp_dsc_slice_bpg_offset_read() warn: inconsistent indenting

vim +/crc_rd_wrk +2721 drivers/gpu/drm/amd/amdgpu/../display/amdgpu_dm/amdgpu_dm_debugfs.c

86bc221918925a Wayne Lin 2021-03-02 2689 static int crc_win_update_set(void *data, u64 val)
86bc221918925a Wayne Lin 2021-03-02 2690 {
9a65df19310859 Wayne Lin 2021-03-02 2691 struct drm_crtc *new_crtc = data;
9a65df19310859 Wayne Lin 2021-03-02 2692 struct drm_crtc *old_crtc = NULL;
9a65df19310859 Wayne Lin 2021-03-02 2693 struct amdgpu_crtc *new_acrtc, *old_acrtc;
9a65df19310859 Wayne Lin 2021-03-02 2694 struct amdgpu_device *adev = drm_to_adev(new_crtc->dev);
9a65df19310859 Wayne Lin 2021-03-02 2695 struct crc_rd_work *crc_rd_wrk = adev->dm.crc_rd_wrk;
86bc221918925a Wayne Lin 2021-03-02 2696
86bc221918925a Wayne Lin 2021-03-02 2697 if (val) {
9a65df19310859 Wayne Lin 2021-03-02 2698 spin_lock_irq(&crc_rd_wrk->crc_rd_work_lock);
9a65df19310859 Wayne Lin 2021-03-02 2699 spin_lock_irq(&adev_to_drm(adev)->event_lock);
9a65df19310859 Wayne Lin 2021-03-02 @2700 if (crc_rd_wrk && crc_rd_wrk->crtc) {
^^^^^^^^^^
This code assumes that "crc_rd_wrk" can be NULL

9a65df19310859 Wayne Lin 2021-03-02 2701 old_crtc = crc_rd_wrk->crtc;
9a65df19310859 Wayne Lin 2021-03-02 2702 old_acrtc = to_amdgpu_crtc(old_crtc);
9a65df19310859 Wayne Lin 2021-03-02 2703 flush_work(&adev->dm.crc_rd_wrk->notify_ta_work);
9a65df19310859 Wayne Lin 2021-03-02 2704 }
9a65df19310859 Wayne Lin 2021-03-02 2705
9a65df19310859 Wayne Lin 2021-03-02 2706 new_acrtc = to_amdgpu_crtc(new_crtc);
9a65df19310859 Wayne Lin 2021-03-02 2707
9a65df19310859 Wayne Lin 2021-03-02 2708 if (old_crtc && old_crtc != new_crtc) {
9a65df19310859 Wayne Lin 2021-03-02 2709 old_acrtc->dm_irq_params.crc_window.activated = false;
9a65df19310859 Wayne Lin 2021-03-02 2710 old_acrtc->dm_irq_params.crc_window.update_win = false;
9a65df19310859 Wayne Lin 2021-03-02 2711 old_acrtc->dm_irq_params.crc_window.skip_frame_cnt = 0;
9a65df19310859 Wayne Lin 2021-03-02 2712
9a65df19310859 Wayne Lin 2021-03-02 2713 new_acrtc->dm_irq_params.crc_window.activated = true;
9a65df19310859 Wayne Lin 2021-03-02 2714 new_acrtc->dm_irq_params.crc_window.update_win = true;
9a65df19310859 Wayne Lin 2021-03-02 2715 new_acrtc->dm_irq_params.crc_window.skip_frame_cnt = 0;
9a65df19310859 Wayne Lin 2021-03-02 2716 crc_rd_wrk->crtc = new_crtc;
^^^^^^^^^^^^^^^^

9a65df19310859 Wayne Lin 2021-03-02 2717 } else {
9a65df19310859 Wayne Lin 2021-03-02 2718 new_acrtc->dm_irq_params.crc_window.activated = true;
9a65df19310859 Wayne Lin 2021-03-02 2719 new_acrtc->dm_irq_params.crc_window.update_win = true;
9a65df19310859 Wayne Lin 2021-03-02 2720 new_acrtc->dm_irq_params.crc_window.skip_frame_cnt = 0;
9a65df19310859 Wayne Lin 2021-03-02 @2721 crc_rd_wrk->crtc = new_crtc;
^^^^^^^^^^^^^^^^
But the rest of the function assumes it cannot.

9a65df19310859 Wayne Lin 2021-03-02 2722 }
9a65df19310859 Wayne Lin 2021-03-02 2723 spin_unlock_irq(&adev_to_drm(adev)->event_lock);
9a65df19310859 Wayne Lin 2021-03-02 2724 spin_unlock_irq(&crc_rd_wrk->crc_rd_work_lock);
86bc221918925a Wayne Lin 2021-03-02 2725 }
86bc221918925a Wayne Lin 2021-03-02 2726
86bc221918925a Wayne Lin 2021-03-02 2727 return 0;
86bc221918925a Wayne Lin 2021-03-02 2728 }

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@xxxxxxxxxxxx