drivers/gpu/drm/i915/display/intel_ddi.c:4030 intel_ddi_encoder_destroy() warn: variable dereferenced before check 'dig_port' (see line 4022)

From: Dan Carpenter
Date: Tue Sep 28 2021 - 02:28:27 EST


tree: https://github.com/0day-ci/linux/commits/Imre-Deak/drm-i915-tc-Fix-TypeC-connect-disconnect-sequences/20210922-114722
head: b4b1e126eb50a8a27bb1348ad13dae05e299a9ac
commit: 295fc54769b7afb65114732f61b1448c3e693011 drm/i915/tc: Fix TypeC PHY connect/disconnect logic on ADL-P
config: x86_64-randconfig-m001-20210927 (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>

smatch warnings:
drivers/gpu/drm/i915/display/intel_ddi.c:4030 intel_ddi_encoder_destroy() warn: variable dereferenced before check 'dig_port' (see line 4022)

vim +/dig_port +4030 drivers/gpu/drm/i915/display/intel_ddi.c

f6bff60e927b2f drivers/gpu/drm/i915/intel_ddi.c Imre Deak 2018-12-14 4018 static void intel_ddi_encoder_destroy(struct drm_encoder *encoder)
f6bff60e927b2f drivers/gpu/drm/i915/intel_ddi.c Imre Deak 2018-12-14 4019 {
4a300e65b59b66 drivers/gpu/drm/i915/display/intel_ddi.c Imre Deak 2021-05-26 4020 struct drm_i915_private *i915 = to_i915(encoder->dev);
b7d02c3a124d9b drivers/gpu/drm/i915/display/intel_ddi.c Ville Syrjälä 2019-12-04 4021 struct intel_digital_port *dig_port = enc_to_dig_port(to_intel_encoder(encoder));
295fc54769b7af drivers/gpu/drm/i915/display/intel_ddi.c Imre Deak 2021-09-21 @4022 enum phy phy = intel_port_to_phy(i915, dig_port->base.port);
^^^^^^^^^^^^^^^^^^^
Dereference.

f6bff60e927b2f drivers/gpu/drm/i915/intel_ddi.c Imre Deak 2018-12-14 4023
f6bff60e927b2f drivers/gpu/drm/i915/intel_ddi.c Imre Deak 2018-12-14 4024 intel_dp_encoder_flush_work(encoder);
295fc54769b7af drivers/gpu/drm/i915/display/intel_ddi.c Imre Deak 2021-09-21 4025 if (intel_phy_is_tc(i915, phy))
295fc54769b7af drivers/gpu/drm/i915/display/intel_ddi.c Imre Deak 2021-09-21 4026 intel_tc_port_flush_work(dig_port);
4a300e65b59b66 drivers/gpu/drm/i915/display/intel_ddi.c Imre Deak 2021-05-26 4027 intel_display_power_flush_work(i915);
f6bff60e927b2f drivers/gpu/drm/i915/intel_ddi.c Imre Deak 2018-12-14 4028
f6bff60e927b2f drivers/gpu/drm/i915/intel_ddi.c Imre Deak 2018-12-14 4029 drm_encoder_cleanup(encoder);
a6c6eac947d519 drivers/gpu/drm/i915/display/intel_ddi.c Anshuman Gupta 2021-01-11 @4030 if (dig_port)
^^^^^^^^
Checked too late.

a6c6eac947d519 drivers/gpu/drm/i915/display/intel_ddi.c Anshuman Gupta 2021-01-11 4031 kfree(dig_port->hdcp_port_data.streams);
f6bff60e927b2f drivers/gpu/drm/i915/intel_ddi.c Imre Deak 2018-12-14 4032 kfree(dig_port);
f6bff60e927b2f drivers/gpu/drm/i915/intel_ddi.c Imre Deak 2018-12-14 4033 }

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