drivers/gpu/drm/radeon/ci_dpm.c | 34 ++++++++++------------------------ 1 file changed, 10 insertions(+), 24 deletions(-)
This patch removes useless NULL pointer checks in functions like
ci_set_private_data_variables_based_on_pptable() and
ci_setup_default_dpm_tables().
The pointers in question are initialized as addresses to existing
structures such as rdev->pm.dpm.dyn_state.vddc_dependency_on_sclk by
utilizing & operator and therefore are not in danger of being NULL.
Fix this by removing extra checks thus cleaning the code a tiny bit.
Found by Linux Verification Center (linuxtesting.org) with static
analysis tool SVACE.
Fixes: cc8dbbb4f62a ("drm/radeon: add dpm support for CI dGPUs (v2)")
Signed-off-by: Nikita Zhandarovich <n.zhandarovich@fintech.ru>
---
drivers/gpu/drm/radeon/ci_dpm.c | 34 ++++++++++------------------------
1 file changed, 10 insertions(+), 24 deletions(-)
diff --git a/drivers/gpu/drm/radeon/ci_dpm.c b/drivers/gpu/drm/radeon/ci_dpm.c
index abe9d65cc460..7c3a960f486a 100644
--- a/drivers/gpu/drm/radeon/ci_dpm.c
+++ b/drivers/gpu/drm/radeon/ci_dpm.c
@@ -3405,12 +3405,8 @@ static int ci_setup_default_dpm_tables(struct radeon_device *rdev)
&rdev->pm.dpm.dyn_state.cac_leakage_table;
u32 i;
- if (allowed_sclk_vddc_table == NULL)
- return -EINVAL;
if (allowed_sclk_vddc_table->count < 1)
return -EINVAL;
- if (allowed_mclk_table == NULL)
- return -EINVAL;
if (allowed_mclk_table->count < 1)
return -EINVAL;
@@ -3468,24 +3464,20 @@ static int ci_setup_default_dpm_tables(struct radeon_device *rdev)
pi->dpm_table.vddc_table.count = allowed_sclk_vddc_table->count;
allowed_mclk_table = &rdev->pm.dpm.dyn_state.vddci_dependency_on_mclk;
- if (allowed_mclk_table) {
- for (i = 0; i < allowed_mclk_table->count; i++) {
- pi->dpm_table.vddci_table.dpm_levels[i].value =
- allowed_mclk_table->entries[i].v;
- pi->dpm_table.vddci_table.dpm_levels[i].enabled = true;
- }
- pi->dpm_table.vddci_table.count = allowed_mclk_table->count;
+ for (i = 0; i < allowed_mclk_table->count; i++) {
+ pi->dpm_table.vddci_table.dpm_levels[i].value =
+ allowed_mclk_table->entries[i].v;
+ pi->dpm_table.vddci_table.dpm_levels[i].enabled = true;
}
+ pi->dpm_table.vddci_table.count = allowed_mclk_table->count;
allowed_mclk_table = &rdev->pm.dpm.dyn_state.mvdd_dependency_on_mclk;
- if (allowed_mclk_table) {
- for (i = 0; i < allowed_mclk_table->count; i++) {
- pi->dpm_table.mvdd_table.dpm_levels[i].value =
- allowed_mclk_table->entries[i].v;
- pi->dpm_table.mvdd_table.dpm_levels[i].enabled = true;
- }
- pi->dpm_table.mvdd_table.count = allowed_mclk_table->count;
+ for (i = 0; i < allowed_mclk_table->count; i++) {
+ pi->dpm_table.mvdd_table.dpm_levels[i].value =
+ allowed_mclk_table->entries[i].v;
+ pi->dpm_table.mvdd_table.dpm_levels[i].enabled = true;
}
+ pi->dpm_table.mvdd_table.count = allowed_mclk_table->count;
ci_setup_default_pcie_tables(rdev);
@@ -4880,16 +4872,10 @@ static int ci_set_private_data_variables_based_on_pptable(struct radeon_device *
struct radeon_clock_voltage_dependency_table *allowed_mclk_vddci_table =
&rdev->pm.dpm.dyn_state.vddci_dependency_on_mclk;
- if (allowed_sclk_vddc_table == NULL)
- return -EINVAL;
if (allowed_sclk_vddc_table->count < 1)
return -EINVAL;
- if (allowed_mclk_vddc_table == NULL)
- return -EINVAL;
if (allowed_mclk_vddc_table->count < 1)
return -EINVAL;
- if (allowed_mclk_vddci_table == NULL)
- return -EINVAL;
if (allowed_mclk_vddci_table->count < 1)
return -EINVAL;
Gentle ping :)
On 1/14/25 16:58, Nikita Zhandarovich wrote:
> This patch removes useless NULL pointer checks in functions like
> ci_set_private_data_variables_based_on_pptable() and
> ci_setup_default_dpm_tables().
>
> The pointers in question are initialized as addresses to existing
> structures such as rdev->pm.dpm.dyn_state.vddc_dependency_on_sclk by
> utilizing & operator and therefore are not in danger of being NULL.
>
> Fix this by removing extra checks thus cleaning the code a tiny bit.
>
> Found by Linux Verification Center (linuxtesting.org) with static
> analysis tool SVACE.
>
> Fixes: cc8dbbb4f62a ("drm/radeon: add dpm support for CI dGPUs (v2)")
> Signed-off-by: Nikita Zhandarovich <n.zhandarovich@fintech.ru>
> ---
> drivers/gpu/drm/radeon/ci_dpm.c | 34 ++++++++++------------------------
> 1 file changed, 10 insertions(+), 24 deletions(-)
>
> diff --git a/drivers/gpu/drm/radeon/ci_dpm.c b/drivers/gpu/drm/radeon/ci_dpm.c
> index abe9d65cc460..7c3a960f486a 100644
> --- a/drivers/gpu/drm/radeon/ci_dpm.c
> +++ b/drivers/gpu/drm/radeon/ci_dpm.c
> @@ -3405,12 +3405,8 @@ static int ci_setup_default_dpm_tables(struct radeon_device *rdev)
> &rdev->pm.dpm.dyn_state.cac_leakage_table;
> u32 i;
>
> - if (allowed_sclk_vddc_table == NULL)
> - return -EINVAL;
> if (allowed_sclk_vddc_table->count < 1)
> return -EINVAL;
> - if (allowed_mclk_table == NULL)
> - return -EINVAL;
> if (allowed_mclk_table->count < 1)
> return -EINVAL;
>
> @@ -3468,24 +3464,20 @@ static int ci_setup_default_dpm_tables(struct radeon_device *rdev)
> pi->dpm_table.vddc_table.count = allowed_sclk_vddc_table->count;
>
> allowed_mclk_table = &rdev->pm.dpm.dyn_state.vddci_dependency_on_mclk;
> - if (allowed_mclk_table) {
> - for (i = 0; i < allowed_mclk_table->count; i++) {
> - pi->dpm_table.vddci_table.dpm_levels[i].value =
> - allowed_mclk_table->entries[i].v;
> - pi->dpm_table.vddci_table.dpm_levels[i].enabled = true;
> - }
> - pi->dpm_table.vddci_table.count = allowed_mclk_table->count;
> + for (i = 0; i < allowed_mclk_table->count; i++) {
> + pi->dpm_table.vddci_table.dpm_levels[i].value =
> + allowed_mclk_table->entries[i].v;
> + pi->dpm_table.vddci_table.dpm_levels[i].enabled = true;
> }
> + pi->dpm_table.vddci_table.count = allowed_mclk_table->count;
>
> allowed_mclk_table = &rdev->pm.dpm.dyn_state.mvdd_dependency_on_mclk;
> - if (allowed_mclk_table) {
> - for (i = 0; i < allowed_mclk_table->count; i++) {
> - pi->dpm_table.mvdd_table.dpm_levels[i].value =
> - allowed_mclk_table->entries[i].v;
> - pi->dpm_table.mvdd_table.dpm_levels[i].enabled = true;
> - }
> - pi->dpm_table.mvdd_table.count = allowed_mclk_table->count;
> + for (i = 0; i < allowed_mclk_table->count; i++) {
> + pi->dpm_table.mvdd_table.dpm_levels[i].value =
> + allowed_mclk_table->entries[i].v;
> + pi->dpm_table.mvdd_table.dpm_levels[i].enabled = true;
> }
> + pi->dpm_table.mvdd_table.count = allowed_mclk_table->count;
>
> ci_setup_default_pcie_tables(rdev);
>
> @@ -4880,16 +4872,10 @@ static int ci_set_private_data_variables_based_on_pptable(struct radeon_device *
> struct radeon_clock_voltage_dependency_table *allowed_mclk_vddci_table =
> &rdev->pm.dpm.dyn_state.vddci_dependency_on_mclk;
>
> - if (allowed_sclk_vddc_table == NULL)
> - return -EINVAL;
> if (allowed_sclk_vddc_table->count < 1)
> return -EINVAL;
> - if (allowed_mclk_vddc_table == NULL)
> - return -EINVAL;
> if (allowed_mclk_vddc_table->count < 1)
> return -EINVAL;
> - if (allowed_mclk_vddci_table == NULL)
> - return -EINVAL;
> if (allowed_mclk_vddci_table->count < 1)
> return -EINVAL;
>
On Thu, Feb 13, 2025 at 12:03 PM Nikita Zhandarovich
<n.zhandarovich@fintech.ru> wrote:
>
> Gentle ping :)
Was already applied:
https://gitlab.freedesktop.org/agd5f/linux/-/commit/189abca05a89fc7b422811e497a7116b3e4f4dca
Thanks,
Alex
>
> On 1/14/25 16:58, Nikita Zhandarovich wrote:
> > This patch removes useless NULL pointer checks in functions like
> > ci_set_private_data_variables_based_on_pptable() and
> > ci_setup_default_dpm_tables().
> >
> > The pointers in question are initialized as addresses to existing
> > structures such as rdev->pm.dpm.dyn_state.vddc_dependency_on_sclk by
> > utilizing & operator and therefore are not in danger of being NULL.
> >
> > Fix this by removing extra checks thus cleaning the code a tiny bit.
> >
> > Found by Linux Verification Center (linuxtesting.org) with static
> > analysis tool SVACE.
> >
> > Fixes: cc8dbbb4f62a ("drm/radeon: add dpm support for CI dGPUs (v2)")
> > Signed-off-by: Nikita Zhandarovich <n.zhandarovich@fintech.ru>
> > ---
> > drivers/gpu/drm/radeon/ci_dpm.c | 34 ++++++++++------------------------
> > 1 file changed, 10 insertions(+), 24 deletions(-)
> >
> > diff --git a/drivers/gpu/drm/radeon/ci_dpm.c b/drivers/gpu/drm/radeon/ci_dpm.c
> > index abe9d65cc460..7c3a960f486a 100644
> > --- a/drivers/gpu/drm/radeon/ci_dpm.c
> > +++ b/drivers/gpu/drm/radeon/ci_dpm.c
> > @@ -3405,12 +3405,8 @@ static int ci_setup_default_dpm_tables(struct radeon_device *rdev)
> > &rdev->pm.dpm.dyn_state.cac_leakage_table;
> > u32 i;
> >
> > - if (allowed_sclk_vddc_table == NULL)
> > - return -EINVAL;
> > if (allowed_sclk_vddc_table->count < 1)
> > return -EINVAL;
> > - if (allowed_mclk_table == NULL)
> > - return -EINVAL;
> > if (allowed_mclk_table->count < 1)
> > return -EINVAL;
> >
> > @@ -3468,24 +3464,20 @@ static int ci_setup_default_dpm_tables(struct radeon_device *rdev)
> > pi->dpm_table.vddc_table.count = allowed_sclk_vddc_table->count;
> >
> > allowed_mclk_table = &rdev->pm.dpm.dyn_state.vddci_dependency_on_mclk;
> > - if (allowed_mclk_table) {
> > - for (i = 0; i < allowed_mclk_table->count; i++) {
> > - pi->dpm_table.vddci_table.dpm_levels[i].value =
> > - allowed_mclk_table->entries[i].v;
> > - pi->dpm_table.vddci_table.dpm_levels[i].enabled = true;
> > - }
> > - pi->dpm_table.vddci_table.count = allowed_mclk_table->count;
> > + for (i = 0; i < allowed_mclk_table->count; i++) {
> > + pi->dpm_table.vddci_table.dpm_levels[i].value =
> > + allowed_mclk_table->entries[i].v;
> > + pi->dpm_table.vddci_table.dpm_levels[i].enabled = true;
> > }
> > + pi->dpm_table.vddci_table.count = allowed_mclk_table->count;
> >
> > allowed_mclk_table = &rdev->pm.dpm.dyn_state.mvdd_dependency_on_mclk;
> > - if (allowed_mclk_table) {
> > - for (i = 0; i < allowed_mclk_table->count; i++) {
> > - pi->dpm_table.mvdd_table.dpm_levels[i].value =
> > - allowed_mclk_table->entries[i].v;
> > - pi->dpm_table.mvdd_table.dpm_levels[i].enabled = true;
> > - }
> > - pi->dpm_table.mvdd_table.count = allowed_mclk_table->count;
> > + for (i = 0; i < allowed_mclk_table->count; i++) {
> > + pi->dpm_table.mvdd_table.dpm_levels[i].value =
> > + allowed_mclk_table->entries[i].v;
> > + pi->dpm_table.mvdd_table.dpm_levels[i].enabled = true;
> > }
> > + pi->dpm_table.mvdd_table.count = allowed_mclk_table->count;
> >
> > ci_setup_default_pcie_tables(rdev);
> >
> > @@ -4880,16 +4872,10 @@ static int ci_set_private_data_variables_based_on_pptable(struct radeon_device *
> > struct radeon_clock_voltage_dependency_table *allowed_mclk_vddci_table =
> > &rdev->pm.dpm.dyn_state.vddci_dependency_on_mclk;
> >
> > - if (allowed_sclk_vddc_table == NULL)
> > - return -EINVAL;
> > if (allowed_sclk_vddc_table->count < 1)
> > return -EINVAL;
> > - if (allowed_mclk_vddc_table == NULL)
> > - return -EINVAL;
> > if (allowed_mclk_vddc_table->count < 1)
> > return -EINVAL;
> > - if (allowed_mclk_vddci_table == NULL)
> > - return -EINVAL;
> > if (allowed_mclk_vddci_table->count < 1)
> > return -EINVAL;
> >
>
© 2016 - 2025 Red Hat, Inc.