[lvc-project] [PATCH v2] drm/amd/pm: check return value of amdgpu_irq_add_id()
amdgpu_irq_ad_id() may fail and the irq handlers will not be registered. This patch adds error code check. Found by Linux Verification Center (linuxtesting.org). Signed-off-by: Igor Artemiev --- v2: Free the source as Alexey Khoroshilov suggested. .../drm/amd/pm/powerplay/hwmgr/smu_helper.c | 19 --- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/drivers/gpu/drm/amd/pm/powerplay/hwmgr/smu_helper.c b/drivers/gpu/drm/amd/pm/powerplay/hwmgr/smu_helper.c index 79a566f3564a..109df1039d5c 100644 --- a/drivers/gpu/drm/amd/pm/powerplay/hwmgr/smu_helper.c +++ b/drivers/gpu/drm/amd/pm/powerplay/hwmgr/smu_helper.c @@ -647,28 +647,41 @@ int smu9_register_irq_handlers(struct pp_hwmgr *hwmgr) { struct amdgpu_irq_src *source = kzalloc(sizeof(struct amdgpu_irq_src), GFP_KERNEL); + int ret; if (!source) return -ENOMEM; source->funcs = _irq_funcs; - amdgpu_irq_add_id((struct amdgpu_device *)(hwmgr->adev), + ret = amdgpu_irq_add_id((struct amdgpu_device *)(hwmgr->adev), SOC15_IH_CLIENTID_THM, THM_9_0__SRCID__THM_DIG_THERM_L2H, source); - amdgpu_irq_add_id((struct amdgpu_device *)(hwmgr->adev), + if (ret) + goto err; + + ret = amdgpu_irq_add_id((struct amdgpu_device *)(hwmgr->adev), SOC15_IH_CLIENTID_THM, THM_9_0__SRCID__THM_DIG_THERM_H2L, source); + if (ret) + goto err; /* Register CTF(GPIO_19) interrupt */ - amdgpu_irq_add_id((struct amdgpu_device *)(hwmgr->adev), + ret = amdgpu_irq_add_id((struct amdgpu_device *)(hwmgr->adev), SOC15_IH_CLIENTID_ROM_SMUIO, SMUIO_9_0__SRCID__SMUIO_GPIO19, source); + if (ret) + goto err; return 0; + +err: + kfree(source); + + return ret; } void *smu_atom_get_data_table(void *dev, uint32_t table, uint16_t *size, -- 2.39.2
[lvc-project] [PATCH] drm/amd/pm: check return value of amdgpu_irq_add_id()
amdgpu_irq_ad_id() may fail and the irq handlers will not be registered. This patch adds error code check. Found by Linux Verification Center (linuxtesting.org). Signed-off-by: Igor Artemiev --- .../gpu/drm/amd/pm/powerplay/hwmgr/smu_helper.c| 14 +++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/drivers/gpu/drm/amd/pm/powerplay/hwmgr/smu_helper.c b/drivers/gpu/drm/amd/pm/powerplay/hwmgr/smu_helper.c index 79a566f3564a..9cb965479dd8 100644 --- a/drivers/gpu/drm/amd/pm/powerplay/hwmgr/smu_helper.c +++ b/drivers/gpu/drm/amd/pm/powerplay/hwmgr/smu_helper.c @@ -647,26 +647,34 @@ int smu9_register_irq_handlers(struct pp_hwmgr *hwmgr) { struct amdgpu_irq_src *source = kzalloc(sizeof(struct amdgpu_irq_src), GFP_KERNEL); + int ret; if (!source) return -ENOMEM; source->funcs = _irq_funcs; - amdgpu_irq_add_id((struct amdgpu_device *)(hwmgr->adev), + ret = amdgpu_irq_add_id((struct amdgpu_device *)(hwmgr->adev), SOC15_IH_CLIENTID_THM, THM_9_0__SRCID__THM_DIG_THERM_L2H, source); - amdgpu_irq_add_id((struct amdgpu_device *)(hwmgr->adev), + if (ret) + return ret; + + ret = amdgpu_irq_add_id((struct amdgpu_device *)(hwmgr->adev), SOC15_IH_CLIENTID_THM, THM_9_0__SRCID__THM_DIG_THERM_H2L, source); + if (ret) + return ret; /* Register CTF(GPIO_19) interrupt */ - amdgpu_irq_add_id((struct amdgpu_device *)(hwmgr->adev), + ret = amdgpu_irq_add_id((struct amdgpu_device *)(hwmgr->adev), SOC15_IH_CLIENTID_ROM_SMUIO, SMUIO_9_0__SRCID__SMUIO_GPIO19, source); + if (ret) + return ret; return 0; } -- 2.39.2
[lvc-project] [PATCH] drm/amd/display: Fix potential null dereference
The 'top_pipe_to_program pointer' can be NULL and it is checked at the first dereference, but not at the second. Add a check before using it. Found by Linux Verification Center (linuxtesting.org) with SVACE. Signed-off-by: Igor Artemiev --- drivers/gpu/drm/amd/display/dc/core/dc.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/drm/amd/display/dc/core/dc.c b/drivers/gpu/drm/amd/display/dc/core/dc.c index 3a9077b60029..154ad23ff931 100644 --- a/drivers/gpu/drm/amd/display/dc/core/dc.c +++ b/drivers/gpu/drm/amd/display/dc/core/dc.c @@ -3824,7 +3824,8 @@ static void commit_planes_for_stream(struct dc *dc, } if ((update_type != UPDATE_TYPE_FAST) && stream->update_flags.bits.dsc_changed) - if (top_pipe_to_program->stream_res.tg->funcs->lock_doublebuffer_enable) { + if (top_pipe_to_program && + top_pipe_to_program->stream_res.tg->funcs->lock_doublebuffer_enable) { top_pipe_to_program->stream_res.tg->funcs->wait_for_state( top_pipe_to_program->stream_res.tg, CRTC_STATE_VACTIVE); -- 2.30.2
[lvc-project] [PATCH] drm/radeon: remove useless conditions
Comparisons of 'table' and 'vddc_sclk_table' with NULL are useless since 'table' and 'vddc_sclk_table' are initialized by an addresses and cannot be NULL. Found by Linux Verification Center (linuxtesting.org) with SVACE. Signed-off-by: Igor Artemiev --- drivers/gpu/drm/radeon/kv_dpm.c | 22 +++--- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/drivers/gpu/drm/radeon/kv_dpm.c b/drivers/gpu/drm/radeon/kv_dpm.c index f7735da07feb..17d312ceb6ec 100644 --- a/drivers/gpu/drm/radeon/kv_dpm.c +++ b/drivers/gpu/drm/radeon/kv_dpm.c @@ -399,7 +399,7 @@ static u32 kv_convert_vid2_to_vid7(struct radeon_device *rdev, >pm.dpm.dyn_state.vddc_dependency_on_sclk; u32 i; - if (vddc_sclk_table && vddc_sclk_table->count) { + if (vddc_sclk_table->count) { if (vid_2bit < vddc_sclk_table->count) return vddc_sclk_table->entries[vid_2bit].v; else @@ -421,7 +421,7 @@ static u32 kv_convert_vid7_to_vid2(struct radeon_device *rdev, >pm.dpm.dyn_state.vddc_dependency_on_sclk; u32 i; - if (vddc_sclk_table && vddc_sclk_table->count) { + if (vddc_sclk_table->count) { for (i = 0; i < vddc_sclk_table->count; i++) { if (vddc_sclk_table->entries[i].v == vid_7bit) return i; @@ -561,7 +561,7 @@ static int kv_program_bootup_state(struct radeon_device *rdev) struct radeon_clock_voltage_dependency_table *table = >pm.dpm.dyn_state.vddc_dependency_on_sclk; - if (table && table->count) { + if (table->count) { for (i = pi->graphics_dpm_level_count - 1; i > 0; i--) { if (table->entries[i].clk == pi->boot_pl.sclk) break; @@ -666,7 +666,7 @@ static int kv_populate_uvd_table(struct radeon_device *rdev) int ret; u32 i; - if (table == NULL || table->count == 0) + if (table->count == 0) return 0; pi->uvd_level_count = 0; @@ -737,7 +737,7 @@ static int kv_populate_vce_table(struct radeon_device *rdev) >pm.dpm.dyn_state.vce_clock_voltage_dependency_table; struct atom_clock_dividers dividers; - if (table == NULL || table->count == 0) + if (table->count == 0) return 0; pi->vce_level_count = 0; @@ -800,7 +800,7 @@ static int kv_populate_samu_table(struct radeon_device *rdev) int ret; u32 i; - if (table == NULL || table->count == 0) + if (table->count == 0) return 0; pi->samu_level_count = 0; @@ -866,7 +866,7 @@ static int kv_populate_acp_table(struct radeon_device *rdev) int ret; u32 i; - if (table == NULL || table->count == 0) + if (table->count == 0) return 0; pi->acp_level_count = 0; @@ -922,7 +922,7 @@ static void kv_calculate_dfs_bypass_settings(struct radeon_device *rdev) struct radeon_clock_voltage_dependency_table *table = >pm.dpm.dyn_state.vddc_dependency_on_sclk; - if (table && table->count) { + if (table->count) { for (i = 0; i < pi->graphics_dpm_level_count; i++) { if (pi->caps_enable_dfs_bypass) { if (kv_get_clock_difference(table->entries[i].clk, 4) < 200) @@ -1532,7 +1532,7 @@ static void kv_set_valid_clock_range(struct radeon_device *rdev, struct radeon_clock_voltage_dependency_table *table = >pm.dpm.dyn_state.vddc_dependency_on_sclk; - if (table && table->count) { + if (table->count) { for (i = 0; i < pi->graphics_dpm_level_count; i++) { if ((table->entries[i].clk >= new_ps->levels[0].sclk) || (i == (pi->graphics_dpm_level_count - 1))) { @@ -1905,7 +1905,7 @@ static int kv_get_high_voltage_limit(struct radeon_device *rdev, int *limit) >pm.dpm.dyn_state.vddc_dependency_on_sclk; int i; - if (table && table->count) { + if (table->count) { for (i = table->count - 1; i >= 0; i--) { if (pi->high_voltage_t && (kv_convert_8bit_index_to_voltage(rdev, table->entries[i].v) <= @@ -2149,7 +2149,7 @@ static void kv_init_graphics_levels(struct radeon_device *rdev) struct radeon_clock_voltage_dependency_table *table = >pm.dpm.dyn_state.vddc_dependency_on_sclk; - if (table && table->count) { + if (table->count) { u32 vid_2bit; pi->graphics_dpm_level_count = 0; -- 2.30.2
[lvc-project] [PATCH] drm/radeon: remove useless conditions
Comparisons of 'table' and 'vddc_sclk_table' with NULL are useless since 'table' and 'vddc_sclk_table' are initialized by an addresses and cannot be NULL. Found by Linux Verification Center (linuxtesting.org) with SVACE. Signed-off-by: Igor Artemiev --- drivers/gpu/drm/radeon/kv_dpm.c | 22 +++--- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/drivers/gpu/drm/radeon/kv_dpm.c b/drivers/gpu/drm/radeon/kv_dpm.c index f7735da07feb..17d312ceb6ec 100644 --- a/drivers/gpu/drm/radeon/kv_dpm.c +++ b/drivers/gpu/drm/radeon/kv_dpm.c @@ -399,7 +399,7 @@ static u32 kv_convert_vid2_to_vid7(struct radeon_device *rdev, >pm.dpm.dyn_state.vddc_dependency_on_sclk; u32 i; - if (vddc_sclk_table && vddc_sclk_table->count) { + if (vddc_sclk_table->count) { if (vid_2bit < vddc_sclk_table->count) return vddc_sclk_table->entries[vid_2bit].v; else @@ -421,7 +421,7 @@ static u32 kv_convert_vid7_to_vid2(struct radeon_device *rdev, >pm.dpm.dyn_state.vddc_dependency_on_sclk; u32 i; - if (vddc_sclk_table && vddc_sclk_table->count) { + if (vddc_sclk_table->count) { for (i = 0; i < vddc_sclk_table->count; i++) { if (vddc_sclk_table->entries[i].v == vid_7bit) return i; @@ -561,7 +561,7 @@ static int kv_program_bootup_state(struct radeon_device *rdev) struct radeon_clock_voltage_dependency_table *table = >pm.dpm.dyn_state.vddc_dependency_on_sclk; - if (table && table->count) { + if (table->count) { for (i = pi->graphics_dpm_level_count - 1; i > 0; i--) { if (table->entries[i].clk == pi->boot_pl.sclk) break; @@ -666,7 +666,7 @@ static int kv_populate_uvd_table(struct radeon_device *rdev) int ret; u32 i; - if (table == NULL || table->count == 0) + if (table->count == 0) return 0; pi->uvd_level_count = 0; @@ -737,7 +737,7 @@ static int kv_populate_vce_table(struct radeon_device *rdev) >pm.dpm.dyn_state.vce_clock_voltage_dependency_table; struct atom_clock_dividers dividers; - if (table == NULL || table->count == 0) + if (table->count == 0) return 0; pi->vce_level_count = 0; @@ -800,7 +800,7 @@ static int kv_populate_samu_table(struct radeon_device *rdev) int ret; u32 i; - if (table == NULL || table->count == 0) + if (table->count == 0) return 0; pi->samu_level_count = 0; @@ -866,7 +866,7 @@ static int kv_populate_acp_table(struct radeon_device *rdev) int ret; u32 i; - if (table == NULL || table->count == 0) + if (table->count == 0) return 0; pi->acp_level_count = 0; @@ -922,7 +922,7 @@ static void kv_calculate_dfs_bypass_settings(struct radeon_device *rdev) struct radeon_clock_voltage_dependency_table *table = >pm.dpm.dyn_state.vddc_dependency_on_sclk; - if (table && table->count) { + if (table->count) { for (i = 0; i < pi->graphics_dpm_level_count; i++) { if (pi->caps_enable_dfs_bypass) { if (kv_get_clock_difference(table->entries[i].clk, 4) < 200) @@ -1532,7 +1532,7 @@ static void kv_set_valid_clock_range(struct radeon_device *rdev, struct radeon_clock_voltage_dependency_table *table = >pm.dpm.dyn_state.vddc_dependency_on_sclk; - if (table && table->count) { + if (table->count) { for (i = 0; i < pi->graphics_dpm_level_count; i++) { if ((table->entries[i].clk >= new_ps->levels[0].sclk) || (i == (pi->graphics_dpm_level_count - 1))) { @@ -1905,7 +1905,7 @@ static int kv_get_high_voltage_limit(struct radeon_device *rdev, int *limit) >pm.dpm.dyn_state.vddc_dependency_on_sclk; int i; - if (table && table->count) { + if (table->count) { for (i = table->count - 1; i >= 0; i--) { if (pi->high_voltage_t && (kv_convert_8bit_index_to_voltage(rdev, table->entries[i].v) <= @@ -2149,7 +2149,7 @@ static void kv_init_graphics_levels(struct radeon_device *rdev) struct radeon_clock_voltage_dependency_table *table = >pm.dpm.dyn_state.vddc_dependency_on_sclk; - if (table && table->count) { + if (table->count) { u32 vid_2bit; pi->graphics_dpm_level_count = 0; -- 2.30.2
[PATCH] drm/amd/display: Fix potential null dereference
The adev->dm.dc pointer can be NULL and dereferenced in amdgpu_dm_fini() without checking. Add a NULL pointer check before calling dc_dmub_srv_destroy(). Found by Linux Verification Center (linuxtesting.org) with SVACE. Fixes: 9a71c7d31734 ("drm/amd/display: Register DMUB service with DC") Signed-off-by: Igor Artemiev --- drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c index a01fd41643fc..27f7a554874e 100644 --- a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +++ b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c @@ -1854,7 +1854,8 @@ static void amdgpu_dm_fini(struct amdgpu_device *adev) dc_deinit_callbacks(adev->dm.dc); #endif - dc_dmub_srv_destroy(>dm.dc->ctx->dmub_srv); + if (adev->dm.dc) + dc_dmub_srv_destroy(>dm.dc->ctx->dmub_srv); if (dc_enable_dmub_notifications(adev->dm.dc)) { kfree(adev->dm.dmub_notify); -- 2.30.2