[bug report] drm/amd/dc: Add dc display driver (v2)

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hello Harry Wentland,

The patch 4562236b3bc0: "drm/amd/dc: Add dc display driver (v2)" from
Sep 12, 2017, leads to the following static checker warning:

	drivers/gpu/drm/amd/amdgpu/../display/dc/core/dc.c:688 construct()
	error: we previously assumed 'dc->current_state' could be null (see line 617)

drivers/gpu/drm/amd/amdgpu/../display/dc/core/dc.c
   519  static void destruct(struct dc *dc)
   520  {
   521          dc_release_state(dc->current_state);
                                 ^^^^^^^^^^^^^^^^^
destruct assumes that dc->current_state is non-NULL

   522          dc->current_state = NULL;
   523  
   524          destroy_links(dc);
   525  
   526          dc_destroy_resource_pool(dc);
   527  
   528          if (dc->ctx->gpio_service)
                    ^^^^^^^

This is also a NULL dereference bug but Smatch does not catch it.

   529                  dal_gpio_service_destroy(&dc->ctx->gpio_service);
   530  
   531          if (dc->ctx->i2caux)
   532                  dal_i2caux_destroy(&dc->ctx->i2caux);
   533  
   534          if (dc->ctx->created_bios)
   535                  dal_bios_parser_destroy(&dc->ctx->dc_bios);
   536  
   537          kfree(dc->ctx);
   538          dc->ctx = NULL;
   539  
   540          kfree(dc->bw_vbios);
   541          dc->bw_vbios = NULL;
   542  
   543          kfree(dc->bw_dceip);
   544          dc->bw_dceip = NULL;
   545  
   546  #ifdef CONFIG_DRM_AMD_DC_DCN1_0
   547          kfree(dc->dcn_soc);
   548          dc->dcn_soc = NULL;
   549  
   550          kfree(dc->dcn_ip);
   551          dc->dcn_ip = NULL;
   552  
   553  #endif
   554  }
   555  
   556  static bool construct(struct dc *dc,
   557                  const struct dc_init_data *init_params)
   558  {
   559          struct dc_context *dc_ctx;
   560          struct bw_calcs_dceip *dc_dceip;
   561          struct bw_calcs_vbios *dc_vbios;
   562  #ifdef CONFIG_DRM_AMD_DC_DCN1_0
   563          struct dcn_soc_bounding_box *dcn_soc;
   564          struct dcn_ip_params *dcn_ip;
   565  #endif
   566  
   567          enum dce_version dc_version = DCE_VERSION_UNKNOWN;
   568  
   569          dc_dceip = kzalloc(sizeof(*dc_dceip), GFP_KERNEL);
   570          if (!dc_dceip) {
   571                  dm_error("%s: failed to create dceip\n", __func__);
   572                  goto fail;
   573          }
   574  
   575          dc->bw_dceip = dc_dceip;
   576  
   577          dc_vbios = kzalloc(sizeof(*dc_vbios), GFP_KERNEL);
   578          if (!dc_vbios) {
   579                  dm_error("%s: failed to create vbios\n", __func__);
   580                  goto fail;
   581          }
   582  
   583          dc->bw_vbios = dc_vbios;
   584  #ifdef CONFIG_DRM_AMD_DC_DCN1_0
   585          dcn_soc = kzalloc(sizeof(*dcn_soc), GFP_KERNEL);
   586          if (!dcn_soc) {
   587                  dm_error("%s: failed to create dcn_soc\n", __func__);
   588                  goto fail;
   589          }
   590  
   591          dc->dcn_soc = dcn_soc;
   592  
   593          dcn_ip = kzalloc(sizeof(*dcn_ip), GFP_KERNEL);
   594          if (!dcn_ip) {
   595                  dm_error("%s: failed to create dcn_ip\n", __func__);
   596                  goto fail;
   597          }
   598  
   599          dc->dcn_ip = dcn_ip;
   600  #endif
   601  
   602          dc_ctx = kzalloc(sizeof(*dc_ctx), GFP_KERNEL);
   603          if (!dc_ctx) {
   604                  dm_error("%s: failed to create ctx\n", __func__);
   605                  goto fail;
   606          }
   607  
   608          dc_ctx->cgs_device = init_params->cgs_device;
   609          dc_ctx->driver_context = init_params->driver;
   610          dc_ctx->dc = dc;
   611          dc_ctx->asic_id = init_params->asic_id;
   612          dc_ctx->dc_sink_id_count = 0;
   613          dc->ctx = dc_ctx;
   614  
   615          dc->current_state = dc_create_state();
   616  
   617          if (!dc->current_state) {
                    ^^^^^^^^^^^^^^^^^^
Check for NULL.

   618                  dm_error("%s: failed to create validate ctx\n", __func__);
   619                  goto fail;
   620          }
   621  
   622          /* Create logger */
   623  
   624          dc_ctx->dce_environment = init_params->dce_environment;
   625  
   626          dc_version = resource_parse_asic_id(init_params->asic_id);
   627          dc_ctx->dce_version = dc_version;
   628  
   629          /* Resource should construct all asic specific resources.
   630           * This should be the only place where we need to parse the asic id
   631           */
   632          if (init_params->vbios_override)
   633                  dc_ctx->dc_bios = init_params->vbios_override;
   634          else {
   635                  /* Create BIOS parser */
   636                  struct bp_init_data bp_init_data;
   637  
   638                  bp_init_data.ctx = dc_ctx;
   639                  bp_init_data.bios = init_params->asic_id.atombios_base_address;
   640  
   641                  dc_ctx->dc_bios = dal_bios_parser_create(
   642                                  &bp_init_data, dc_version);
   643  
   644                  if (!dc_ctx->dc_bios) {
   645                          ASSERT_CRITICAL(false);
   646                          goto fail;
   647                  }
   648  
   649                  dc_ctx->created_bios = true;
   650                  }
   651  
   652          /* Create I2C AUX */
   653          dc_ctx->i2caux = dal_i2caux_create(dc_ctx);
   654  
   655          if (!dc_ctx->i2caux) {
   656                  ASSERT_CRITICAL(false);
   657                  goto fail;
   658          }
   659  
   660          /* Create GPIO service */
   661          dc_ctx->gpio_service = dal_gpio_service_create(
   662                          dc_version,
   663                          dc_ctx->dce_environment,
   664                          dc_ctx);
   665  
   666          if (!dc_ctx->gpio_service) {
   667                  ASSERT_CRITICAL(false);
   668                  goto fail;
   669          }
   670  
   671          dc->res_pool = dc_create_resource_pool(
   672                          dc,
   673                          init_params->num_virtual_links,
   674                          dc_version,
   675                          init_params->asic_id);
   676          if (!dc->res_pool)
   677                  goto fail;
   678  
   679          dc_resource_state_construct(dc, dc->current_state);
   680  
   681          if (!create_links(dc, init_params->num_virtual_links))
   682                  goto fail;
   683  
   684          return true;
   685  
   686  fail:
   687  
   688          destruct(dc);
   689          return false;
   690  }

regards,
dan carpenter
_______________________________________________
amd-gfx mailing list
amd-gfx@xxxxxxxxxxxxxxxxxxxxx
https://lists.freedesktop.org/mailman/listinfo/amd-gfx




[Index of Archives]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux