2017-08-29 13:21:47

by Himanshu Jha

[permalink] [raw]
Subject: [PATCH] drm/amd: Remove null check before kfree

Kfree on NULL pointer is a no-op and therefore checking is redundant.

Signed-off-by: Himanshu Jha <[email protected]>
---
drivers/gpu/drm/amd/amdgpu/amdgpu_connectors.c | 6 ++----
drivers/gpu/drm/amd/powerplay/smumgr/smu7_smumgr.c | 6 ++----
2 files changed, 4 insertions(+), 8 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_connectors.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_connectors.c
index 8d1cf2d..f51b41f 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_connectors.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_connectors.c
@@ -346,10 +346,8 @@ static void amdgpu_connector_free_edid(struct drm_connector *connector)
{
struct amdgpu_connector *amdgpu_connector = to_amdgpu_connector(connector);

- if (amdgpu_connector->edid) {
- kfree(amdgpu_connector->edid);
- amdgpu_connector->edid = NULL;
- }
+ kfree(amdgpu_connector->edid);
+ amdgpu_connector->edid = NULL;
}

static int amdgpu_connector_ddc_get_modes(struct drm_connector *connector)
diff --git a/drivers/gpu/drm/amd/powerplay/smumgr/smu7_smumgr.c b/drivers/gpu/drm/amd/powerplay/smumgr/smu7_smumgr.c
index 76347ff..00075c2 100644
--- a/drivers/gpu/drm/amd/powerplay/smumgr/smu7_smumgr.c
+++ b/drivers/gpu/drm/amd/powerplay/smumgr/smu7_smumgr.c
@@ -606,10 +606,8 @@ int smu7_init(struct pp_smumgr *smumgr)

int smu7_smu_fini(struct pp_smumgr *smumgr)
{
- if (smumgr->backend) {
- kfree(smumgr->backend);
- smumgr->backend = NULL;
- }
+ kfree(smumgr->backend);
+ smumgr->backend = NULL;
cgs_rel_firmware(smumgr->device, CGS_UCODE_ID_SMU);
return 0;
}
--
2.7.4


2017-08-29 13:28:24

by Christian König

[permalink] [raw]
Subject: Re: [PATCH] drm/amd: Remove null check before kfree

Am 29.08.2017 um 15:21 schrieb Himanshu Jha:
> Kfree on NULL pointer is a no-op and therefore checking is redundant.
>
> Signed-off-by: Himanshu Jha <[email protected]>

Reviewed-by: Christian König <[email protected]>

> ---
> drivers/gpu/drm/amd/amdgpu/amdgpu_connectors.c | 6 ++----
> drivers/gpu/drm/amd/powerplay/smumgr/smu7_smumgr.c | 6 ++----
> 2 files changed, 4 insertions(+), 8 deletions(-)
>
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_connectors.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_connectors.c
> index 8d1cf2d..f51b41f 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_connectors.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_connectors.c
> @@ -346,10 +346,8 @@ static void amdgpu_connector_free_edid(struct drm_connector *connector)
> {
> struct amdgpu_connector *amdgpu_connector = to_amdgpu_connector(connector);
>
> - if (amdgpu_connector->edid) {
> - kfree(amdgpu_connector->edid);
> - amdgpu_connector->edid = NULL;
> - }
> + kfree(amdgpu_connector->edid);
> + amdgpu_connector->edid = NULL;
> }
>
> static int amdgpu_connector_ddc_get_modes(struct drm_connector *connector)
> diff --git a/drivers/gpu/drm/amd/powerplay/smumgr/smu7_smumgr.c b/drivers/gpu/drm/amd/powerplay/smumgr/smu7_smumgr.c
> index 76347ff..00075c2 100644
> --- a/drivers/gpu/drm/amd/powerplay/smumgr/smu7_smumgr.c
> +++ b/drivers/gpu/drm/amd/powerplay/smumgr/smu7_smumgr.c
> @@ -606,10 +606,8 @@ int smu7_init(struct pp_smumgr *smumgr)
>
> int smu7_smu_fini(struct pp_smumgr *smumgr)
> {
> - if (smumgr->backend) {
> - kfree(smumgr->backend);
> - smumgr->backend = NULL;
> - }
> + kfree(smumgr->backend);
> + smumgr->backend = NULL;
> cgs_rel_firmware(smumgr->device, CGS_UCODE_ID_SMU);
> return 0;
> }


2017-08-29 19:43:21

by Alex Deucher

[permalink] [raw]
Subject: Re: [PATCH] drm/amd: Remove null check before kfree

On Tue, Aug 29, 2017 at 9:28 AM, Christian König
<[email protected]> wrote:
> Am 29.08.2017 um 15:21 schrieb Himanshu Jha:
>>
>> Kfree on NULL pointer is a no-op and therefore checking is redundant.
>>
>> Signed-off-by: Himanshu Jha <[email protected]>
>
>
> Reviewed-by: Christian König <[email protected]>
>

Applied. thanks!

Alex


>
>> ---
>> drivers/gpu/drm/amd/amdgpu/amdgpu_connectors.c | 6 ++----
>> drivers/gpu/drm/amd/powerplay/smumgr/smu7_smumgr.c | 6 ++----
>> 2 files changed, 4 insertions(+), 8 deletions(-)
>>
>> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_connectors.c
>> b/drivers/gpu/drm/amd/amdgpu/amdgpu_connectors.c
>> index 8d1cf2d..f51b41f 100644
>> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_connectors.c
>> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_connectors.c
>> @@ -346,10 +346,8 @@ static void amdgpu_connector_free_edid(struct
>> drm_connector *connector)
>> {
>> struct amdgpu_connector *amdgpu_connector =
>> to_amdgpu_connector(connector);
>> - if (amdgpu_connector->edid) {
>> - kfree(amdgpu_connector->edid);
>> - amdgpu_connector->edid = NULL;
>> - }
>> + kfree(amdgpu_connector->edid);
>> + amdgpu_connector->edid = NULL;
>> }
>> static int amdgpu_connector_ddc_get_modes(struct drm_connector
>> *connector)
>> diff --git a/drivers/gpu/drm/amd/powerplay/smumgr/smu7_smumgr.c
>> b/drivers/gpu/drm/amd/powerplay/smumgr/smu7_smumgr.c
>> index 76347ff..00075c2 100644
>> --- a/drivers/gpu/drm/amd/powerplay/smumgr/smu7_smumgr.c
>> +++ b/drivers/gpu/drm/amd/powerplay/smumgr/smu7_smumgr.c
>> @@ -606,10 +606,8 @@ int smu7_init(struct pp_smumgr *smumgr)
>> int smu7_smu_fini(struct pp_smumgr *smumgr)
>> {
>> - if (smumgr->backend) {
>> - kfree(smumgr->backend);
>> - smumgr->backend = NULL;
>> - }
>> + kfree(smumgr->backend);
>> + smumgr->backend = NULL;
>> cgs_rel_firmware(smumgr->device, CGS_UCODE_ID_SMU);
>> return 0;
>> }
>
>
>
> _______________________________________________
> amd-gfx mailing list
> [email protected]
> https://lists.freedesktop.org/mailman/listinfo/amd-gfx