drivers/gpu/drm/amd/amdgpu/../display/dc/link/link_factory.c:384 construct_phy() warn: variable dereferenced before check 'link->link_enc' (see line 381)

From: Dan Carpenter
Date: Mon May 22 2023 - 02:52:01 EST


tree: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master
head: d635f6cc934bcd467c5d67148ece74632fd96abf
commit: 76f5dc40ebb188b081e03783541856c03e97f8e0 drm/amd/display: move dc_link functions in link root folder to dc_link_exports
config: ia64-randconfig-m041-20230514
compiler: ia64-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 <error27@xxxxxxxxx>
| Closes: https://lore.kernel.org/r/202305201930.FVPVEaPp-lkp@xxxxxxxxx/

smatch warnings:
drivers/gpu/drm/amd/amdgpu/../display/dc/link/link_factory.c:384 construct_phy() warn: variable dereferenced before check 'link->link_enc' (see line 381)

vim +384 drivers/gpu/drm/amd/amdgpu/../display/dc/link/link_factory.c

54618888d1ea7a Wenjing Liu 2023-01-18 367 enc_init_data.ctx = dc_ctx;
54618888d1ea7a Wenjing Liu 2023-01-18 368 bp_funcs->get_src_obj(dc_ctx->dc_bios, link->link_id, 0,
54618888d1ea7a Wenjing Liu 2023-01-18 369 &enc_init_data.encoder);
54618888d1ea7a Wenjing Liu 2023-01-18 370 enc_init_data.connector = link->link_id;
54618888d1ea7a Wenjing Liu 2023-01-18 371 enc_init_data.channel = get_ddc_line(link);
54618888d1ea7a Wenjing Liu 2023-01-18 372 enc_init_data.hpd_source = get_hpd_line(link);
54618888d1ea7a Wenjing Liu 2023-01-18 373
54618888d1ea7a Wenjing Liu 2023-01-18 374 link->hpd_src = enc_init_data.hpd_source;
54618888d1ea7a Wenjing Liu 2023-01-18 375
54618888d1ea7a Wenjing Liu 2023-01-18 376 enc_init_data.transmitter =
54618888d1ea7a Wenjing Liu 2023-01-18 377 translate_encoder_to_transmitter(enc_init_data.encoder);
54618888d1ea7a Wenjing Liu 2023-01-18 378 link->link_enc =
54618888d1ea7a Wenjing Liu 2023-01-18 379 link->dc->res_pool->funcs->link_enc_create(dc_ctx, &enc_init_data);
54618888d1ea7a Wenjing Liu 2023-01-18 380
54618888d1ea7a Wenjing Liu 2023-01-18 @381 DC_LOG_DC("BIOS object table - DP_IS_USB_C: %d", link->link_enc->features.flags.bits.DP_IS_USB_C);
^^^^^^^^^^^^^^^^
Dereference

54618888d1ea7a Wenjing Liu 2023-01-18 382 DC_LOG_DC("BIOS object table - IS_DP2_CAPABLE: %d", link->link_enc->features.flags.bits.IS_DP2_CAPABLE);
^^^^^^^^^^^^^^^^
Here too.

54618888d1ea7a Wenjing Liu 2023-01-18 383
54618888d1ea7a Wenjing Liu 2023-01-18 @384 if (!link->link_enc) {
^^^^^^^^^^^^^^
NULL checked too late.


54618888d1ea7a Wenjing Liu 2023-01-18 385 DC_ERROR("Failed to create link encoder!\n");
54618888d1ea7a Wenjing Liu 2023-01-18 386 goto link_enc_create_fail;
54618888d1ea7a Wenjing Liu 2023-01-18 387 }
54618888d1ea7a Wenjing Liu 2023-01-18 388

--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki