<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css" style="display:none;"><!-- P {margin-top:0;margin-bottom:0;} --></style>
</head>
<body dir="ltr">
<div id="divtagdefaultwrapper" style="font-size:12pt;color:#000000;font-family:Calibri,Helvetica,sans-serif;" dir="ltr">
<p><br>
</p>
<meta content="text/html; charset=UTF-8">
<div dir="ltr">
<div id="x_divtagdefaultwrapper" dir="ltr" style="font-size: 12pt; color: rgb(0, 0, 0); font-family: Calibri, Helvetica, sans-serif, EmojiFont, 'Apple Color Emoji', 'Segoe UI Emoji', NotoColorEmoji, 'Segoe UI Symbol', 'Android Emoji', EmojiSymbols;">
<p><font size="2" style="color: rgb(33, 33, 33); font-family: 'Times New Roman', serif, serif, EmojiFont;"><span style="font-size: 10pt;"><span style="font-family: Calibri, Helvetica, sans-serif, EmojiFont, 'Apple Color Emoji', 'Segoe UI Emoji', NotoColorEmoji, 'Segoe UI Symbol', 'Android Emoji', EmojiSymbols; font-size: 13.3333px;">Reviewed-by:
</span> Rex Zhu <</span></font><a href="mailto:Rex.Zhu@amd.com" target="_blank" rel="noopener noreferrer" style="font-family: 'Times New Roman', serif, serif, EmojiFont; font-size: 16px;"><font size="2"><span style="font-size: 10pt;">Rex.Zhu@amd.com</span></font></a><font size="2" style="color: rgb(33, 33, 33); font-family: 'Times New Roman', serif, serif, EmojiFont;"><span style="font-size: 10pt;">></span></font><br>
</p>
<p><font size="2" style="color: rgb(33, 33, 33); font-family: 'Times New Roman', serif, serif, EmojiFont;"><span style="font-size: 10pt;"><br>
</span></font></p>
<p><font size="2" style="color: rgb(33, 33, 33); font-family: 'Times New Roman', serif, serif, EmojiFont;"><span style="font-size: 10pt;">Best Regards</span></font></p>
<p><font size="2" style="color: rgb(33, 33, 33); font-family: 'Times New Roman', serif, serif, EmojiFont;"><span style="font-size: 10pt;">Rex</span></font></p>
</div>
<hr tabindex="-1" style="display:inline-block; width:98%">
<div id="x_divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" color="#000000" style="font-size:11pt"><b>From:</b> Wentland, Harry<br>
<b>Sent:</b> Tuesday, August 29, 2017 9:34:01 PM<br>
<b>To:</b> Himanshu Jha; airlied@linux.ie<br>
<b>Cc:</b> linux-kernel@vger.kernel.org; dri-devel@lists.freedesktop.org; amd-gfx@lists.freedesktop.org; Deucher, Alexander; Zhu, Rex; Koenig, Christian<br>
<b>Subject:</b> Re: [PATCH] drm/amd/powerplay/hwmgr: Remove null check before kfree</font>
<div> </div>
</div>
</div>
<font size="2"><span style="font-size:10pt;">
<div class="PlainText">On 2017-08-29 09:12 AM, Himanshu Jha wrote:<br>
> kfree on NULL pointer is a no-op and therefore checking is redundant.<br>
> <br>
> Signed-off-by: Himanshu Jha <himanshujha199640@gmail.com><br>
<br>
Reviewed-by: Harry Wentland <harry.wentland@amd.com><br>
<br>
Harry<br>
<br>
> ---<br>
>  drivers/gpu/drm/amd/powerplay/hwmgr/cz_hwmgr.c     |  6 +-<br>
>  .../gpu/drm/amd/powerplay/hwmgr/processpptables.c  | 96 ++++++++--------------<br>
>  drivers/gpu/drm/amd/powerplay/hwmgr/rv_hwmgr.c     | 52 ++++--------<br>
>  drivers/gpu/drm/amd/powerplay/hwmgr/smu7_hwmgr.c   | 12 +--<br>
>  4 files changed, 56 insertions(+), 110 deletions(-)<br>
> <br>
> diff --git a/drivers/gpu/drm/amd/powerplay/hwmgr/cz_hwmgr.c b/drivers/gpu/drm/amd/powerplay/hwmgr/cz_hwmgr.c<br>
> index bc839ff..9f2c037 100644<br>
> --- a/drivers/gpu/drm/amd/powerplay/hwmgr/cz_hwmgr.c<br>
> +++ b/drivers/gpu/drm/amd/powerplay/hwmgr/cz_hwmgr.c<br>
> @@ -1225,10 +1225,8 @@ static int cz_hwmgr_backend_fini(struct pp_hwmgr *hwmgr)<br>
>                phm_destroy_table(hwmgr, &(hwmgr->power_down_asic));<br>
>                phm_destroy_table(hwmgr, &(hwmgr->setup_asic));<br>
>  <br>
> -             if (NULL != hwmgr->dyn_state.vddc_dep_on_dal_pwrl) {<br>
> -                     kfree(hwmgr->dyn_state.vddc_dep_on_dal_pwrl);<br>
> -                     hwmgr->dyn_state.vddc_dep_on_dal_pwrl = NULL;<br>
> -             }<br>
> +             kfree(hwmgr->dyn_state.vddc_dep_on_dal_pwrl);<br>
> +             hwmgr->dyn_state.vddc_dep_on_dal_pwrl = NULL;<br>
>  <br>
>                kfree(hwmgr->backend);<br>
>                hwmgr->backend = NULL;<br>
> diff --git a/drivers/gpu/drm/amd/powerplay/hwmgr/processpptables.c b/drivers/gpu/drm/amd/powerplay/hwmgr/processpptables.c<br>
> index 2716721..a6dbc55 100644<br>
> --- a/drivers/gpu/drm/amd/powerplay/hwmgr/processpptables.c<br>
> +++ b/drivers/gpu/drm/amd/powerplay/hwmgr/processpptables.c<br>
> @@ -1615,85 +1615,53 @@ static int pp_tables_uninitialize(struct pp_hwmgr *hwmgr)<br>
>        if (hwmgr->chip_id == CHIP_RAVEN)<br>
>                return 0;<br>
>  <br>
> -     if (NULL != hwmgr->dyn_state.vddc_dependency_on_sclk) {<br>
> -             kfree(hwmgr->dyn_state.vddc_dependency_on_sclk);<br>
> -             hwmgr->dyn_state.vddc_dependency_on_sclk = NULL;<br>
> -     }<br>
> +     kfree(hwmgr->dyn_state.vddc_dependency_on_sclk);<br>
> +     hwmgr->dyn_state.vddc_dependency_on_sclk = NULL;<br>
>  <br>
> -     if (NULL != hwmgr->dyn_state.vddci_dependency_on_mclk) {<br>
> -             kfree(hwmgr->dyn_state.vddci_dependency_on_mclk);<br>
> -             hwmgr->dyn_state.vddci_dependency_on_mclk = NULL;<br>
> -     }<br>
> +     kfree(hwmgr->dyn_state.vddci_dependency_on_mclk);<br>
> +     hwmgr->dyn_state.vddci_dependency_on_mclk = NULL;<br>
>  <br>
> -     if (NULL != hwmgr->dyn_state.vddc_dependency_on_mclk) {<br>
> -             kfree(hwmgr->dyn_state.vddc_dependency_on_mclk);<br>
> -             hwmgr->dyn_state.vddc_dependency_on_mclk = NULL;<br>
> -     }<br>
> +     kfree(hwmgr->dyn_state.vddc_dependency_on_mclk);<br>
> +     hwmgr->dyn_state.vddc_dependency_on_mclk = NULL;<br>
>  <br>
> -     if (NULL != hwmgr->dyn_state.mvdd_dependency_on_mclk) {<br>
> -             kfree(hwmgr->dyn_state.mvdd_dependency_on_mclk);<br>
> -             hwmgr->dyn_state.mvdd_dependency_on_mclk = NULL;<br>
> -     }<br>
> +     kfree(hwmgr->dyn_state.mvdd_dependency_on_mclk);<br>
> +     hwmgr->dyn_state.mvdd_dependency_on_mclk = NULL;<br>
>  <br>
> -     if (NULL != hwmgr->dyn_state.valid_mclk_values) {<br>
> -             kfree(hwmgr->dyn_state.valid_mclk_values);<br>
> -             hwmgr->dyn_state.valid_mclk_values = NULL;<br>
> -     }<br>
> +     kfree(hwmgr->dyn_state.valid_mclk_values);<br>
> +     hwmgr->dyn_state.valid_mclk_values = NULL;<br>
>  <br>
> -     if (NULL != hwmgr->dyn_state.valid_sclk_values) {<br>
> -             kfree(hwmgr->dyn_state.valid_sclk_values);<br>
> -             hwmgr->dyn_state.valid_sclk_values = NULL;<br>
> -     }<br>
> +     kfree(hwmgr->dyn_state.valid_sclk_values);<br>
> +     hwmgr->dyn_state.valid_sclk_values = NULL;<br>
>  <br>
> -     if (NULL != hwmgr->dyn_state.cac_leakage_table) {<br>
> -             kfree(hwmgr->dyn_state.cac_leakage_table);<br>
> -             hwmgr->dyn_state.cac_leakage_table = NULL;<br>
> -     }<br>
> +     kfree(hwmgr->dyn_state.cac_leakage_table);<br>
> +     hwmgr->dyn_state.cac_leakage_table = NULL;<br>
>  <br>
> -     if (NULL != hwmgr->dyn_state.vddc_phase_shed_limits_table) {<br>
> -             kfree(hwmgr->dyn_state.vddc_phase_shed_limits_table);<br>
> -             hwmgr->dyn_state.vddc_phase_shed_limits_table = NULL;<br>
> -     }<br>
> +     kfree(hwmgr->dyn_state.vddc_phase_shed_limits_table);<br>
> +     hwmgr->dyn_state.vddc_phase_shed_limits_table = NULL;<br>
>  <br>
> -     if (NULL != hwmgr->dyn_state.vce_clock_voltage_dependency_table) {<br>
> -             kfree(hwmgr->dyn_state.vce_clock_voltage_dependency_table);<br>
> -             hwmgr->dyn_state.vce_clock_voltage_dependency_table = NULL;<br>
> -     }<br>
> +     kfree(hwmgr->dyn_state.vce_clock_voltage_dependency_table);<br>
> +     hwmgr->dyn_state.vce_clock_voltage_dependency_table = NULL;<br>
>  <br>
> -     if (NULL != hwmgr->dyn_state.uvd_clock_voltage_dependency_table) {<br>
> -             kfree(hwmgr->dyn_state.uvd_clock_voltage_dependency_table);<br>
> -             hwmgr->dyn_state.uvd_clock_voltage_dependency_table = NULL;<br>
> -     }<br>
> +     kfree(hwmgr->dyn_state.uvd_clock_voltage_dependency_table);<br>
> +     hwmgr->dyn_state.uvd_clock_voltage_dependency_table = NULL;<br>
>  <br>
> -     if (NULL != hwmgr->dyn_state.samu_clock_voltage_dependency_table) {<br>
> -             kfree(hwmgr->dyn_state.samu_clock_voltage_dependency_table);<br>
> -             hwmgr->dyn_state.samu_clock_voltage_dependency_table = NULL;<br>
> -     }<br>
> +     kfree(hwmgr->dyn_state.samu_clock_voltage_dependency_table);<br>
> +     hwmgr->dyn_state.samu_clock_voltage_dependency_table = NULL;<br>
>  <br>
> -     if (NULL != hwmgr->dyn_state.acp_clock_voltage_dependency_table) {<br>
> -             kfree(hwmgr->dyn_state.acp_clock_voltage_dependency_table);<br>
> -             hwmgr->dyn_state.acp_clock_voltage_dependency_table = NULL;<br>
> -     }<br>
> +     kfree(hwmgr->dyn_state.acp_clock_voltage_dependency_table);<br>
> +     hwmgr->dyn_state.acp_clock_voltage_dependency_table = NULL;<br>
>  <br>
> -     if (NULL != hwmgr->dyn_state.cac_dtp_table) {<br>
> -             kfree(hwmgr->dyn_state.cac_dtp_table);<br>
> -             hwmgr->dyn_state.cac_dtp_table = NULL;<br>
> -     }<br>
> +     kfree(hwmgr->dyn_state.cac_dtp_table);<br>
> +     hwmgr->dyn_state.cac_dtp_table = NULL;<br>
>  <br>
> -     if (NULL != hwmgr->dyn_state.ppm_parameter_table) {<br>
> -             kfree(hwmgr->dyn_state.ppm_parameter_table);<br>
> -             hwmgr->dyn_state.ppm_parameter_table = NULL;<br>
> -     }<br>
> +     kfree(hwmgr->dyn_state.ppm_parameter_table);<br>
> +     hwmgr->dyn_state.ppm_parameter_table = NULL;<br>
>  <br>
> -     if (NULL != hwmgr->dyn_state.vdd_gfx_dependency_on_sclk) {<br>
> -             kfree(hwmgr->dyn_state.vdd_gfx_dependency_on_sclk);<br>
> -             hwmgr->dyn_state.vdd_gfx_dependency_on_sclk = NULL;<br>
> -     }<br>
> +     kfree(hwmgr->dyn_state.vdd_gfx_dependency_on_sclk);<br>
> +     hwmgr->dyn_state.vdd_gfx_dependency_on_sclk = NULL;<br>
>  <br>
> -     if (NULL != hwmgr->dyn_state.vq_budgeting_table) {<br>
> -             kfree(hwmgr->dyn_state.vq_budgeting_table);<br>
> -             hwmgr->dyn_state.vq_budgeting_table = NULL;<br>
> -     }<br>
> +     kfree(hwmgr->dyn_state.vq_budgeting_table);<br>
> +     hwmgr->dyn_state.vq_budgeting_table = NULL;<br>
>  <br>
>        return 0;<br>
>  }<br>
> diff --git a/drivers/gpu/drm/amd/powerplay/hwmgr/rv_hwmgr.c b/drivers/gpu/drm/amd/powerplay/hwmgr/rv_hwmgr.c<br>
> index 2c3e6ba..5547ed3 100644<br>
> --- a/drivers/gpu/drm/amd/powerplay/hwmgr/rv_hwmgr.c<br>
> +++ b/drivers/gpu/drm/amd/powerplay/hwmgr/rv_hwmgr.c<br>
> @@ -640,40 +640,24 @@ static int rv_hwmgr_backend_fini(struct pp_hwmgr *hwmgr)<br>
>        phm_destroy_table(hwmgr, &(hwmgr->power_down_asic));<br>
>        phm_destroy_table(hwmgr, &(hwmgr->setup_asic));<br>
>  <br>
> -     if (pinfo->vdd_dep_on_dcefclk) {<br>
> -             kfree(pinfo->vdd_dep_on_dcefclk);<br>
> -             pinfo->vdd_dep_on_dcefclk = NULL;<br>
> -     }<br>
> -     if (pinfo->vdd_dep_on_socclk) {<br>
> -             kfree(pinfo->vdd_dep_on_socclk);<br>
> -             pinfo->vdd_dep_on_socclk = NULL;<br>
> -     }<br>
> -     if (pinfo->vdd_dep_on_fclk) {<br>
> -             kfree(pinfo->vdd_dep_on_fclk);<br>
> -             pinfo->vdd_dep_on_fclk = NULL;<br>
> -     }<br>
> -     if (pinfo->vdd_dep_on_dispclk) {<br>
> -             kfree(pinfo->vdd_dep_on_dispclk);<br>
> -             pinfo->vdd_dep_on_dispclk = NULL;<br>
> -     }<br>
> -     if (pinfo->vdd_dep_on_dppclk) {<br>
> -             kfree(pinfo->vdd_dep_on_dppclk);<br>
> -             pinfo->vdd_dep_on_dppclk = NULL;<br>
> -     }<br>
> -     if (pinfo->vdd_dep_on_phyclk) {<br>
> -             kfree(pinfo->vdd_dep_on_phyclk);<br>
> -             pinfo->vdd_dep_on_phyclk = NULL;<br>
> -     }<br>
> -<br>
> -     if (NULL != hwmgr->dyn_state.vddc_dep_on_dal_pwrl) {<br>
> -             kfree(hwmgr->dyn_state.vddc_dep_on_dal_pwrl);<br>
> -             hwmgr->dyn_state.vddc_dep_on_dal_pwrl = NULL;<br>
> -     }<br>
> -<br>
> -     if (NULL != hwmgr->dyn_state.vq_budgeting_table) {<br>
> -             kfree(hwmgr->dyn_state.vq_budgeting_table);<br>
> -             hwmgr->dyn_state.vq_budgeting_table = NULL;<br>
> -     }<br>
> +     kfree(pinfo->vdd_dep_on_dcefclk);<br>
> +     pinfo->vdd_dep_on_dcefclk = NULL;<br>
> +     kfree(pinfo->vdd_dep_on_socclk);<br>
> +     pinfo->vdd_dep_on_socclk = NULL;<br>
> +     kfree(pinfo->vdd_dep_on_fclk);<br>
> +     pinfo->vdd_dep_on_fclk = NULL;<br>
> +     kfree(pinfo->vdd_dep_on_dispclk);<br>
> +     pinfo->vdd_dep_on_dispclk = NULL;<br>
> +     kfree(pinfo->vdd_dep_on_dppclk);<br>
> +     pinfo->vdd_dep_on_dppclk = NULL;<br>
> +     kfree(pinfo->vdd_dep_on_phyclk);<br>
> +     pinfo->vdd_dep_on_phyclk = NULL;<br>
> +<br>
> +     kfree(hwmgr->dyn_state.vddc_dep_on_dal_pwrl);<br>
> +     hwmgr->dyn_state.vddc_dep_on_dal_pwrl = NULL;<br>
> +<br>
> +     kfree(hwmgr->dyn_state.vq_budgeting_table);<br>
> +     hwmgr->dyn_state.vq_budgeting_table = NULL;<br>
>  <br>
>        kfree(hwmgr->backend);<br>
>        hwmgr->backend = NULL;<br>
> diff --git a/drivers/gpu/drm/amd/powerplay/hwmgr/smu7_hwmgr.c b/drivers/gpu/drm/amd/powerplay/hwmgr/smu7_hwmgr.c<br>
> index c274323..eb8a3ff 100644<br>
> --- a/drivers/gpu/drm/amd/powerplay/hwmgr/smu7_hwmgr.c<br>
> +++ b/drivers/gpu/drm/amd/powerplay/hwmgr/smu7_hwmgr.c<br>
> @@ -2282,15 +2282,11 @@ static int smu7_set_private_data_based_on_pptable_v0(struct pp_hwmgr *hwmgr)<br>
>  <br>
>  static int smu7_hwmgr_backend_fini(struct pp_hwmgr *hwmgr)<br>
>  {<br>
> -     if (NULL != hwmgr->dyn_state.vddc_dep_on_dal_pwrl) {<br>
> -             kfree(hwmgr->dyn_state.vddc_dep_on_dal_pwrl);<br>
> -             hwmgr->dyn_state.vddc_dep_on_dal_pwrl = NULL;<br>
> -     }<br>
> +     kfree(hwmgr->dyn_state.vddc_dep_on_dal_pwrl);<br>
> +     hwmgr->dyn_state.vddc_dep_on_dal_pwrl = NULL;<br>
>        pp_smu7_thermal_fini(hwmgr);<br>
> -     if (NULL != hwmgr->backend) {<br>
> -             kfree(hwmgr->backend);<br>
> -             hwmgr->backend = NULL;<br>
> -     }<br>
> +     kfree(hwmgr->backend);<br>
> +     hwmgr->backend = NULL;<br>
>  <br>
>        return 0;<br>
>  }<br>
> <br>
</div>
</span></font></div>
</body>
</html>